improved selection of default apps

This commit is contained in:
Josia Pietsch 2024-11-12 02:47:09 +01:00
parent acbcef5827
commit 6a42ef0747
Signed by: jrpie
GPG key ID: E70B571D66986A2D
3 changed files with 41 additions and 24 deletions

View file

@ -10,6 +10,7 @@ import android.widget.Toast
import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.apps.AppInfo
import de.jrpie.android.launcher.apps.AppInfo.Companion.INVALID_USER
import de.jrpie.android.launcher.apps.DetailedAppInfo
import de.jrpie.android.launcher.preferences.LauncherPreferences
interface Action {
@ -22,7 +23,18 @@ interface Action {
fun writeToIntent(intent: Intent)
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()) {
return null
}
@ -32,7 +44,14 @@ interface Action {
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? {
@ -48,12 +67,17 @@ interface Action {
fun resetToDefaultActions(context: Context) {
val editor = LauncherPreferences.getSharedPreferences().edit()
val boundActions = HashSet<String>()
Gesture.entries.forEach { gesture ->
context.resources
.getStringArray(gesture.defaultsResource)
.map { fromId(it, null) }
.firstOrNull { it?.isAvailable(context) ?: false }
?.bindToGesture(editor, gesture.id)
.filterNot { boundActions.contains(it) }
.map { Pair(it, fromId(it, null, context)) }
.firstOrNull { it.second?.isAvailable(context) ?: false }
?.apply {
boundActions.add(first)
second?.bindToGesture(editor, gesture.id)
}
}
editor.apply()
}

View file

@ -117,28 +117,28 @@ enum class Gesture(
"action.left",
R.string.settings_gesture_left,
R.string.settings_gesture_description_left,
R.array.default_left,
R.array.default_messengers,
R.anim.right_left
),
SWIPE_LEFT_TOP_EDGE(
"action.left_top",
R.string.settings_gesture_left_top_edge,
R.string.settings_gesture_description_left_top_edge,
R.array.default_left_top,
R.array.default_messengers,
R.anim.right_left
),
SWIPE_LEFT_BOTTOM_EDGE(
"action.left_bottom",
R.string.settings_gesture_left_bottom_edge,
R.string.settings_gesture_description_left_bottom_edge,
R.array.default_left_bottom,
R.array.default_messengers,
R.anim.right_left
),
SWIPE_LEFT_DOUBLE(
"action.double_left",
R.string.settings_gesture_double_left,
R.string.settings_gesture_description_double_left,
R.array.default_double_left,
R.array.default_messengers,
R.anim.right_left
),
SWIPE_RIGHT(

View file

@ -88,31 +88,22 @@
<item>info.tangential.cone</item>
</string-array>
<!-- Swipe left - Messengers -->
<string-array name="default_left">
<string-array name="default_messengers">
<item>de.spiritcroc.riotx</item> <!-- SchildiChat -->
<item>io.element.android.x</item> <!-- Element X -->
<item>im.vector.app</item> <!-- Element -->
<item>org.thoughtcrime.securesms</item> <!-- Signal -->
</string-array>
<string-array name="default_left_top">
<item>org.briarproject.briar.android</item> <!-- Briar -->
<item>eu.siacs.conversations</item> <!-- Conversations -->
<item>ch.threema.app.libre</item> <!-- Threema -->
<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 -->
</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>org.telegram.messenger</item> <!-- Telegram -->
<item>com.discord</item>
</string-array>
<!-- Volume up -->
<string-array name="default_volume_up">
<item>launcher:volumeUp</item>
@ -135,6 +126,8 @@
<string-array name="default_long_click">
<item>com.beemdevelopment.aegis</item> <!-- Aegis 2FA -->
<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 -->
</string-array>