package com.color.keyboard.black.max

import android.app.Activity
import android.os.CountDownTimer
import android.util.Log
import com.color.keyboard.black.ColorApp


object WelComManager {

    private lateinit var timer: CountDownTimer
    private var need_Show = true

    @JvmStatic
    fun initTimer(activity: Activity, countTime: Long, countAction: (Long) -> Unit, goMainAction: () -> Unit): CountDownTimer {
        need_Show = true
        timer = object : CountDownTimer(countTime, 100) {
            override fun onTick(millisUntilFinished: Long) {
                countAction.invoke(millisUntilFinished)
                if (need_Show) {
                    MaxManager.ShowAd(activity) {
                        Log.d(ColorApp.TAG, "--onTick----------it=$it")
                        if (it == MaxManager.type_has_cache) {
                            need_Show = false
                        }
                        if (it == MaxManager.type_show_close || it == MaxManager.type_show_fail) {
                            Log.d(ColorApp.TAG, "--onTick---------enter")
                            goMainAction.invoke()
                        }
                    }
                }
            }

            override fun onFinish() {
                if (need_Show) {
                    MaxManager.ShowAd(activity) {
                        goMainAction.invoke()
                    }
                }
            }
        }
        return timer
    }

}