package com.tencent.liteav.demo.player

import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.tencent.liteav.demo.superplayer.database.entity.CountDown
import com.tencent.liteav.demo.superplayer.ui.view.WheelView
import com.tencent.liteav.demo.superplayer.util.TimersUtil
import kotlin.concurrent.thread

class PlayerWheel : AppCompatActivity() {
    private lateinit var hourWheel: WheelView
    private lateinit var minuteWheel: WheelView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_wheel)
        findViewById<WheelView>(R.id.layout_wheel).apply {
            hourWheel = this

            val list = mutableListOf<String>()
            for (i in 0..24) {
                list.add("${i}小时")
            }

            setItems(list)
        }

        findViewById<WheelView>(R.id.layout_wheel2).apply {
            minuteWheel = this

            val list = mutableListOf<String>()
            for (i in 0..60) {
                list.add("${i}分钟")
            }

            setItems(list)
        }

        findViewById<TextView>(R.id.wheel_cancel).setOnClickListener {
            finish()
        }

        findViewById<ImageView>(R.id.wheel_close).setOnClickListener {
            finish()
        }

        findViewById<TextView>(R.id.wheel_confirm).setOnClickListener {
            val duration = hourWheel.seletedIndex * 60 * 60 + minuteWheel.seletedIndex * 60
            if (duration == 0) {
                Toast.makeText(this@PlayerWheel, "请选择正确的时间", Toast.LENGTH_SHORT).show()
            } else {
                TimersUtil.sendNewTimer(CountDown.TYPE_DURATION, duration)
                finish()
            }
        }
    }
}