package com.android.launcher3.function.pwd

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.EditText
import android.widget.GridLayout
import com.android.launcher3.BaseActivity
import com.android.launcher3.R
import com.android.launcher3.mdm.DisableCompat
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
import com.secspace.lib.common.dialog.other.DialogUIUtils
import com.secspace.lib.common.function.DialogManager.PwdListener
import com.secspace.lib.common.function.DialogManager.showEncryptedVerDialog
import com.secspace.lib.common.function.model.Encrypted
import com.secspace.lib.common.utils.*
import kotlinx.android.synthetic.main.activity_setting.*

class SettingPwdActivity : BaseActivity(){
    private var mContext: Context? = null
    private var pwd: QMUICommonListItemView? = null
    private var pwdCar: QMUICommonListItemView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setAndroidNativeLightStatusBar(true)
        setContentView(R.layout.activity_setting)
        mContext = this
        initView()
    }

    private fun initView() {
        tv_setting_title.setText(R.string.edu_item_pwd_manager)
        pwd = grouplistview.createItemView(null,
                getString(R.string.edu_item_change_pwd),
                null,
                GridLayout.HORIZONTAL,
                QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON,
                dp2px(48f))
        pwdCar = grouplistview.createItemView(null,
                getString(R.string.edu_item_pwd_cer),
                null,
                GridLayout.HORIZONTAL,
                QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON,
                dp2px(48f))
        QMUIGroupListView.newSection(this)
                .addItemView(pwd) {
                    startActivity(Intent(this, ChangePwdActivity::class.java))
                }
                .addItemView(pwdCar) {
                    startActivity(Intent(this, EncryptedActivity::class.java))
                }
                .addTo(grouplistview)
    }

    fun close(view: View?) {
        finish()
    }

    private fun reinforce() {
        val packages: MutableList<String> = PkgManager.getInstance(mContext).queryLauncherPackages()
        packages.remove(mContext?.packageName)
        if(packages.isNotEmpty()){
            Prefs.setHideLauncherPackages(mContext, packages)
        }
        for (packageName in packages) {
            DisableCompat.disableApplication(mContext, packageName)
        }
    }
}