add option to toggle tile and shortcut

This commit is contained in:
lucky 2022-01-14 11:59:48 +03:00
parent 218012b8fc
commit c7e504eed6
4 changed files with 61 additions and 5 deletions

View File

@ -81,6 +81,10 @@ open class MainActivity : AppCompatActivity() {
private fun setup() {
binding.apply {
description.setOnLongClickListener {
showLaunchersSettings()
true
}
code.setOnClickListener {
prefs.isCodeEnabled = !prefs.isCodeEnabled
updateCodeColorState()
@ -138,6 +142,30 @@ open class MainActivity : AppCompatActivity() {
}
}
private fun showLaunchersSettings() {
var launchers = prefs.launchers
val checkedLaunchers = mutableListOf<Boolean>()
for (launcher in Launcher.values()) {
checkedLaunchers.add(launchers.and(launcher.flag) != 0)
}
MaterialAlertDialogBuilder(this)
.setMultiChoiceItems(
resources.getStringArray(R.array.launchers),
checkedLaunchers.toBooleanArray(),
) { _, index, isChecked ->
val value = Launcher.values()[index]
launchers = when (isChecked) {
true -> launchers.or(value.flag)
false -> launchers.and(value.flag.inv())
}
}
.setPositiveButton(R.string.ok) { _, _ ->
prefs.launchers = launchers
setLaunchers(prefs.isServiceEnabled)
}
.show()
}
private fun showWipeOnInactivitySettings() {
val items = arrayOf("1", "2", "3", "5", "7", "10", "15", "30")
var days = prefs.wipeOnInactivityDays
@ -169,8 +197,18 @@ open class MainActivity : AppCompatActivity() {
}
prefs.isServiceEnabled = true
setCodeReceiverState(prefs.isCodeEnabled)
setTileState(true)
shortcut.push()
setLaunchers(true)
}
private fun setLaunchers(value: Boolean) {
if (value) {
val launchers = prefs.launchers
setTileState(launchers.and(Launcher.TILE.flag) != 0)
if (launchers.and(Launcher.SHORTCUT.flag) != 0) shortcut.push() else shortcut.remove()
} else {
setTileState(false)
shortcut.remove()
}
}
private fun showWipeJobServiceStartFailedPopup() {
@ -185,8 +223,7 @@ open class MainActivity : AppCompatActivity() {
prefs.isServiceEnabled = false
setCodeReceiverState(false)
setWipeOnInactivityComponentsState(false)
setTileState(false)
shortcut.remove()
setLaunchers(false)
admin.remove()
}

View File

@ -11,11 +11,13 @@ class Preferences(ctx: Context) {
private const val SERVICE_ENABLED = "service_enabled"
private const val CODE = "code"
private const val CODE_ENABLED = "code_enabled"
private const val WIPE_DATA = "wipe_data"
private const val WIPE_ESIM = "wipe_esim"
private const val MAX_FAILED_PASSWORD_ATTEMPTS = "max_failed_password_attempts"
private const val WIPE_ON_INACTIVITY = "wipe_on_inactivity"
private const val LAUNCHERS = "launchers"
private const val CODE_ENABLED = "code_enabled"
private const val WIPE_ON_INACTIVITY_DAYS = "wipe_on_inactivity_days"
private const val FILE_NAME = "sec_shared_prefs"
@ -38,6 +40,10 @@ class Preferences(ctx: Context) {
get() = prefs.getBoolean(SERVICE_ENABLED, false)
set(value) = prefs.edit { putBoolean(SERVICE_ENABLED, value) }
var launchers: Int
get() = prefs.getInt(LAUNCHERS, 0)
set(value) = prefs.edit { putInt(LAUNCHERS, value) }
var code: String
get() = prefs.getString(CODE, "") ?: ""
set(value) = prefs.edit { putString(CODE, value) }
@ -72,3 +78,8 @@ class Preferences(ctx: Context) {
)
set(value) = prefs.edit { putInt(WIPE_ON_INACTIVITY_DAYS, value) }
}
enum class Launcher(val flag: Int) {
TILE(1),
SHORTCUT(1 shl 1),
}

View File

@ -27,4 +27,8 @@
<string name="dialog_confirm_panic_title">Подтвердите</string>
<string name="dialog_confirm_panic_message">Активировать тревогу\? Это заблокирует устройство и опционально сотрёт его данные.</string>
<string name="yes">Да</string>
<string-array name="launchers">
<item>Плитка</item>
<item>Ярлык</item>
</string-array>
</resources>

View File

@ -27,4 +27,8 @@
<string name="dialog_confirm_panic_title">Confirm</string>
<string name="dialog_confirm_panic_message">Activate panic\? This will lock a device and optionally wipe its data.</string>
<string name="yes">Yes</string>
<string-array name="launchers">
<item>Tile</item>
<item>Shortcut</item>
</string-array>
</resources>