implemented #67 - option to hide apps that are bound to gestures

This commit is contained in:
Josia Pietsch 2024-11-12 01:53:41 +01:00
parent c1dcc0fe4e
commit acbcef5827
Signed by: jrpie
GPG key ID: E70B571D66986A2D
8 changed files with 48 additions and 15 deletions

View file

@ -16,7 +16,7 @@ import de.jrpie.android.launcher.apps.DetailedAppInfo
import de.jrpie.android.launcher.getIntent import de.jrpie.android.launcher.getIntent
import de.jrpie.android.launcher.openAppSettings import de.jrpie.android.launcher.openAppSettings
class AppAction(private var appInfo: AppInfo) : Action { class AppAction(val appInfo: AppInfo) : Action {
override fun invoke(context: Context, rect: Rect?): Boolean { override fun invoke(context: Context, rect: Rect?): Boolean {
val packageName = appInfo.packageName.toString() val packageName = appInfo.packageName.toString()

View file

@ -2,6 +2,7 @@ package de.jrpie.android.launcher.actions
import android.content.Context import android.content.Context
import de.jrpie.android.launcher.R import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.preferences.LauncherPreferences
/** /**
* @param id internal id to serialize the action. Used as a key in shared preferences. * @param id internal id to serialize the action. Used as a key in shared preferences.
@ -32,14 +33,18 @@ enum class Gesture(
R.string.settings_gesture_description_vol_down, R.string.settings_gesture_description_vol_down,
R.array.default_volume_down, 0, 0 R.array.default_volume_down, 0, 0
), ),
TIME("action.time", TIME(
"action.time",
R.string.settings_gesture_time, R.string.settings_gesture_time,
R.string.settings_gesture_description_time, R.string.settings_gesture_description_time,
R.array.default_time), R.array.default_time
DATE("action.date", ),
DATE(
"action.date",
R.string.settings_gesture_date, R.string.settings_gesture_date,
R.string.settings_gesture_description_date, R.string.settings_gesture_description_date,
R.array.default_date), R.array.default_date
),
LONG_CLICK( LONG_CLICK(
"action.long_click", "action.long_click",
R.string.settings_gesture_long_click, R.string.settings_gesture_long_click,
@ -52,11 +57,13 @@ enum class Gesture(
R.string.settings_gesture_description_double_click, R.string.settings_gesture_description_double_click,
R.array.default_double_click, 0, 0 R.array.default_double_click, 0, 0
), ),
SWIPE_UP("action.up", SWIPE_UP(
"action.up",
R.string.settings_gesture_up, R.string.settings_gesture_up,
R.string.settings_gesture_description_up, R.string.settings_gesture_description_up,
R.array.default_up, R.array.default_up,
R.anim.bottom_up), R.anim.bottom_up
),
SWIPE_UP_LEFT_EDGE( SWIPE_UP_LEFT_EDGE(
"action.up_left", "action.up_left",
R.string.settings_gesture_up_left_edge, R.string.settings_gesture_up_left_edge,
@ -170,6 +177,7 @@ enum class Gesture(
fun getLabel(context: Context): String { fun getLabel(context: Context): String {
return context.resources.getString(this.labelResource) return context.resources.getString(this.labelResource)
} }
fun getDescription(context: Context): String { fun getDescription(context: Context): String {
return context.resources.getString(this.descriptionResource) return context.resources.getString(this.descriptionResource)
} }
@ -242,6 +250,16 @@ enum class Gesture(
} }
} }
fun isEnabled(): Boolean {
if (isEdgeVariant()) {
return LauncherPreferences.enabled_gestures().edgeSwipe()
}
if (isDoubleVariant()) {
return LauncherPreferences.enabled_gestures().doubleSwipe()
}
return true
}
operator fun invoke(context: Context) { operator fun invoke(context: Context) {
val action = Action.forGesture(this) val action = Action.forGesture(this)
Action.launch(action, context, this.animationIn, this.animationOut) Action.launch(action, context, this.animationIn, this.animationOut)

View file

@ -1,5 +1,8 @@
package de.jrpie.android.launcher.apps package de.jrpie.android.launcher.apps
import de.jrpie.android.launcher.actions.Action
import de.jrpie.android.launcher.actions.AppAction
import de.jrpie.android.launcher.actions.Gesture
import de.jrpie.android.launcher.preferences.LauncherPreferences import de.jrpie.android.launcher.preferences.LauncherPreferences
import java.util.Locale import java.util.Locale
import kotlin.text.Regex.Companion.escapeReplacement import kotlin.text.Regex.Companion.escapeReplacement
@ -14,20 +17,29 @@ class AppFilter(
val hidden = LauncherPreferences.apps().hidden() ?: setOf() val hidden = LauncherPreferences.apps().hidden() ?: setOf()
val favorites = LauncherPreferences.apps().favorites() ?: setOf() val favorites = LauncherPreferences.apps().favorites() ?: setOf()
apps = apps.filter { info -> apps = apps.filter { info ->
favoritesVisibility.predicate(favorites, info) favoritesVisibility.predicate(favorites, info)
&& hiddenVisibility.predicate(hidden, info) && hiddenVisibility.predicate(hidden, info)
} }
if (LauncherPreferences.apps().hideBoundApps()) {
val boundApps = Gesture.entries
.filter(Gesture::isEnabled)
.mapNotNull { g -> (Action.forGesture(g) as? AppAction)?.appInfo }
.toSet()
apps = apps.filterNot { info -> boundApps.contains(info.app) }
}
// normalize text for search // normalize text for search
var allowedSpecialCharacters = search val allowedSpecialCharacters = search
.lowercase(Locale.ROOT) .lowercase(Locale.ROOT)
.toCharArray() .toCharArray()
.distinct() .distinct()
.filter { c -> !c.isLetter() } .filter { c -> !c.isLetter() }
.map { c -> escapeReplacement(c.toString()) } .map { c -> escapeReplacement(c.toString()) }
.fold("") { x, y -> x + y } .fold("") { x, y -> x + y }
var disallowedCharsRegex = "[^\\p{L}$allowedSpecialCharacters]".toRegex() val disallowedCharsRegex = "[^\\p{L}$allowedSpecialCharacters]".toRegex()
fun normalize(text: String): String { fun normalize(text: String): String {
return text.lowercase(Locale.ROOT).replace(disallowedCharsRegex, "") return text.lowercase(Locale.ROOT).replace(disallowedCharsRegex, "")

View file

@ -28,6 +28,7 @@ import eu.jonahbauer.android.preference.annotations.serializer.PreferenceSeriali
@PreferenceGroup(name = "apps", prefix = "settings_apps_", suffix = "_key", value = { @PreferenceGroup(name = "apps", prefix = "settings_apps_", suffix = "_key", value = {
@Preference(name = "favorites", type = Set.class, serializer = LauncherPreferences$Config.AppInfoSetSerializer.class), @Preference(name = "favorites", type = Set.class, serializer = LauncherPreferences$Config.AppInfoSetSerializer.class),
@Preference(name = "hidden", type = Set.class, serializer = LauncherPreferences$Config.AppInfoSetSerializer.class), @Preference(name = "hidden", type = Set.class, serializer = LauncherPreferences$Config.AppInfoSetSerializer.class),
@Preference(name = "hide_bound_apps", type = boolean.class, defaultValue = "false"),
}), }),
@PreferenceGroup(name = "gestures", prefix = "settings_gesture_", suffix = "_key", value = { @PreferenceGroup(name = "gestures", prefix = "settings_gesture_", suffix = "_key", value = {
}), }),

View file

@ -155,12 +155,7 @@ class ActionsRecyclerAdapter(val activity: Activity) :
} }
init { init {
val doubleActions = LauncherPreferences.enabled_gestures().doubleSwipe() gesturesList = Gesture.entries.filter(Gesture::isEnabled) as ArrayList<Gesture>
val edgeActions = LauncherPreferences.enabled_gestures().edgeSwipe()
gesturesList = Gesture.entries.filter {
(doubleActions || !it.isDoubleVariant())
&& (edgeActions || !it.isEdgeVariant())
} as ArrayList<Gesture>
} }
fun updateActions() { fun updateActions() {

View file

@ -11,6 +11,7 @@
<string name="settings_internal_version_code_key" translatable="false">internal.version_code</string> <string name="settings_internal_version_code_key" translatable="false">internal.version_code</string>
<string name="settings_apps_favorites_key" translatable="false">apps.favorites</string> <string name="settings_apps_favorites_key" translatable="false">apps.favorites</string>
<string name="settings_apps_hidden_key" translatable="false">apps.hidden</string> <string name="settings_apps_hidden_key" translatable="false">apps.hidden</string>
<string name="settings_apps_hide_bound_apps_key" translatable="false">apps.hide_bound_apps</string>
<string name="settings_general_choose_home_screen_key" translatable="false">general.select_launcher</string> <string name="settings_general_choose_home_screen_key" translatable="false">general.select_launcher</string>
<!-- <!--

View file

@ -142,6 +142,7 @@
<string name="settings_launcher_section_apps">Apps</string> <string name="settings_launcher_section_apps">Apps</string>
<string name="settings_apps_hidden">Hidden apps</string> <string name="settings_apps_hidden">Hidden apps</string>
<string name="settings_apps_hide_bound_apps">Don\'t show apps that are bound to a gesture in the app list</string>
<!-- <!--
- -

View file

@ -124,6 +124,11 @@
android:title="@string/settings_apps_hidden" android:title="@string/settings_apps_hidden"
/> />
<SwitchPreference
android:key="@string/settings_apps_hide_bound_apps_key"
android:title="@string/settings_apps_hide_bound_apps"
android:defaultValue="false" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/settings_launcher_section_display" android:title="@string/settings_launcher_section_display"