package com.tencent.liteav.demo.player

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.tencent.liteav.demo.player.databinding.FragmentTimerBinding
import com.tencent.liteav.demo.player.util.PlayerTimerUtil

class PlayerTimer : AppCompatActivity(), View.OnClickListener {
    private var _viewBinding: FragmentTimerBinding? = null
    private val viewBinding get() = _viewBinding!!

    private val none get() = viewBinding.timerItemNone

    private val ep1 get() = viewBinding.timerItemEpisodeOne
    private val ep2 get() = viewBinding.timerItemEpisodeTwo
    private val ep3 get() = viewBinding.timerItemEpisodeThree

    private val dt10 get() = viewBinding.timerItemDuration10
    private val dt20 get() = viewBinding.timerItemDuration20
    private val dt30 get() = viewBinding.timerItemDuration30
    private val custom get() = viewBinding.timerItemDurationCustom

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        _viewBinding = FragmentTimerBinding.inflate(layoutInflater)
        setContentView(viewBinding.root)

        window.setLayout(-1, -1)

        none.setOnClickListener(this)
        ep1.setOnClickListener(this)
        ep2.setOnClickListener(this)
        ep3.setOnClickListener(this)
        dt10.setOnClickListener(this)
        dt20.setOnClickListener(this)
        dt30.setOnClickListener(this)
        custom.setOnClickListener(this)
    }

    override fun onClick(v: View) {
        when (v.id) {
            none.id -> {
                PlayerTimerUtil.setTimer(0, 0)
            }
            ep1.id -> {
                PlayerTimerUtil.setTimer(1, 1)
            }
            ep2.id -> {
                PlayerTimerUtil.setTimer(1, 2)
            }
            ep3.id -> {
                PlayerTimerUtil.setTimer(1, 3)
            }
            dt10.id -> {
                PlayerTimerUtil.setTimer(2, 10)
            }
            dt20.id -> {
                PlayerTimerUtil.setTimer(2, 20)
            }
            dt30.id -> {
                PlayerTimerUtil.setTimer(2, 30)
            }
            custom.id -> {
                PlayerTimerUtil.setTimer(2, 100)
            }
        }

        finish()
    }
}