package com.duben.microtribe.ui.activitys

import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import com.duben.microtribe.R
import com.duben.microtribe.ui.activitys.base.BaseActivity
import com.duben.microtribe.utils.SpanUtils
import com.duben.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.activity_nine_know.*

/**
 * 描述：9宫格手机
 * 作者：孟崔广
 */
class NineKnowActivity : BaseActivity(), View.OnClickListener {

    companion object {
        const val COMPLETE = "COMPLETE"
        const val NEED = "NEED"
    }

    private var complete = 0
    private var need = 0

    override fun getContentViewLayoutID() = R.layout.activity_nine_know

    override fun isApplyKitKatTranslucency() = false

    override fun toggleOverridePendingTransition() = true

    override fun getOverridePendingTransitionMode() = TransitionMode.SCALE

    override fun getBundleExtras(extras: Bundle?) {
        super.getBundleExtras(extras)
        extras?.let {
            complete = it.getInt(COMPLETE, 0)
            need = it.getInt(NEED, 0)
        }
    }

    override fun initViewsAndEvents() {
        tv_nine_know_text.text = SpanUtils()
            .append("再看")
            .append("${need - complete}")
            .setForegroundColor(resources.getColor(R.color.red))
            .append("次广告后抽")
            .append("手机")
            .setForegroundColor(resources.getColor(R.color.red))
            .create()

        initListener()
    }


    private fun initListener() {
        tv_nine_know_next.setOnClickListener(this)
    }

    override fun finish() {
        super.finish()
        overridePendingTransition(0, R.anim.scale_out)
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        return if (keyCode == KeyEvent.KEYCODE_BACK) {
            true
        } else super.onKeyDown(
            keyCode,
            event
        )
    }

    override fun onClick(v: View) {
        if (AntiShake.check(v.id)) return

        when (v.id) {
            R.id.tv_nine_know_next -> {
                finish()
            }
        }
    }
}