package com.convenient.android.lib

import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.convenient.android.common.base.viewbinding.BaseBindingActivity
import com.convenient.android.common.utils.date.*
import com.convenient.android.lib.databinding.ActivityDateBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * @author: hubowen
 * @date: 2022/8/3
 * @description:
 */
class DateUtilActivity : BaseBindingActivity<ActivityDateBinding>(ActivityDateBinding::inflate) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.apply {

            lifecycleScope.launch(Dispatchers.IO) {
                while (true) {
                    delay(1000)
                    withContext(Dispatchers.Main) {
                        idDateActivityTvTime.text = System.currentTimeMillis().toDate(DateUtils.DateFormat.DEFAULT_PATTERN.dateFormat)
                    }
                }
            }

            idDateActivityTvContent.text =
                "${System.currentTimeMillis().toDate(DateUtils.DateFormat.DEFAULT_PATTERN.dateFormat)}\n" +
                        "${year("年")}${month(isAbbreviation = true)}${day("日")}${hour("时")}${minute("分")}${second("秒")}${week(isAbbreviation = true)}"
        }
    }
}