package com.renrenliao.im.ui.activity

import android.view.LayoutInflater
import android.view.MenuItem
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import com.gyf.immersionbar.ktx.immersionBar
import com.gyf.immersionbar.ktx.statusBarHeight
import com.renrenliao.im.R
import com.renrenliao.im.base.BaseVMActivity
import com.renrenliao.im.ext.click
import com.renrenliao.im.ui.adapter.FriendCircleAdapter
import com.renrenliao.im.utils.DeviceUtils
import com.renrenliao.im.utils.GlideUtils
import com.renrenliao.im.viewmodel.FriendCircleViewModel
import kotlinx.android.synthetic.main.activity_friendcircle.*
import org.koin.androidx.viewmodel.ext.android.getViewModel

/**
 **@ClassName FriendCircleActivity
 **@Description
 **@Author gan
 **@Date 2022/6/15 15:14
 **/
class FriendCircleActivity : BaseVMActivity<FriendCircleViewModel>() {

    private val friendCircleAdapter by lazy { FriendCircleAdapter() }
    val list = listOf<String>("1", "2", "3", "4", "5", "6", "7")

    var pageIndex = 1
    val pageSize = 20

    override fun initVM(): FriendCircleViewModel = getViewModel()

    override fun getLayoutResId(): Int = R.layout.activity_friendcircle

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == android.R.id.home) {
            finish()
        }
        return super.onOptionsItemSelected(item);
    }

    override fun initView() {
        immersionBar {
            statusBarColor(R.color.transparent)
            navigationBarColor(R.color.white)
        }
        val param = tool_bar.layoutParams
        param.height = DeviceUtils.dip2px(this, 45f).toInt() + statusBarHeight
        tool_bar.setPadding(0, statusBarHeight, 0, 0)
        setSupportActionBar(tool_bar)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.setHomeButtonEnabled(true)


        val url_cover = "https://cdn.pixabay.com/photo/2016/12/23/12/40/night-1927265_960_720.jpg"
        val url_avatar =
            "https://img.iplaysoft.com/wp-content/uploads/2019/free-images/free_stock_photo.jpg"

        GlideUtils.loadComImage(iv_cover, url_cover)
        GlideUtils.loadUserImage(iv_avatar, url_avatar)

        recy.run {
            adapter = friendCircleAdapter
            layoutManager = LinearLayoutManager(this@FriendCircleActivity)
        }
        friendCircleAdapter.setList(list)
    }

    override fun initData() {
        getFriendCircleData()
    }

    private fun getFriendCircleData() {
        mViewModel.getCircleData(pageIndex, pageSize)
        pageIndex++
    }


    override fun startObserve() {

    }
}