<commit_before>package com.ruuvi.tag.feature

import android.app.AlertDialog
import android.content.Intent
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Point
import android.graphics.Typeface
import android.os.Bundle
import android.os.Handler
import android.support.design.widget.BottomSheetDialog
import android.support.v7.app.AppCompatActivity
import com.ruuvi.tag.R
import com.ruuvi.tag.model.RuuviTag
import com.ruuvi.tag.scanning.RuuviTagListener
import com.ruuvi.tag.scanning.RuuviTagScanner
import com.ruuvi.tag.util.Utils

import kotlinx.android.synthetic.main.activity_tag_details.*
import android.support.v4.view.PagerAdapter
import android.support.v4.view.ViewPager
import android.view.*
import android.support.v4.view.ViewPager.OnPageChangeListener
import android.widget.*
import kotlinx.android.synthetic.main.content_tag_details.*
import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan
import android.text.SpannableString
import android.text.Spanned
import android.text.style.TypefaceSpan
import com.ruuvi.tag.util.CustomTypefaceSpan


class TagDetails : AppCompatActivity(), RuuviTagListener {
    var tag: RuuviTag? = null
    var tags: List<RuuviTag>? = null

    var scanner: RuuviTagScanner? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tag_details)
        setSupportActionBar(toolbar)

        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.title = null
        supportActionBar?.setIcon(R.drawable.logo_white)

        val size = Point()
        windowManager.defaultDisplay.getSize(size)
        tag_pager.pageMargin = - (size.x / 2)
        tag_pager.setOnPageChangeListener(object : OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {}
            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}

            override fun onPageSelected(position: Int) {
                tag = tags!!.get(position)
                updateUI()
            }
        })

        val tagId = intent.getStringExtra("id");
        tags = RuuviTag.getAll()
        val pagerAdapter = TagPager(tags!!)
        tag_pager.adapter = pagerAdapter
        tag_pager.offscreenPageLimit = 100

        for (i in tags!!.indices) {
            if (tags!!.get(i).id == tagId) {
                tag = tags!!.get(i)
                tag_pager.currentItem = i
            }
        }

        if (tag == null) {
            Toast.makeText(this, "Something went wrong..", Toast.LENGTH_SHORT).show()
            finish()
        }

        val handler = Handler()
        handler.post(object: Runnable {
            override fun run() {
                updateUI()
                handler.postDelayed(this, 1000)
            }
        })

        scanner = RuuviTagScanner(this, this)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == android.R.id.home) {
            finish()
        } else if (item?.itemId == R.id.action_share) {
            if (tag?.url != null) {
                if (!tag!!.url.isEmpty()) {
                    val shareIntent = Intent(Intent.ACTION_SEND)
                    shareIntent.type = "text/plain"
                    shareIntent.putExtra(Intent.EXTRA_TEXT, tag!!.url!!)
                    this.startActivity(shareIntent)
                    return true;
                }
            }
            Toast.makeText(this,
                    "You can only share tags in weather station mode right now"
                    , Toast.LENGTH_SHORT).show()
        } else {
            showOptionsMenu()
        }
        return true
    }

    override fun onResume() {
        super.onResume()
        tags = RuuviTag.getAll()
        scanner?.start()
    }

    override fun onPause() {
        super.onPause()
        scanner?.stop()
    }

    override fun tagFound(tag: RuuviTag) {
        if (tags == null) return;
        for (mTag in tags!!) {
            if (mTag.id == tag.id) {
                mTag.updateDataFrom(tag)
                mTag.update()
            }
        }
    }

    fun updateUI() {
        for (mTag in tags!!) {
            if (mTag.id == tag!!.id) {
                tag = mTag
            }
        }
        tag?.let {
            val ss1 = SpannableString(String.format(this.getString(R.string.temperature_reading), tag?.temperature) + "C")
            ss1.setSpan(CustomTypefaceSpan(dummyTextView.typeface), ss1.length - 2, ss1.length, 0)
            tag_temp.text = ss1
            tag_humidity.text = String.format(this.getString(R.string.humidity_reading), tag?.humidity)
            tag_pressure.text = String.format(this.getString(R.string.pressure_reading), tag?.pressure)
            tag_signal.text = String.format(this.getString(R.string.signal_reading), tag?.rssi)
            var updatedAt = this.resources.getString(R.string.updated) + " " + Utils.strDescribingTimeSince(tag?.updateAt);
            tag_updated.text = updatedAt
        }
    }

    private fun showOptionsMenu() {
        val sheetDialog = BottomSheetDialog(this)
        var listView = ListView(this)
        val menu: List<String> = this.resources.getStringArray(R.array.station_tag_menu).toList()

        listView.adapter = ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,
                menu
        )

        listView.onItemClickListener = AdapterView.OnItemClickListener { adapterView, view, i, l ->
            when (i) {
                0 -> {
                    val intent = Intent(this, TagSettings::class.java)
                    intent.putExtra(TagSettings.TAG_ID, tag?.id)
                    this.startActivity(intent)
                }
                1 -> {
                    delete()
                }
            }
<commit_msg>more font things<commit_after>package com.ruuvi.tag.feature

import android.app.AlertDialog
import android.content.Intent
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Point
import android.graphics.Typeface
import android.os.Bundle
import android.os.Handler
import android.support.design.widget.BottomSheetDialog
import android.support.v7.app.AppCompatActivity
import com.ruuvi.tag.R
import com.ruuvi.tag.model.RuuviTag
import com.ruuvi.tag.scanning.RuuviTagListener
import com.ruuvi.tag.scanning.RuuviTagScanner
import com.ruuvi.tag.util.Utils

import kotlinx.android.synthetic.main.activity_tag_details.*
import android.support.v4.view.PagerAdapter
import android.support.v4.view.ViewPager
import android.view.*
import android.support.v4.view.ViewPager.OnPageChangeListener
import android.widget.*
import kotlinx.android.synthetic.main.content_tag_details.*
import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan
import android.text.SpannableString
import android.text.Spanned
import android.text.style.SuperscriptSpan
import android.text.style.TypefaceSpan
import com.ruuvi.tag.util.CustomTypefaceSpan


class TagDetails : AppCompatActivity(), RuuviTagListener {
    var tag: RuuviTag? = null
    var tags: List<RuuviTag>? = null

    var scanner: RuuviTagScanner? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tag_details)
        setSupportActionBar(toolbar)

        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.title = null
        supportActionBar?.setIcon(R.drawable.logo_white)

        val size = Point()
        windowManager.defaultDisplay.getSize(size)
        tag_pager.pageMargin = - (size.x / 2)
        tag_pager.setOnPageChangeListener(object : OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {}
            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}

            override fun onPageSelected(position: Int) {
                tag = tags!!.get(position)
                updateUI()
            }
        })

        val tagId = intent.getStringExtra("id");
        tags = RuuviTag.getAll()
        val pagerAdapter = TagPager(tags!!)
        tag_pager.adapter = pagerAdapter
        tag_pager.offscreenPageLimit = 100

        for (i in tags!!.indices) {
            if (tags!!.get(i).id == tagId) {
                tag = tags!!.get(i)
                tag_pager.currentItem = i
            }
        }

        if (tag == null) {
            Toast.makeText(this, "Something went wrong..", Toast.LENGTH_SHORT).show()
            finish()
        }

        val handler = Handler()
        handler.post(object: Runnable {
            override fun run() {
                updateUI()
                handler.postDelayed(this, 1000)
            }
        })

        scanner = RuuviTagScanner(this, this)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == android.R.id.home) {
            finish()
        } else if (item?.itemId == R.id.action_share) {
            if (tag?.url != null) {
                if (!tag!!.url.isEmpty()) {
                    val shareIntent = Intent(Intent.ACTION_SEND)
                    shareIntent.type = "text/plain"
                    shareIntent.putExtra(Intent.EXTRA_TEXT, tag!!.url!!)
                    this.startActivity(shareIntent)
                    return true;
                }
            }
            Toast.makeText(this,
                    "You can only share tags in weather station mode right now"
                    , Toast.LENGTH_SHORT).show()
        } else {
            showOptionsMenu()
        }
        return true
    }

    override fun onResume() {
        super.onResume()
        tags = RuuviTag.getAll()
        scanner?.start()
    }

    override fun onPause() {
        super.onPause()
        scanner?.stop()
    }

    override fun tagFound(tag: RuuviTag) {
        if (tags == null) return;
        for (mTag in tags!!) {
            if (mTag.id == tag.id) {
                mTag.updateDataFrom(tag)
                mTag.update()
            }
        }
    }

    fun updateUI() {
        for (mTag in tags!!) {
            if (mTag.id == tag!!.id) {
                tag = mTag
            }
        }
        tag?.let {
            val temperature = SpannableString(String.format(this.getString(R.string.temperature_reading), tag?.temperature) + "C")
            temperature.setSpan(CustomTypefaceSpan(dummyTextView.typeface), temperature.length - 2, temperature.length, 0)
            temperature.setSpan(RelativeSizeSpan(0.6f), temperature.length - 2, temperature.length, 0)
            temperature.setSpan(SuperscriptSpan(), temperature.length - 2, temperature.length, 0)
            tag_temp.text = temperature
            tag_humidity.text = String.format(this.getString(R.string.humidity_reading), tag?.humidity)
            tag_pressure.text = String.format(this.getString(R.string.pressure_reading), tag?.pressure)
            tag_signal.text = String.format(this.getString(R.string.signal_reading), tag?.rssi)
            var updatedAt = this.resources.getString(R.string.updated) + " " + Utils.strDescribingTimeSince(tag?.updateAt);
            tag_updated.text = updatedAt
        }
    }

    private fun showOptionsMenu() {
        val sheetDialog = BottomSheetDialog(this)
        var listView = ListView(this)
        val menu: List<String> = this.resources.getStringArray(R.array.station_tag_menu).toList()

        listView.adapter = ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,
                menu
        )

        listView.onItemClickListener = AdapterView.OnItemClickListener { adapterView, view, i, l ->
            when (i) {
                0 -> {
                    val intent = Intent(this, TagSettings::class.java)
                    intent.putExtra(TagSettings.TAG_ID, tag?.id)
                    this.startActivity(intent)
                }
                1 -> {
                    delete()
                }
            }

{'fraction_non_alphanumeric': 0.10216819973718791, 'fraction_numerical': 0.0036957950065703024, 'mean_word_length': 2.110344827586207, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '931212', 'n_tokens_mistral': 3570, 'n_tokens_neox': 3411, 'n_words': 628}