package eu.smoser.epv

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

class HelpActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_help)
        setSupportActionBar(findViewById(R.id.toolbar))
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.setDisplayShowHomeEnabled(true)

        findViewById<Button>(R.id.button).setOnClickListener {
            lifecycleScope.executeAsyncTask(onPreExecute = {}, doInBackground = {
                val dao = AppDatabase.getInstance(this@HelpActivity).userDao()
                dao?.getAll()
            }, onPostExecute = {
                findViewById<TextView>(R.id.textHelp).text = ""
                it?.forEach { user ->
                    findViewById<TextView>(R.id.textHelp).append(user.toString() + "\n")
                }
            })
        }
    }

    override fun onSupportNavigateUp(): Boolean {
        onBackPressed()
        return true
    }
}