package com.renrenliao.im.ui.activity

import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.renrenliao.im.R
import com.renrenliao.im.base.BaseVMActivity
import com.renrenliao.im.im.AlarmEntity
import com.renrenliao.im.im.AlarmType
import com.renrenliao.im.ui.adapter.VerificationAdapter
import com.renrenliao.im.utils.DeviceUtils
import com.renrenliao.im.utils.RouteUtils
import com.renrenliao.im.viewmodel.VerificationViewModel
import com.renrenliao.im.widget.view.VerticalDecoration
import kotlinx.android.synthetic.main.activity_verification.*
import kotlinx.android.synthetic.main.activity_verification.tool_bar
import org.koin.androidx.viewmodel.ext.android.getViewModel

/**
 **@ClassName VerificationActivity
 **@Description
 **@Author gan
 **@Date 2022/6/20 13:15
 **/
class VerificationActivity:BaseVMActivity<VerificationViewModel>() {

    private val  verificationAdapter  by lazy { VerificationAdapter() }


    override fun initVM(): VerificationViewModel = getViewModel()

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

    override fun initView() {
        tool_bar.setOnBackListener { onBackPressed() }

        //设置分割线
        val mDivider = ContextCompat.getDrawable(this, R.drawable.divider_left_63)
        recy.addItemDecoration(VerticalDecoration(this, mDivider, DeviceUtils.dip2px(this, 0.6f).toInt()))
        recy.run {
            layoutManager = LinearLayoutManager(this@VerificationActivity)
            adapter = verificationAdapter
        }

        verificationAdapter.setOnItemClickListener { _, _, position ->
            RouteUtils.gotoProcessAddFriend(this,verificationAdapter.data[position])
        }
    }

    override fun initData() {
        mViewModel.getAddFriendReq()
    }

    override fun startObserve() {
        mViewModel.alarmLiveData.observe(this){alarms ->

            if (alarms.isEmpty()){
                verificationAdapter.setEmptyView(R.layout.layout_empty_verification)
            }
            //倒序排序
            alarms.sortedByDescending { it.time }
            verificationAdapter.setList(alarms)
        }
    }
}