package com.develop.setting.init.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.develop.food.base.ui.BaseActivity
import com.develop.food.base.router.Screens
import com.develop.setting.R
import com.develop.setting.databinding.ActivityScreensaverBinding
import com.develop.setting.init.adapter.CircleAdapter
import com.develop.setting.init.adapter.ScreenBannerAdapter
import com.youth.banner.listener.OnPageChangeListener

@Route(path = Screens.Setting.SCREEN_SAVER)
class ScreensaverActivity : BaseActivity<ActivityScreensaverBinding>() {

    override fun createViewBinding(inflater: LayoutInflater): ActivityScreensaverBinding {
        return ActivityScreensaverBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        hasShowScreenSaver = true
        val dataList = mutableListOf(
            R.drawable.screen_lock_017,
            R.drawable.screen_lock_017,
            R.drawable.screen_lock_017,
            R.drawable.screen_lock_017
        )
        binding.showTimeView.visibility = View.GONE
        val bannerAdapter = ScreenBannerAdapter(dataList)
        binding.bannerView.adapter = bannerAdapter
        val circleAdapter = CircleAdapter()
        circleAdapter.setList(dataList)
        binding.circleRecycler.adapter = circleAdapter
        binding.bannerView.apply {
            setLoopTime(5000)
            setOnBannerListener { data, position ->
                finish()
            }
            addOnPageChangeListener(object : OnPageChangeListener {
                override fun onPageScrolled(
                    position: Int,
                    positionOffset: Float,
                    positionOffsetPixels: Int
                ) {

                }

                override fun onPageSelected(position: Int) {
                    circleAdapter.updateSelectedPosition(position)
                }

                override fun onPageScrollStateChanged(state: Int) {
                }
            })
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        hasShowScreenSaver = false
        binding.showTimeView.stopTime()
    }
}