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.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

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMemberAccessBinding.inflate(layoutInflater)
        setContentView(binding.root)
        TopBarUtils.setStatusBar(this.window)
        TopBarUtils.setLightStatusBar(this.window,true)
        handler.postDelayed({
            val intent= Intent(
                this@MemberAccessActivity,
                SortActivity::class.java
            )
            startActivity(intent)
            finish()
        }, 4000)
        countDownTimer = object : CountDownTimer(4000, 100) {
            override fun onTick(millisUntilFinished: Long) {
                val progress = ((4000 - millisUntilFinished) / 4000f * 100).toInt()
                binding.progressbar.progress = progress
            }

            override fun onFinish() {
                binding.progressbar.progress = 100
            }
        }.start()
    }

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

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