package com.ydl.confide.intro

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.ydl.confide.R
import com.ydl.confide.api.ConfideRoute
import com.ydl.confide.databinding.ActivityExpertIntroBinding
import com.ydl.confide.home.util.ConfideNetworkUtil
import com.ydl.ydlcommon.view.dialog.CommonDialog


@Route(path = ConfideRoute.R_VIDEO_SHOW)
class ExpertIntroActivity : AppCompatActivity() {

    @Autowired
    @JvmField
    var initPos: Int = 0

    private lateinit var binding: ActivityExpertIntroBinding
    private lateinit var adapter: IntroAdapter

    private val data = mutableListOf<VideoViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_expert_intro)
        if (Build.VERSION.SDK_INT >= 21) {
            val decorView = window.decorView
            val option = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
            decorView.systemUiVisibility = option
            window.statusBarColor = Color.TRANSPARENT
        }
        binding.ivBack.setOnClickListener { onBackPressed() }
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        binding.viewPager.orientation = ViewPager2.ORIENTATION_VERTICAL
        binding.viewPager.offscreenPageLimit = 1
        adapter = IntroAdapter(this, data, this)
        binding.viewPager.adapter = adapter
        binding.viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                adapter.onSelect(position)
                if (position == data.size - 1) {
                    loadMore()
                }
            }
        })
        adapter.checkNetwork()
    }

    private fun loadMore() {
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        data.add(VideoViewModel())
        adapter.notifyItemRangeInserted(data.size - 5, 5)
    }
}