mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
improved selection of default apps
This commit is contained in:
parent
acbcef5827
commit
6a42ef0747
3 changed files with 41 additions and 24 deletions
|
@ -10,6 +10,7 @@ import android.widget.Toast
|
||||||
import de.jrpie.android.launcher.R
|
import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.apps.AppInfo
|
import de.jrpie.android.launcher.apps.AppInfo
|
||||||
import de.jrpie.android.launcher.apps.AppInfo.Companion.INVALID_USER
|
import de.jrpie.android.launcher.apps.AppInfo.Companion.INVALID_USER
|
||||||
|
import de.jrpie.android.launcher.apps.DetailedAppInfo
|
||||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||||
|
|
||||||
interface Action {
|
interface Action {
|
||||||
|
@ -22,7 +23,18 @@ interface Action {
|
||||||
fun writeToIntent(intent: Intent)
|
fun writeToIntent(intent: Intent)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun fromId(id: String, user: Int?): Action? {
|
/**
|
||||||
|
* Get an action for a specific id.
|
||||||
|
* An id is of the form:
|
||||||
|
* - "launcher:${launcher_action_name}", see [LauncherAction]
|
||||||
|
* - "${package_name}", see [AppAction]
|
||||||
|
* - "${package_name}:${activity_name}", see [AppAction]
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param user a user id, ignored if the action is a [LauncherAction].
|
||||||
|
* @param context used to complete [AppInfo] if possible
|
||||||
|
*/
|
||||||
|
private fun fromId(id: String, user: Int?, context: Context? = null): Action? {
|
||||||
if (id.isEmpty()) {
|
if (id.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -32,7 +44,14 @@ interface Action {
|
||||||
|
|
||||||
val values = id.split(";")
|
val values = id.split(";")
|
||||||
|
|
||||||
return AppAction(AppInfo(values[0], values.getOrNull(1), user ?: INVALID_USER))
|
var info = AppInfo(values[0], values.getOrNull(1), user ?: INVALID_USER)
|
||||||
|
|
||||||
|
// try to complete an incomplete AppInfo if a context is provided
|
||||||
|
if (context != null && (info.user == INVALID_USER || info.activityName == null)) {
|
||||||
|
info = DetailedAppInfo.fromAppInfo(info, context)?.app?:info
|
||||||
|
}
|
||||||
|
|
||||||
|
return AppAction(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun forGesture(gesture: Gesture): Action? {
|
fun forGesture(gesture: Gesture): Action? {
|
||||||
|
@ -48,12 +67,17 @@ interface Action {
|
||||||
|
|
||||||
fun resetToDefaultActions(context: Context) {
|
fun resetToDefaultActions(context: Context) {
|
||||||
val editor = LauncherPreferences.getSharedPreferences().edit()
|
val editor = LauncherPreferences.getSharedPreferences().edit()
|
||||||
|
val boundActions = HashSet<String>()
|
||||||
Gesture.entries.forEach { gesture ->
|
Gesture.entries.forEach { gesture ->
|
||||||
context.resources
|
context.resources
|
||||||
.getStringArray(gesture.defaultsResource)
|
.getStringArray(gesture.defaultsResource)
|
||||||
.map { fromId(it, null) }
|
.filterNot { boundActions.contains(it) }
|
||||||
.firstOrNull { it?.isAvailable(context) ?: false }
|
.map { Pair(it, fromId(it, null, context)) }
|
||||||
?.bindToGesture(editor, gesture.id)
|
.firstOrNull { it.second?.isAvailable(context) ?: false }
|
||||||
|
?.apply {
|
||||||
|
boundActions.add(first)
|
||||||
|
second?.bindToGesture(editor, gesture.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,28 +117,28 @@ enum class Gesture(
|
||||||
"action.left",
|
"action.left",
|
||||||
R.string.settings_gesture_left,
|
R.string.settings_gesture_left,
|
||||||
R.string.settings_gesture_description_left,
|
R.string.settings_gesture_description_left,
|
||||||
R.array.default_left,
|
R.array.default_messengers,
|
||||||
R.anim.right_left
|
R.anim.right_left
|
||||||
),
|
),
|
||||||
SWIPE_LEFT_TOP_EDGE(
|
SWIPE_LEFT_TOP_EDGE(
|
||||||
"action.left_top",
|
"action.left_top",
|
||||||
R.string.settings_gesture_left_top_edge,
|
R.string.settings_gesture_left_top_edge,
|
||||||
R.string.settings_gesture_description_left_top_edge,
|
R.string.settings_gesture_description_left_top_edge,
|
||||||
R.array.default_left_top,
|
R.array.default_messengers,
|
||||||
R.anim.right_left
|
R.anim.right_left
|
||||||
),
|
),
|
||||||
SWIPE_LEFT_BOTTOM_EDGE(
|
SWIPE_LEFT_BOTTOM_EDGE(
|
||||||
"action.left_bottom",
|
"action.left_bottom",
|
||||||
R.string.settings_gesture_left_bottom_edge,
|
R.string.settings_gesture_left_bottom_edge,
|
||||||
R.string.settings_gesture_description_left_bottom_edge,
|
R.string.settings_gesture_description_left_bottom_edge,
|
||||||
R.array.default_left_bottom,
|
R.array.default_messengers,
|
||||||
R.anim.right_left
|
R.anim.right_left
|
||||||
),
|
),
|
||||||
SWIPE_LEFT_DOUBLE(
|
SWIPE_LEFT_DOUBLE(
|
||||||
"action.double_left",
|
"action.double_left",
|
||||||
R.string.settings_gesture_double_left,
|
R.string.settings_gesture_double_left,
|
||||||
R.string.settings_gesture_description_double_left,
|
R.string.settings_gesture_description_double_left,
|
||||||
R.array.default_double_left,
|
R.array.default_messengers,
|
||||||
R.anim.right_left
|
R.anim.right_left
|
||||||
),
|
),
|
||||||
SWIPE_RIGHT(
|
SWIPE_RIGHT(
|
||||||
|
|
|
@ -88,31 +88,22 @@
|
||||||
<item>info.tangential.cone</item>
|
<item>info.tangential.cone</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<!-- Swipe left - Messengers -->
|
<string-array name="default_messengers">
|
||||||
<string-array name="default_left">
|
|
||||||
<item>de.spiritcroc.riotx</item> <!-- SchildiChat -->
|
<item>de.spiritcroc.riotx</item> <!-- SchildiChat -->
|
||||||
<item>io.element.android.x</item> <!-- Element X -->
|
<item>io.element.android.x</item> <!-- Element X -->
|
||||||
<item>im.vector.app</item> <!-- Element -->
|
<item>im.vector.app</item> <!-- Element -->
|
||||||
<item>org.thoughtcrime.securesms</item> <!-- Signal -->
|
<item>org.thoughtcrime.securesms</item> <!-- Signal -->
|
||||||
</string-array>
|
<item>org.briarproject.briar.android</item> <!-- Briar -->
|
||||||
|
<item>eu.siacs.conversations</item> <!-- Conversations -->
|
||||||
<string-array name="default_left_top">
|
<item>ch.threema.app.libre</item> <!-- Threema -->
|
||||||
<item>com.android.messaging</item> <!-- SMS -->
|
<item>com.android.messaging</item> <!-- SMS -->
|
||||||
<item>com.android.google.messaging</item> <!-- SMS -->
|
<item>com.google.android.apps.messaging</item> <!-- SMS -->
|
||||||
<item>com.samsung.android.messaging</item> <!-- Samsung SMS -->
|
<item>com.samsung.android.messaging</item> <!-- Samsung SMS -->
|
||||||
</string-array>
|
|
||||||
<string-array name="default_left_bottom">
|
|
||||||
<item>org.thoughtcrime.securesms</item> <!-- Signal -->
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Swipe double left - More messengers -->
|
|
||||||
<string-array name="default_double_left">
|
|
||||||
<item>com.whatsapp</item> <!-- WhatsApp -->
|
<item>com.whatsapp</item> <!-- WhatsApp -->
|
||||||
<item>org.telegram.messenger</item> <!-- Telegram -->
|
<item>org.telegram.messenger</item> <!-- Telegram -->
|
||||||
|
<item>com.discord</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|
||||||
<!-- Volume up -->
|
<!-- Volume up -->
|
||||||
<string-array name="default_volume_up">
|
<string-array name="default_volume_up">
|
||||||
<item>launcher:volumeUp</item>
|
<item>launcher:volumeUp</item>
|
||||||
|
@ -135,6 +126,8 @@
|
||||||
<string-array name="default_long_click">
|
<string-array name="default_long_click">
|
||||||
<item>com.beemdevelopment.aegis</item> <!-- Aegis 2FA -->
|
<item>com.beemdevelopment.aegis</item> <!-- Aegis 2FA -->
|
||||||
<item>org.fedorahosted.freeotp</item>
|
<item>org.fedorahosted.freeotp</item>
|
||||||
|
<item>proton.android.pass.fdroid</item> <!-- Proton Pass -->
|
||||||
|
<item>com.kunzisoft.keepass.libre</item> <!-- KeePassDX -->
|
||||||
<item>launcher:settings</item> <!-- Launcher Settings -->
|
<item>launcher:settings</item> <!-- Launcher Settings -->
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue