package com.example.defenseapplication.liveVideo

import android.graphics.Color
import android.os.Bundle
import android.text.Editable
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import com.example.defenseapplication.databinding.WarningVoiceContentActivityBinding
import com.gyf.immersionbar.ImmersionBar
//警告语音内容
class WarningVoiceContentActivity : AppCompatActivity() {

    private lateinit var binding: WarningVoiceContentActivityBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = WarningVoiceContentActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)
        // ImmersionBar核心调用,沉浸式
        ImmersionBar.with(this)
            .statusBarDarkFont(true)
            .titleBar(binding.topBar)
            .init()
        // 初始化计数显示
        val initialLength = binding.etWarningContent.text.length
        updateWordCount(initialLength)

        // 添加文本变化监听
        binding.etWarningContent.doAfterTextChanged { text ->
            val length = text?.length ?: 0
            updateWordCount(length)
        }
        binding.btnBack.setOnClickListener {
            finish()
        }
        binding.btnSave.setOnClickListener {
            //保存的逻辑
            finish()
        }
    }
    private fun updateWordCount(current: Int) {
        binding.tvWordCount.text = "$current/100"
        //字数达到上限时改变颜色
        val color = if (current >= 100) Color.RED else Color.GRAY
        binding.tvWordCount.setTextColor(color)
    }
}
