package com.test.basd.fastcleanerjunk.helps

import android.app.AppOpsManager
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.constant.PermissionConstants
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.PermissionUtils
import com.test.basd.fastcleanerjunk.activity.MainActivity
import com.test.basd.fastcleanerjunk.activity.PermissionTripActivity
import com.test.basd.fastcleanerjunk.view.DialogViews
import org.json.JSONObject

abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {

    protected abstract val binding: T

    protected open val isLightMode: Boolean? = null

    lateinit var launcher: ActivityLauncher

    override fun onCreate(savedInstanceState: Bundle?) {
        launcher = ActivityLauncher(this)
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        isLightMode?.let {
            BarUtils.setStatusBarLightMode(this, it)
        }

        EventHelper.event("page_${javaClass.simpleName}")

        initView()
        initListener()
    }

    protected abstract fun initView()

    protected open fun initListener() {}

    protected fun finishToMain() {
        if (this !is MainActivity && !ActivityUtils.isActivityExistsInStack(MainActivity::class.java)) {
            startActivity(Intent(this, MainActivity::class.java))
        }
        finish()
    }

    var dialog: Dialog? = null

    override fun onDestroy() {
        super.onDestroy()
        if (dialog != null) {
            dialog?.dismiss()
        }
    }
}