package com.ym.chat.activity

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.ym.chat.R
import com.ym.chat.adapter.SystemMsgAdapter
import com.ym.chat.contract.SystemMessageContract
import com.ym.chat.presenter.SystemMsgPresenter
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.chat.ChatMessageEntity
import kotlinx.android.synthetic.main.activity_layout_system_message.*


class SystemMessageActivity : BaseActivity(), SystemMessageContract.View {
    private var mPressenter: SystemMsgPresenter? = null
    private var mAdapter: SystemMsgAdapter? = null
    override fun init() {
        id_img_back?.setOnClickListener {
            finish()
        }
        mPressenter = SystemMsgPresenter(this)
        mAdapter = SystemMsgAdapter(this)
        id_rl_system_msg?.layoutManager = LinearLayoutManager(this)
        id_rl_system_msg?.adapter = mAdapter

        mPressenter?.getmsgLog("", "")
    }

    override fun before() {
        super.before()
        setStatusBarBackground(AppContext.get().resources.getColor(R.color.transparent))
    }

    override fun onClick(v: View?) {

    }

    override fun layoutID(): Int {
        return R.layout.activity_layout_system_message
    }

    override fun setData(reslut: ChatMessageEntity?) {
        if(!reslut?.MsgList.isNullOrEmpty()){
            id_ll_system_empty_msg.visibility=View.GONE
            if(mAdapter!=null){
                mAdapter?.clear()
            }
            mAdapter?.appendToList(reslut?.MsgList)
            mAdapter?.notifyDataSetChanged()
        }else{
            setEmptyView()
        }

    }

    override fun setEmptyView() {
        id_ll_system_empty_msg.visibility=View.VISIBLE

    }
}