mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-22 22:11:27 +01:00
implement #93 - treat back button as a gesture
Some checks failed
Android CI / build (push) Has been cancelled
Some checks failed
Android CI / build (push) Has been cancelled
This commit is contained in:
parent
fa2f1c4127
commit
944eb89fef
12 changed files with 108 additions and 13 deletions
|
@ -21,6 +21,9 @@ sealed interface Action {
|
|||
fun getIcon(context: Context): Drawable?
|
||||
fun isAvailable(context: Context): Boolean
|
||||
|
||||
// Can the action be used to reach µLauncher settings?
|
||||
fun canReachSettings(): Boolean
|
||||
|
||||
|
||||
fun bindToGesture(prefEditor: Editor, id: String) {
|
||||
prefEditor.putString(id, Json.encodeToString(this))
|
||||
|
@ -50,7 +53,10 @@ sealed interface Action {
|
|||
.map { Pair(it, Json.decodeFromString<Action>(it)) }
|
||||
.firstOrNull { it.second.isAvailable(context) }
|
||||
?.apply {
|
||||
boundActions.add(first)
|
||||
// allow to bind CHOOSE to multiple gestures
|
||||
if (second != LauncherAction.CHOOSE) {
|
||||
boundActions.add(first)
|
||||
}
|
||||
second.bindToGesture(editor, gesture.id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,4 +74,8 @@ class AppAction(val app: AppInfo) : Action {
|
|||
// check if app is installed
|
||||
return DetailedAppInfo.fromAppInfo(app, context) != null
|
||||
}
|
||||
|
||||
override fun canReachSettings(): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -168,6 +168,12 @@ enum class Gesture(
|
|||
R.string.settings_gesture_description_double_right,
|
||||
R.array.default_double_right,
|
||||
R.anim.left_right
|
||||
),
|
||||
BACK(
|
||||
"action.back",
|
||||
R.string.settings_gesture_back,
|
||||
R.string.settings_gesture_description_back,
|
||||
R.array.default_up
|
||||
);
|
||||
|
||||
enum class Edge {
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.os.UserManager
|
|||
import android.provider.Settings
|
||||
import android.view.KeyEvent
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.AppCompatDrawableManager
|
||||
import de.jrpie.android.launcher.Application
|
||||
import de.jrpie.android.launcher.R
|
||||
import de.jrpie.android.launcher.apps.AppFilter
|
||||
|
@ -40,25 +41,29 @@ enum class LauncherAction(
|
|||
val label: Int,
|
||||
val icon: Int,
|
||||
val launch: (Context) -> Unit,
|
||||
val available: (Context) -> Boolean = { true }
|
||||
private val canReachSettings: Boolean = false,
|
||||
val available: (Context) -> Boolean = { true },
|
||||
) : Action {
|
||||
SETTINGS(
|
||||
"settings",
|
||||
R.string.list_other_settings,
|
||||
R.drawable.baseline_settings_24,
|
||||
::openSettings
|
||||
::openSettings,
|
||||
true
|
||||
),
|
||||
CHOOSE(
|
||||
"choose",
|
||||
R.string.list_other_list,
|
||||
R.drawable.baseline_menu_24,
|
||||
::openAppsList
|
||||
::openAppsList,
|
||||
true
|
||||
),
|
||||
CHOOSE_FROM_FAVORITES(
|
||||
"choose_from_favorites",
|
||||
R.string.list_other_list_favorites,
|
||||
R.drawable.baseline_favorite_24,
|
||||
{ context -> openAppsList(context, true) }
|
||||
{ context -> openAppsList(context, true) },
|
||||
true
|
||||
),
|
||||
TOGGLE_PRIVATE_SPACE_LOCK(
|
||||
"toggle_private_space_lock",
|
||||
|
@ -127,7 +132,11 @@ enum class LauncherAction(
|
|||
}
|
||||
|
||||
override fun isAvailable(context: Context): Boolean {
|
||||
return true
|
||||
return this.available(context)
|
||||
}
|
||||
|
||||
override fun canReachSettings(): Boolean {
|
||||
return this.canReachSettings
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -7,6 +7,7 @@ import de.jrpie.android.launcher.actions.Action
|
|||
import de.jrpie.android.launcher.apps.AppInfo
|
||||
import de.jrpie.android.launcher.apps.DetailedAppInfo
|
||||
import de.jrpie.android.launcher.preferences.legacy.migratePreferencesFromVersion1
|
||||
import de.jrpie.android.launcher.preferences.legacy.migratePreferencesFromVersion2
|
||||
import de.jrpie.android.launcher.preferences.legacy.migratePreferencesFromVersionUnknown
|
||||
import de.jrpie.android.launcher.ui.HomeActivity
|
||||
|
||||
|
@ -14,7 +15,7 @@ import de.jrpie.android.launcher.ui.HomeActivity
|
|||
* Increase when breaking changes are introduced and write an appropriate case in
|
||||
* `migratePreferencesToNewVersion`
|
||||
*/
|
||||
const val PREFERENCE_VERSION = 2
|
||||
const val PREFERENCE_VERSION = 3
|
||||
const val UNKNOWN_PREFERENCE_VERSION = -1
|
||||
private const val TAG = "Launcher - Preferences"
|
||||
|
||||
|
@ -32,13 +33,16 @@ fun migratePreferencesToNewVersion(context: Context) {
|
|||
|
||||
UNKNOWN_PREFERENCE_VERSION -> { /* still using the old preferences file */
|
||||
migratePreferencesFromVersionUnknown(context)
|
||||
|
||||
Log.i(TAG, "migration of preferences complete.")
|
||||
Log.i(TAG, "migration of preferences complete (${UNKNOWN_PREFERENCE_VERSION} -> ${PREFERENCE_VERSION}).")
|
||||
}
|
||||
|
||||
1 -> {
|
||||
migratePreferencesFromVersion1()
|
||||
Log.i(TAG, "migration of preferences complete.")
|
||||
Log.i(TAG, "migration of preferences complete (1 -> ${PREFERENCE_VERSION}).")
|
||||
}
|
||||
2 -> {
|
||||
migratePreferencesFromVersion2()
|
||||
Log.i(TAG, "migration of preferences complete (2 -> ${PREFERENCE_VERSION}).")
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
|
|
@ -117,11 +117,12 @@ private fun migrateAction(key: String) {
|
|||
* (see [PREFERENCE_VERSION])
|
||||
*/
|
||||
fun migratePreferencesFromVersion1() {
|
||||
assert(PREFERENCE_VERSION == 2)
|
||||
assert(LauncherPreferences.internal().versionCode() == 1)
|
||||
Gesture.entries.forEach { g -> migrateAction(g.id) }
|
||||
migrateAppInfoSet(LauncherPreferences.apps().keys().hidden())
|
||||
migrateAppInfoSet(LauncherPreferences.apps().keys().favorites())
|
||||
migrateAppInfoStringMap(LauncherPreferences.apps().keys().customNames())
|
||||
LauncherPreferences.internal().versionCode(2)
|
||||
|
||||
migratePreferencesFromVersion2()
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.jrpie.android.launcher.preferences.legacy
|
||||
|
||||
import de.jrpie.android.launcher.actions.Action
|
||||
import de.jrpie.android.launcher.actions.Gesture
|
||||
import de.jrpie.android.launcher.actions.LauncherAction
|
||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||
import de.jrpie.android.launcher.preferences.PREFERENCE_VERSION
|
||||
|
||||
|
||||
/**
|
||||
* Migrate preferences from version 2 (used until version 0.0.21) to the current format
|
||||
* (see [PREFERENCE_VERSION])
|
||||
*/
|
||||
fun migratePreferencesFromVersion2() {
|
||||
assert(PREFERENCE_VERSION == 3)
|
||||
assert(LauncherPreferences.internal().versionCode() == 2)
|
||||
// previously there was no setting for this
|
||||
Action.setActionForGesture(Gesture.BACK, LauncherAction.CHOOSE)
|
||||
LauncherPreferences.internal().versionCode(3)
|
||||
}
|
|
@ -50,7 +50,6 @@ private const val TAG = "Preferences ? -> 1"
|
|||
* and a different file was used.
|
||||
*/
|
||||
fun migratePreferencesFromVersionUnknown(context: Context) {
|
||||
assert(PREFERENCE_VERSION == 2)
|
||||
|
||||
Log.i(
|
||||
TAG,
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.util.DisplayMetrics
|
|||
import android.view.GestureDetector
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -54,6 +55,10 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
) {
|
||||
recreate()
|
||||
}
|
||||
|
||||
if (prefKey?.startsWith("action.") == true) {
|
||||
updateSettingsFallbackButtonVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
private var edgeWidth = 0.15f
|
||||
|
@ -80,6 +85,10 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
handleBack()
|
||||
}
|
||||
}
|
||||
binding.buttonFallbackSettings.setOnClickListener {
|
||||
LauncherAction.SETTINGS.invoke(this)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -96,6 +105,20 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
|
||||
}
|
||||
|
||||
private fun updateSettingsFallbackButtonVisibility() {
|
||||
// If µLauncher settings can not be reached from any action bound to an enabled gesture,
|
||||
// show the fallback button.
|
||||
binding.buttonFallbackSettings.visibility = if (
|
||||
!Gesture.entries.any { g ->
|
||||
g.isEnabled() && Action.forGesture(g)?.canReachSettings() == true
|
||||
}
|
||||
) {
|
||||
View.VISIBLE
|
||||
} else {
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun initClock() {
|
||||
val locale = Locale.getDefault()
|
||||
val dateVisible = LauncherPreferences.clock().dateVisible()
|
||||
|
@ -152,6 +175,7 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
edgeWidth = LauncherPreferences.enabled_gestures().edgeSwipeEdgeWidth() / 100f
|
||||
|
||||
initClock()
|
||||
updateSettingsFallbackButtonVisibility()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -299,7 +323,7 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
|
||||
|
||||
private fun handleBack() {
|
||||
LauncherAction.CHOOSE.launch(this)
|
||||
Gesture.BACK(this)
|
||||
}
|
||||
|
||||
override fun isHomeScreen(): Boolean {
|
||||
|
|
|
@ -34,4 +34,18 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<!-- only shown when µLauncher settings can't be reached by a gesture -->
|
||||
<ImageView
|
||||
android:id="@+id/button_fallback_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/settings"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:padding="20dp"
|
||||
android:alpha="0.4"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:srcCompat="@drawable/baseline_settings_24"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -3,6 +3,12 @@
|
|||
<resources>
|
||||
<!-- Default Apps for different actions (button-press, swipes ...) -->
|
||||
|
||||
<!-- Back - Apps list -->
|
||||
<string-array name="default_back">
|
||||
<item>{\"type\": \"action:launcher\", \"value\": \"choose\"}</item> <!-- All Apps -->
|
||||
</string-array>
|
||||
|
||||
|
||||
<!-- Swipe up - Apps list -->
|
||||
<string-array name="default_up">
|
||||
<item>{\"type\": \"action:launcher\", \"value\": \"choose\"}</item> <!-- All Apps -->
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
- Settings : Apps
|
||||
-
|
||||
-->
|
||||
<string name="settings_gesture_back">Back</string>
|
||||
<string name="settings_gesture_description_back">Back button / back gesture</string>
|
||||
<string name="settings_gesture_up">Up</string>
|
||||
<string name="settings_gesture_description_up">Swipe up</string>
|
||||
<string name="settings_gesture_double_up">Double Up</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue