package com.zxbw.modulemain.activity

import android.content.Intent
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.zxbw.modulemain.R
import com.zxbw.modulemain.adapter.CardAdapter
import com.zxbw.modulemain.contract.CardVoucherContract
import com.zxbw.modulemain.presenter.CardVoucherPresenter
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.qy.JgqQyEntity
import com.zxhl.cms.net.model.qy.RightsDetailEntity
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.OnRecycleItemClickListener
import kotlinx.android.synthetic.main.activity_layout_card_voucher.*

class CardVoucherActivity:BaseActivity(),CardVoucherContract.View ,OnRecycleItemClickListener<RightsDetailEntity>{
    private var mPresenter:CardVoucherPresenter?=null
    private var mAdapter:CardAdapter?=null
    private var brand:String=""
    override fun onClick(v: View?) {

    }
    override fun before() {
        super.before()
        setStatusBarBackground(AppContext.get().resources.getColor(R.color.transparent))
    }
    override fun layoutID(): Int {
        return R.layout.activity_layout_card_voucher
    }

    override fun init() {
        brand = intent?.data?.getQueryParameter("brand") ?: ""
        id_img_back?.setOnClickListener {
            finish()
        }
        mPresenter= CardVoucherPresenter(this)
        mAdapter= CardAdapter(this,this)
        id_rl_card_voucher?.layoutManager= LinearLayoutManager(mActivity)
        id_rl_card_voucher?.adapter=mAdapter
        id_refresh_layout?.setOnRefreshListener {
            mPresenter?.getCardList(brand)
        }
        mPresenter?.getCardList(brand)
    }




    override fun setData(result: List<RightsDetailEntity>?) {
        id_refresh_layout?.isRefreshing = false
        mAdapter?.clear()
        mAdapter?.appendToList(result)
        mAdapter?.notifyDataSetChanged()
    }

    override fun onItemClick(view: View?, position: Int, data: RightsDetailEntity?) {
      //  showToast(""+position)
        val intent = Intent(mActivity, CardDetailActivity::class.java)
        intent.putExtra("cardbean", data)
        startActivity(intent)

        // JumpUtils.CardDetailJump()
    }
}