package com.android.launcher3.function.setting

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.GridLayout
import com.android.launcher3.BaseActivity
import com.android.launcher3.R
import com.android.launcher3.mdm.DisableCompat
import com.android.launcher3.settings.Contants
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
import com.secspace.lib.common.utils.PkgManager
import com.secspace.lib.common.utils.Prefs
import com.secspace.lib.common.utils.ToastUtil
import com.secspace.lib.common.utils.dp2px
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) {
                    val intent1 = Intent(this, ChangePwdActivity::class.java)
                    intent1.putExtra(Contants.IS_SHOW_ORIGINAL_PWD, true)
                    startActivity(intent1)
                }
                .addItemView(pwdCar) {
                    ToastUtil.showShort(mContext, R.string.edu_toast_wait)
                }
                .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)
        }
    }
}