package pxds.etmo.lexn.ylyy

import android.os.Handler
import com.blankj.utilcode.util.SPUtils
import com.test.basd.supercleanermax.R
import com.test.basd.supercleanermax.databinding.AfqrlyBinding
import pxds.lmmd.zmwf.Khko.string

class Azmb {

    private val binding: AfqrlyBinding

    private val listener:ProgressListener

    private var mIsPaused = false

    private var mHandler: Handler

    private var mProgress = 0

    fun maxProgress() {
        binding.shnrslm.progress = binding.shnrslm.max
        listener.onProgressMax()
    }

    interface ProgressListener{
         fun onProgressMax()
    }

    fun resumeProgress() {
        if (mIsPaused) {
            mIsPaused = false
            startProgress()
        }
    }

    fun pauseProgress() {
        if (!mIsPaused) {
            mIsPaused = true
            mHandler.removeCallbacksAndMessages(null)
        }
    }

    fun startProgress() {
        val mRunnable: Runnable = object : Runnable {
            override fun run() {
                if (!mIsPaused) {
                    mProgress++
                    binding.shnrslm.progress = mProgress
                    if (mProgress < 9) {
                        mHandler.postDelayed(this, 1000)
                    } else {
                        listener.onProgressMax()
                        pauseProgress()
                    }
                }
            }
        }
        mHandler.postDelayed(mRunnable, 1000)
    }

    private fun initView() {
        val loadTime = SPUtils.getInstance().getInt(R.string.ވޘލހސ_D.string(), 15)
        binding.shnrslm.max = loadTime
        binding.shnrslm.progress = 0

    }

    constructor(binding: AfqrlyBinding, listener: ProgressListener) {
        this.binding = binding
        this.listener = listener
        mHandler = Handler()
        initView()
    }
}