package com.duben.microtribe.ui.widgets

import android.app.Activity
import android.app.Dialog
import android.view.Gravity
import android.view.KeyEvent
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import com.duben.microtribe.R
import com.duben.microtribe.utils.SpanUtils

class NineContinueDialog(
    activity: Activity,
    watchCount: Int,
    listener: DialogListener
) :
    Dialog(activity, R.style.dialog) {

    private val lp: WindowManager.LayoutParams

    init {
        setContentView(R.layout.dialog_nine_continue)
        // 设置window属性
        lp = window!!.attributes
        lp.gravity = Gravity.CENTER
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
        lp.windowAnimations = R.style.DialogAnimFade
        window!!.attributes = lp

        // 设置外部不可关闭
        setCancelable(false)
        setCanceledOnTouchOutside(false)
        setOnKeyListener { dialogInterface, i, keyEvent ->
            i == KeyEvent.KEYCODE_BACK
        }

        val tv_nine_text = findViewById<TextView>(R.id.tv_nine_text)
        val tv_nine_next = findViewById<TextView>(R.id.tv_nine_next)
        val tv_nine_close = findViewById<ImageView>(R.id.tv_nine_close)

        tv_nine_text.text = SpanUtils()
            .append("再看")
            .append("$watchCount")
            .setForegroundColor(context.resources.getColor(R.color.red))
            .append("次即可抽奖")
            .create()
        listener.setDialog(this)
        tv_nine_next.setOnClickListener(listener)
        tv_nine_close.setOnClickListener { dismiss() }
    }

}