package com.zxhl.cms.pay

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.zxhl.cms.R
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.chat.RecordEntity
import com.zxhl.cms.utils.RecyclerViewScrollListener
import kotlinx.android.synthetic.main.activity_layout_pay_record.*
import kotlinx.android.synthetic.main.layout_record_empty_view.*

class PayRecordActivity : BaseActivity(), RecordContract.View {
    private var mPresenter: RecordPresenter? = null
    private var mAdapter: PayRecordAdapter? = null
    override fun before() {
        super.before()
        setStatusBarBackground(resources.getColor(R.color.transparent))
    }
    override fun init() {
        id_img_back?.setOnClickListener {
            finish()
        }
        mPresenter = RecordPresenter(this)
        mAdapter = PayRecordAdapter(this)
        id_rl_pay_record?.layoutManager = LinearLayoutManager(this)
        id_rl_pay_record?.adapter = mAdapter
        id_rl_pay_record?.addOnScrollListener(object : RecyclerViewScrollListener() {
            override fun onScrollToBottom() {
                super.onScrollToBottom()
                if ((mAdapter?.list?.size ?: 0) > 0) {
                    mPresenter?.getMemberRecord(false)
                }
            }
        })
        id_refresh_layout.setColorSchemeColors(resources.getColor(com.zxhl.cms.R.color.color_aa60ff))
        id_refresh_layout?.setOnRefreshListener {
            mPresenter?.getMemberRecord(true)
        }
        mPresenter?.getMemberRecord(true)
    }

    override fun onClick(v: View?) {

    }

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

    override fun setData(boolean: Boolean, reslut: List<RecordEntity>?) {
        id_layout_empty?.visibility=View.GONE
        if (boolean) {
            mAdapter?.clear()
        }

        id_refresh_layout?.isRefreshing = false
        val start = mAdapter?.getItemCount() ?: 0
        mAdapter?.appendToList(reslut)
        if (boolean) {
            mAdapter?.notifyDataSetChanged()
        } else {
            val end = mAdapter?.getItemCount() ?: 0
            mAdapter?.notifyItemRangeChanged(start, end)
        }
    }

    override fun setEmptyView() {
        id_refresh_layout?.isRefreshing = false
        id_layout_empty?.visibility=View.VISIBLE
        id_tv_empty_trip?.text="暂无会员充值记录～"
    }

}