package com.qimai.android.widget

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.qimai.android.widget.databinding.ActivityLogBinding
import com.qimai.log.QLog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class LogActivity : AppCompatActivity() {

    private lateinit var bind: ActivityLogBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        bind = ActivityLogBinding.inflate(layoutInflater)
        setContentView(bind.root)
        init()
    }

    private fun init() {
        bind.btnLog.setOnClickListener { initLog() }
        bind.btnWrite.setOnClickListener {
            lifecycleScope.launch(Dispatchers.IO) {
                QLog.write("123456", QLog.D)
                withContext(Dispatchers.Main) {
                    QLog.write("123456789", QLog.E)
                }
            }
        }

    }

    /**
     * 初始化LogUp
     */
    private fun initLog() {
        QLog.init(true)
    }
}