package com.cheng.blzb.ui.fragment.photo

import android.graphics.Color
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.cheng.blzb.R
import com.cheng.blzb.databinding.FragmentPhotoViewBinding
import com.example.base.ui.BaseFragment

class PhotoViewFragment : BaseFragment<FragmentPhotoViewBinding, PhotoViewViewModel>() {
    private val photos by lazy { arguments?.getStringArrayList("photos") ?: arrayListOf() }
    private val index by lazy { arguments?.getInt("index") ?: 0 }
    private val mAdapter by lazy { PhotoViewAdapter() }

    override fun initView() {
        super.initView()
        mTitleBar?.background = null
        mTitleBar?.setTitleTextColor(Color.WHITE)
        setBackColor(R.color.white)

        binding.vpPhoto.adapter = mAdapter
    }

    override fun initData() {
        super.initData()
        mAdapter.setList(photos)
        binding.vpPhoto.setCurrentItem(index, false)
    }

    override fun initListener() {
        super.initListener()
        binding.vpPhoto.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                mTitleBar?.title = "${position + 1}/${mAdapter.data.size}"
            }
        })
    }
}