mirror of https://github.com/x13a/Wasted.git
move PanicKit and code to launchers
This commit is contained in:
parent
5f31be5eba
commit
88da4bcc37
|
@ -51,6 +51,7 @@
|
|||
<activity
|
||||
android:name=".PanicResponderActivity"
|
||||
android:noHistory="true"
|
||||
android:enabled="false"
|
||||
android:exported="true"
|
||||
android:theme="@android:style/Theme.NoDisplay">
|
||||
<intent-filter>
|
||||
|
@ -62,6 +63,7 @@
|
|||
<activity
|
||||
android:name=".PanicConnectionActivity"
|
||||
android:noHistory="true"
|
||||
android:enabled="false"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="info.guardianproject.panic.action.CONNECT" />
|
||||
|
|
|
@ -88,14 +88,8 @@ open class MainActivity : AppCompatActivity() {
|
|||
|
||||
private fun setup() {
|
||||
binding.apply {
|
||||
description.setOnLongClickListener {
|
||||
showLaunchersSettings()
|
||||
true
|
||||
}
|
||||
code.setOnClickListener {
|
||||
prefs.isCodeEnabled = !prefs.isCodeEnabled
|
||||
updateCodeColorState()
|
||||
setCodeReceiverState(prefs.isServiceEnabled && prefs.isCodeEnabled)
|
||||
showLaunchersSettings()
|
||||
}
|
||||
code.setOnLongClickListener {
|
||||
prefs.code = makeCode()
|
||||
|
@ -172,7 +166,7 @@ open class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
prefs.launchers = launchers
|
||||
setLaunchers(prefs.isServiceEnabled)
|
||||
setLaunchersState(prefs.isServiceEnabled)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
@ -196,7 +190,7 @@ open class MainActivity : AppCompatActivity() {
|
|||
|
||||
private fun updateCodeColorState() {
|
||||
binding.code.setBackgroundColor(getColor(
|
||||
if (prefs.isCodeEnabled) R.color.code_receiver_on else R.color.code_receiver_off
|
||||
if (prefs.launchers != 0) R.color.code_receiver_on else R.color.code_receiver_off
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -207,19 +201,23 @@ open class MainActivity : AppCompatActivity() {
|
|||
return
|
||||
}
|
||||
prefs.isServiceEnabled = true
|
||||
setCodeReceiverState(prefs.isCodeEnabled)
|
||||
setLaunchers(true)
|
||||
setLaunchersState(true)
|
||||
}
|
||||
|
||||
private fun setLaunchers(value: Boolean) {
|
||||
private fun setLaunchersState(value: Boolean) {
|
||||
if (value) {
|
||||
val launchers = prefs.launchers
|
||||
setPanicKitState(launchers.and(Launcher.PANIC_KIT.flag) != 0)
|
||||
setTileState(launchers.and(Launcher.TILE.flag) != 0)
|
||||
if (launchers.and(Launcher.SHORTCUT.flag) != 0) shortcut.push() else shortcut.remove()
|
||||
shortcut.setState(launchers.and(Launcher.SHORTCUT.flag) != 0)
|
||||
setCodeReceiverState(launchers.and(Launcher.CODE.flag) != 0)
|
||||
} else {
|
||||
setPanicKitState(false)
|
||||
setTileState(false)
|
||||
shortcut.remove()
|
||||
shortcut.setState(false)
|
||||
setCodeReceiverState(false)
|
||||
}
|
||||
updateCodeColorState()
|
||||
}
|
||||
|
||||
private fun showWipeJobServiceStartFailedPopup() {
|
||||
|
@ -232,9 +230,8 @@ open class MainActivity : AppCompatActivity() {
|
|||
|
||||
private fun setOff() {
|
||||
prefs.isServiceEnabled = false
|
||||
setCodeReceiverState(false)
|
||||
setWipeOnInactivityComponentsState(false)
|
||||
setLaunchers(false)
|
||||
setLaunchersState(false)
|
||||
admin.remove()
|
||||
}
|
||||
|
||||
|
@ -247,6 +244,11 @@ open class MainActivity : AppCompatActivity() {
|
|||
private fun setTileState(value: Boolean) =
|
||||
setComponentState(QSTileService::class.java, value)
|
||||
|
||||
private fun setPanicKitState(value: Boolean) {
|
||||
setComponentState(PanicConnectionActivity::class.java, value)
|
||||
setComponentState(PanicResponderActivity::class.java, value)
|
||||
}
|
||||
|
||||
private fun setComponentState(cls: Class<*>, value: Boolean) {
|
||||
packageManager.setComponentEnabledSetting(
|
||||
ComponentName(this, cls),
|
||||
|
|
|
@ -17,12 +17,12 @@ class Preferences(ctx: Context) {
|
|||
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"
|
||||
// migration
|
||||
private const val DO_WIPE = "do_wipe"
|
||||
private const val CODE_ENABLED = "code_enabled"
|
||||
private const val WIPE_ON_INACTIVE = "wipe_on_inactive"
|
||||
private const val WIPE_ON_INACTIVE_DAYS = "wipe_on_inactive_days"
|
||||
}
|
||||
|
@ -41,17 +41,16 @@ class Preferences(ctx: Context) {
|
|||
set(value) = prefs.edit { putBoolean(SERVICE_ENABLED, value) }
|
||||
|
||||
var launchers: Int
|
||||
get() = prefs.getInt(LAUNCHERS, 0)
|
||||
get() = prefs.getInt(
|
||||
LAUNCHERS,
|
||||
if (prefs.getBoolean(CODE_ENABLED, false)) Launcher.CODE.flag else 0,
|
||||
)
|
||||
set(value) = prefs.edit { putInt(LAUNCHERS, value) }
|
||||
|
||||
var code: String
|
||||
get() = prefs.getString(CODE, "") ?: ""
|
||||
set(value) = prefs.edit { putString(CODE, value) }
|
||||
|
||||
var isCodeEnabled: Boolean
|
||||
get() = prefs.getBoolean(CODE_ENABLED, false)
|
||||
set(value) = prefs.edit { putBoolean(CODE_ENABLED, value) }
|
||||
|
||||
var isWipeData: Boolean
|
||||
get() = prefs.getBoolean(WIPE_DATA, prefs.getBoolean(DO_WIPE, false))
|
||||
set(value) = prefs.edit { putBoolean(WIPE_DATA, value) }
|
||||
|
@ -80,6 +79,8 @@ class Preferences(ctx: Context) {
|
|||
}
|
||||
|
||||
enum class Launcher(val flag: Int) {
|
||||
TILE(1),
|
||||
SHORTCUT(1 shl 1),
|
||||
PANIC_KIT(1),
|
||||
TILE(1 shl 1),
|
||||
SHORTCUT(1 shl 2),
|
||||
CODE(1 shl 3)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ class ShortcutManager(private val ctx: Context) {
|
|||
|
||||
private val prefs by lazy { Preferences(ctx) }
|
||||
|
||||
fun push() {
|
||||
private fun push() {
|
||||
ShortcutManagerCompat.pushDynamicShortcut(
|
||||
ctx,
|
||||
ShortcutInfoCompat.Builder(ctx, SHORTCUT_ID)
|
||||
|
@ -28,5 +28,6 @@ class ShortcutManager(private val ctx: Context) {
|
|||
)
|
||||
}
|
||||
|
||||
fun remove() = ShortcutManagerCompat.removeDynamicShortcuts(ctx, arrayListOf(SHORTCUT_ID))
|
||||
private fun remove() = ShortcutManagerCompat.removeDynamicShortcuts(ctx, arrayListOf(SHORTCUT_ID))
|
||||
fun setState(value: Boolean) = if (value) push() else remove()
|
||||
}
|
|
@ -28,7 +28,9 @@
|
|||
<string name="dialog_confirm_panic_message">Активировать тревогу\? Это заблокирует устройство и опционально сотрёт его данные.</string>
|
||||
<string name="yes">Да</string>
|
||||
<string-array name="launchers">
|
||||
<item>PanicKit</item>
|
||||
<item>Плитка</item>
|
||||
<item>Ярлык</item>
|
||||
<item>Код</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
<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>PanicKit</item>
|
||||
<item>Tile</item>
|
||||
<item>Shortcut</item>
|
||||
<item>Code</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue