package invalid.lena.rsend

import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

// LogActivity shows the plain-text sync log with refresh and clear.
class LogActivity : AppCompatActivity() {

    private lateinit var log: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_log)
        setSupportActionBar(findViewById(R.id.toolbar))
        title = "Log"
        fitSystemBars()
        log = findViewById(R.id.log)
        findViewById<Button>(R.id.refresh).setOnClickListener { load() }
        findViewById<Button>(R.id.clear).setOnClickListener {
            SyncLog(this).file.writeText("")
            load()
        }
    }

    override fun onResume() {
        super.onResume()
        load()
    }

    private fun load() {
        log.text = SyncLog(this).text().ifEmpty { "No log yet." }
    }
}
