package com.ym.userinfo.module.activity

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.umeng.analytics.MobclickAgent
import com.ym.library.module.WithdrawEntity
import com.ym.library.net.BaseActivity
import com.ym.library.utils.StatusBarUtil
import com.ym.module.userinfo.R
import com.ym.userinfo.module.adapter.WithdrawalsRecordAdapter
import com.ym.userinfo.module.contract.WithdrawalsRecordContract
import com.ym.userinfo.module.presenter.WithdrawalsRecordPresenter
import kotlinx.android.synthetic.main.activity_withdrawals_record.*
import kotlinx.android.synthetic.main.layout_user_toolbar.*

class WithdrawalsRecordActivity : BaseActivity(), WithdrawalsRecordContract.View {

    private var adapter: WithdrawalsRecordAdapter? = null
    private var mPresenter: WithdrawalsRecordPresenter? = null

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

    override fun before() {
        super.before()
        StatusBarUtil.transportStatus(this, resources.getColor(R.color.transparent))
    }

    override fun init() {
        mPresenter = WithdrawalsRecordPresenter(this)
        mPresenter?.requestWithdrawalsRecord()

        tv_user_toolbar_title.text = "提现记录"
        iv_user_toolbar_back.setOnClickListener { finish() }

        adapter = WithdrawalsRecordAdapter(this)
        recycler_record.layoutManager = LinearLayoutManager(this)
        recycler_record.adapter = adapter
    }


    override fun updataSuccess(datas: List<WithdrawEntity>) {
        if (datas.isNotEmpty()) {
            recycler_record.visibility = View.VISIBLE
            adapter?.clear()
            adapter?.appendToList(datas)
            adapter?.notifyDataSetChanged()
        } else {
            tv_record_no_history.visibility = View.VISIBLE
            recycler_record.visibility = View.GONE
        }
    }

    override fun onResume() {
        super.onResume()
        MobclickAgent.onResume(this)
    }

    override fun onPause() {
        super.onPause()
        MobclickAgent.onPause(this)
    }


}
