package com.mints.goodmoney.ui.activitys

import android.os.Bundle
import android.view.View
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.TTNativeExpressManager
import com.mints.goodmoney.manager.TtCsjAdManager
import com.mints.goodmoney.mvp.model.WalkBean
import com.mints.goodmoney.mvp.presenters.WalkPresenter
import com.mints.goodmoney.mvp.views.WalkView
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.widgets.StepView
import kotlinx.android.synthetic.main.activity_walk.*

/**
 * 描述：走路赚钱
 * 作者：孟崔广
 * 时间：2020/10/13 11:55
 */
class WalkActivity : BaseActivity(), View.OnClickListener, WalkView, StepView.StepViewListener {

    private val walkPresenter by lazy { WalkPresenter() }
    private val ttNativeExpressManager by lazy { TTNativeExpressManager() }
    private var curCoin = 0//点击的汽泡金币

    override fun getContentViewLayoutID() = R.layout.activity_walk

    override fun isApplyKitKatTranslucency() = false

    override fun initViewsAndEvents() {
        walkPresenter.attachView(this)

        initListener()
    }

    override fun onResume() {
        super.onResume()

        initExpress()
        walkPresenter.getWalkMsg()
    }

    override fun onDestroy() {
        super.onDestroy()

        svWalk?.destoryAnim()
        ttNativeExpressManager.onTTAdDestroy()
        walkPresenter.detachView()
    }

    private fun initListener() {
        ivWalkBack.setOnClickListener(this)
        svWalk.setStepViewListener(this)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.ivWalkBack -> {
                finish()
            }
        }
    }

    override fun getWalkMsgSuc(data: WalkBean) {
        svWalk.setThreeBtnGone()
        curCoin = data.bubbleCoin
        for (i in 0..data.bubbleCount - 1) {
            svWalk.setWaterTextviewLayout(i + 1, 0)
        }

        svWalk.setWaterMaxProgress(data.maxWalk)
        svWalk.setWaterProgress(data.walk, data.maxWalk)

        // 是否可领取奖励
        if (data.isWalk) {
            svWalk.setTvDrinkBtnEnable()
        } else {
            svWalk.setTvDrinkBtnNone()
        }
        svWalk.setTvDrinkBtnText(data.walkText)
    }

    override fun clickForWalkSuc(walkCoin: Int) {
        val bundle = Bundle()
        bundle.putInt(Constant.MAIN_CUR_COIN, walkCoin)
        bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_WALK)
        readyGo(AwardActivity::class.java, bundle)
    }

    override fun clickWater(water: Int, waterCoin: String) {
        if (water == 0) {
            walkPresenter.clickForWalk()
        } else {
            val bundle = Bundle()
            bundle.putInt(Constant.MAIN_CUR_COIN, curCoin)
            bundle.putString(Constant.MAIN_CARRIER_TYPE, Constant.CARRIER_WALK_BUBBLE)
            readyGo(AwardActivity::class.java, bundle)
        }
    }

    /**
     * 初始化信息iyc
     */
    private fun initExpress() {
        try {
            ttNativeExpressManager.initTTAd( false)
            ttNativeExpressManager.getNativeExpressInit( TtCsjAdManager.TT_AD_NATIVEEXPRESS_WALK, flWalkAd, 320f, 0f)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}