package com.bc_chat.circle.activity

import com.alibaba.android.arouter.facade.annotation.Route
import com.amap.api.mapcore.util.it
import com.bc_chat.bc_base.config.RouteConfig
import com.bc_chat.bc_base.entity.contact.Fans
import com.bc_chat.circle.adapetr.FansAdapter
import com.bc_chat.circle.contract.TopicDetailsContract
import com.bc_chat.circle.dataSource.MineFansDataSource
import com.bc_chat.circle.presenter.TopicDetailsPresenter
import com.bc_chat.contacts.R
import com.zhaohaoting.framework.abs.BaseRecyclerActivity
import com.zhaohaoting.framework.abs.adapter.AbsRecyclerAdapter
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.mvchelper.mvc.IAsyncDataSource
import com.zhaohaoting.framework.utils.ActivityUtils

/**
 * author：Created by zhaohaoting on 2019/8/29
 * email：526309416@qq.com
 * desc：
 */
@Route(path = RouteConfig.MINE_FOLLOW)
class MineFollowActivity : BaseRecyclerActivity<Fans, List<Fans>>(), TopicDetailsContract.View {

    override fun commentSuccess() {

    }

    override fun deleteSuccess(position: Int) {
    }

    override fun likeSuccess(type: Int) {
        refresh()
    }

    //1-我的关注 2-我的粉丝
    private val type by lazy {
        intent.getStringExtra("type") ?: "1"
    }

    //1-我的关注 2-我的粉丝
    private val fansAdapter by lazy {
        FansAdapter(this, type)
    }

    override fun initPresenter(): BasePresenter<*> {
        return TopicDetailsPresenter(this)
    }

    override fun getAdapter(): AbsRecyclerAdapter<Fans, List<Fans>> = fansAdapter

    override fun getDataSource(): IAsyncDataSource<List<Fans>> = MineFansDataSource(type)

    override fun onInit() {
        titleView.text = if ("1".equals(type)) "我的关注" else "我的粉丝"
        flContent.setBackgroundColor(resources.getColor(R.color.white))
        fansAdapter.addOnItemViewClickListener { vh, view, position ->
            val fans = fansAdapter.data.get(position)
            if (view.id == R.id.tv_cancel_follow) {
                (presenter as TopicDetailsPresenter).like(fans.uid!!, 2)
            }
        }
    }

    override fun onItemClick(vh: AbsRecyclerAdapter.BaseViewHolder<*>?, position: Int) {
        val fans = adapter.data[position]
        ActivityUtils.newInstance(this).putExtra("cuid", fans.uid).navigation(UserCircleDetailsActivity::class.java)
    }
}