package com.paperapp.lenscape.preview

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.ad.tradpluslibrary.TPAdManager
import com.paperapp.lenscape.DApp
import com.paperapp.lenscape.databinding.ActivityMemberAccessBinding
import com.paperapp.lenscape.TopBarUtils

class MemberAccessActivity : AppCompatActivity() {
    lateinit var binding: ActivityMemberAccessBinding
    private var handler: Handler = Handler()
    private var countDownTimer: CountDownTimer? = null
    private val time=14000L

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMemberAccessBinding.inflate(layoutInflater)
        setContentView(binding.root)
        TopBarUtils.setStatusBar(this.window)
        TopBarUtils.setLightStatusBar(this.window,true)
        TPAdManager.init(
            this@MemberAccessActivity,
            DApp.TAG,
            "6C000EF75603E28FF44B27BBA4A32E11",
            "D067789A71596B4925D5C97397EE7712",
            "7C75F80B7EA2B803013A08F4A7145B12",
            "2CD1AA77B2DB4019DFD9D278A8E54D12"
        ) {
            null
        }

        countDownTimer = TPAdManager.showWelcomeAd(
            this@MemberAccessActivity,
            time,
            { aLong ->
                val progressPercentage = (100 * aLong) / time
                val percentage = 100 - progressPercentage
                binding.progressbar.progress = percentage.toInt()
            },
            {
                binding.progressbar.progress = 100
                val intent= Intent(
                    this@MemberAccessActivity,
                    SortActivity::class.java
                )
                startActivity(intent)
                finish()
            }
        )
        countDownTimer?.start()

    }

    override fun onDestroy() {
        super.onDestroy()
        handler.removeCallbacksAndMessages(null)

        if (countDownTimer != null) {
            countDownTimer!!.cancel()
        }
    }
}