package com.android.launcher3.function.setting

import android.content.Context
import android.content.Intent
import android.icu.lang.UCharacter.DecompositionType
import android.os.Bundle
import android.view.View
import android.widget.GridLayout
import com.android.launcher3.BaseActivity
import com.android.launcher3.BuildConfig
import com.android.launcher3.R
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
import com.secspace.lib.common.update.CheckUpdateCore
import com.secspace.lib.common.utils.ImeiUtil
import com.secspace.lib.common.utils.dp2px
import kotlinx.android.synthetic.main.activity_setting.*

class SettingAboutActivity : BaseActivity() {
    private var mContext: Context? = null
    private var version: QMUICommonListItemView? = null
    private var update: QMUICommonListItemView? = null
    private var privacy: QMUICommonListItemView? = null
    private var uniqueId: 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_about)
        version = grouplistview.createItemView(null,
                getString(R.string.edu_item_version),
                String.format(getString(R.string.edu_version), BuildConfig.VERSION_NAME),
                DecompositionType.VERTICAL,
                QMUICommonListItemView.ACCESSORY_TYPE_NONE,
                dp2px(48f))
        privacy = grouplistview.createItemView(null,
                getString(R.string.edu_item_privacy),
                null,
                GridLayout.HORIZONTAL,
                QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON,
                dp2px(48f))
        update = grouplistview.createItemView(null,
                getString(R.string.edu_item_update),
                null,
                GridLayout.HORIZONTAL,
                QMUICommonListItemView.ACCESSORY_TYPE_CHEVRON,
                dp2px(48f))
        uniqueId = grouplistview.createItemView(null,
                getString(R.string.edu_item_unique),
                ImeiUtil.uniqueId(mContext, true),
                DecompositionType.VERTICAL,
                QMUICommonListItemView.ACCESSORY_TYPE_NONE,
                dp2px(48f))
        QMUIGroupListView.newSection(mContext)
                .addItemView(version) { }
                .addItemView(uniqueId) { }
                .addItemView(update) { CheckUpdateCore.get().checkUpdate(true) }
                .addItemView(privacy) { startActivity(Intent(mContext, PrivacyPolicyActivity::class.java)) }
                .addTo(grouplistview)
    }

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