Revert "Remove home button gesture"
This reverts commit 99fd69d5d960a847b2cd05259a595016028b170c.
This commit is contained in:
parent
d81936212d
commit
c4ec894add
@ -91,6 +91,7 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
|
|||||||
val swipeUpAction = settings.swipeUp
|
val swipeUpAction = settings.swipeUp
|
||||||
val longPressAction = settings.longPress
|
val longPressAction = settings.longPress
|
||||||
val doubleTapAction = settings.doubleTap
|
val doubleTapAction = settings.doubleTap
|
||||||
|
val homeButtonAction = settings.homeButton
|
||||||
|
|
||||||
val swipeLeftAppKey = (swipeLeftAction as? GestureAction.Launch)?.key
|
val swipeLeftAppKey = (swipeLeftAction as? GestureAction.Launch)?.key
|
||||||
val swipeRightAppKey = (swipeRightAction as? GestureAction.Launch)?.key
|
val swipeRightAppKey = (swipeRightAction as? GestureAction.Launch)?.key
|
||||||
@ -98,6 +99,7 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
|
|||||||
val swipeUpAppKey = (swipeUpAction as? GestureAction.Launch)?.key
|
val swipeUpAppKey = (swipeUpAction as? GestureAction.Launch)?.key
|
||||||
val longPressAppKey = (longPressAction as? GestureAction.Launch)?.key
|
val longPressAppKey = (longPressAction as? GestureAction.Launch)?.key
|
||||||
val doubleTapAppKey = (doubleTapAction as? GestureAction.Launch)?.key
|
val doubleTapAppKey = (doubleTapAction as? GestureAction.Launch)?.key
|
||||||
|
val homeButtonAppKey = (homeButtonAction as? GestureAction.Launch)?.key
|
||||||
val apps = listOfNotNull(
|
val apps = listOfNotNull(
|
||||||
swipeLeftAppKey,
|
swipeLeftAppKey,
|
||||||
swipeRightAppKey,
|
swipeRightAppKey,
|
||||||
@ -105,6 +107,7 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
|
|||||||
swipeUpAppKey,
|
swipeUpAppKey,
|
||||||
longPressAppKey,
|
longPressAppKey,
|
||||||
doubleTapAppKey,
|
doubleTapAppKey,
|
||||||
|
homeButtonAppKey,
|
||||||
).let { searchableRepository.getByKeys(it).first() }
|
).let { searchableRepository.getByKeys(it).first() }
|
||||||
|
|
||||||
GestureState(
|
GestureState(
|
||||||
@ -114,12 +117,14 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
|
|||||||
swipeUpAction = swipeUpAction,
|
swipeUpAction = swipeUpAction,
|
||||||
longPressAction = longPressAction,
|
longPressAction = longPressAction,
|
||||||
doubleTapAction = doubleTapAction,
|
doubleTapAction = doubleTapAction,
|
||||||
|
homeButtonAction = homeButtonAction,
|
||||||
swipeLeftApp = apps.find { it.key == swipeLeftAppKey },
|
swipeLeftApp = apps.find { it.key == swipeLeftAppKey },
|
||||||
swipeRightApp = apps.find { it.key == swipeRightAppKey },
|
swipeRightApp = apps.find { it.key == swipeRightAppKey },
|
||||||
swipeDownApp = apps.find { it.key == swipeDownAppKey },
|
swipeDownApp = apps.find { it.key == swipeDownAppKey },
|
||||||
swipeUpApp = apps.find { it.key == swipeUpAppKey },
|
swipeUpApp = apps.find { it.key == swipeUpAppKey },
|
||||||
longPressApp = apps.find { it.key == longPressAppKey },
|
longPressApp = apps.find { it.key == longPressAppKey },
|
||||||
doubleTapApp = apps.find { it.key == doubleTapAppKey },
|
doubleTapApp = apps.find { it.key == doubleTapAppKey },
|
||||||
|
homeButtonApp = apps.find { it.key == homeButtonAppKey },
|
||||||
)
|
)
|
||||||
}.stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
}.stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
||||||
}
|
}
|
||||||
@ -131,11 +136,13 @@ data class GestureState(
|
|||||||
val swipeUpAction: GestureAction = GestureAction.NoAction,
|
val swipeUpAction: GestureAction = GestureAction.NoAction,
|
||||||
val longPressAction: GestureAction = GestureAction.NoAction,
|
val longPressAction: GestureAction = GestureAction.NoAction,
|
||||||
val doubleTapAction: GestureAction = GestureAction.NoAction,
|
val doubleTapAction: GestureAction = GestureAction.NoAction,
|
||||||
|
val homeButtonAction: GestureAction = GestureAction.NoAction,
|
||||||
val swipeLeftApp: SavableSearchable? = null,
|
val swipeLeftApp: SavableSearchable? = null,
|
||||||
val swipeRightApp: SavableSearchable? = null,
|
val swipeRightApp: SavableSearchable? = null,
|
||||||
val swipeDownApp: SavableSearchable? = null,
|
val swipeDownApp: SavableSearchable? = null,
|
||||||
val swipeUpApp: SavableSearchable? = null,
|
val swipeUpApp: SavableSearchable? = null,
|
||||||
val longPressApp: SavableSearchable? = null,
|
val longPressApp: SavableSearchable? = null,
|
||||||
val doubleTapApp: SavableSearchable? = null,
|
val doubleTapApp: SavableSearchable? = null,
|
||||||
|
val homeButtonApp: SavableSearchable? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package de.mm20.launcher2.ui.launcher
|
package de.mm20.launcher2.ui.launcher
|
||||||
|
|
||||||
import android.app.WallpaperManager
|
import android.app.WallpaperManager
|
||||||
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
@ -349,6 +350,11 @@ abstract class SharedLauncherActivity(
|
|||||||
gestures.longPressApp,
|
gestures.longPressApp,
|
||||||
Gesture.LongPress,
|
Gesture.LongPress,
|
||||||
),
|
),
|
||||||
|
homeButton = getScaffoldGesture(
|
||||||
|
gestures.homeButtonAction,
|
||||||
|
gestures.homeButtonApp,
|
||||||
|
Gesture.HomeButton,
|
||||||
|
),
|
||||||
fixedSearchBar = fixedSearchBar,
|
fixedSearchBar = fixedSearchBar,
|
||||||
searchBarStyle = searchBarStyle,
|
searchBarStyle = searchBarStyle,
|
||||||
searchBarPosition = if (bottomSearchBar) SearchBarPosition.Bottom else SearchBarPosition.Top,
|
searchBarPosition = if (bottomSearchBar) SearchBarPosition.Bottom else SearchBarPosition.Top,
|
||||||
@ -419,6 +425,17 @@ abstract class SharedLauncherActivity(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isNewIntent = false
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
isNewIntent = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
isNewIntent = false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
val windowController = WindowCompat.getInsetsController(window, window.decorView.rootView)
|
val windowController = WindowCompat.getInsetsController(window, window.decorView.rootView)
|
||||||
|
|||||||
@ -95,6 +95,7 @@ import de.mm20.launcher2.preferences.SearchBarStyle
|
|||||||
import de.mm20.launcher2.searchactions.actions.SearchAction
|
import de.mm20.launcher2.searchactions.actions.SearchAction
|
||||||
import de.mm20.launcher2.ui.component.SearchBarLevel
|
import de.mm20.launcher2.ui.component.SearchBarLevel
|
||||||
import de.mm20.launcher2.ui.ktx.toPixels
|
import de.mm20.launcher2.ui.ktx.toPixels
|
||||||
|
import de.mm20.launcher2.ui.launcher.SharedLauncherActivity
|
||||||
import de.mm20.launcher2.ui.launcher.helper.WallpaperBlur
|
import de.mm20.launcher2.ui.launcher.helper.WallpaperBlur
|
||||||
import de.mm20.launcher2.ui.launcher.search.SearchVM
|
import de.mm20.launcher2.ui.launcher.search.SearchVM
|
||||||
import de.mm20.launcher2.ui.launcher.search.filters.KeyboardFilterBar
|
import de.mm20.launcher2.ui.launcher.search.filters.KeyboardFilterBar
|
||||||
@ -142,6 +143,7 @@ internal data class ScaffoldConfiguration(
|
|||||||
val swipeRight: ScaffoldGesture? = null,
|
val swipeRight: ScaffoldGesture? = null,
|
||||||
val doubleTap: ScaffoldGesture? = null,
|
val doubleTap: ScaffoldGesture? = null,
|
||||||
val longPress: ScaffoldGesture? = null,
|
val longPress: ScaffoldGesture? = null,
|
||||||
|
val homeButton: ScaffoldGesture? = null,
|
||||||
/**
|
/**
|
||||||
* Position of the search bar
|
* Position of the search bar
|
||||||
*/
|
*/
|
||||||
@ -207,6 +209,7 @@ private operator fun ScaffoldConfiguration.get(gesture: Gesture): ScaffoldGestur
|
|||||||
Gesture.SwipeRight -> swipeRight
|
Gesture.SwipeRight -> swipeRight
|
||||||
Gesture.DoubleTap -> doubleTap
|
Gesture.DoubleTap -> doubleTap
|
||||||
Gesture.LongPress -> longPress
|
Gesture.LongPress -> longPress
|
||||||
|
Gesture.HomeButton -> homeButton
|
||||||
Gesture.TapSearchBar -> searchBarTap
|
Gesture.TapSearchBar -> searchBarTap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,6 +222,7 @@ enum class Gesture(val orientation: Orientation?) {
|
|||||||
DoubleTap(null),
|
DoubleTap(null),
|
||||||
LongPress(null),
|
LongPress(null),
|
||||||
TapSearchBar(null),
|
TapSearchBar(null),
|
||||||
|
HomeButton(null),
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class LauncherScaffoldState(
|
internal class LauncherScaffoldState(
|
||||||
@ -750,6 +754,11 @@ internal class LauncherScaffoldState(
|
|||||||
performTapGesture(Gesture.LongPress)
|
performTapGesture(Gesture.LongPress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun onHomeButtonPress() {
|
||||||
|
performTapGesture(Gesture.HomeButton)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun onSearchBarTap() {
|
suspend fun onSearchBarTap() {
|
||||||
if (currentComponent is SearchComponent) return
|
if (currentComponent is SearchComponent) return
|
||||||
openSearch()
|
openSearch()
|
||||||
@ -1190,7 +1199,17 @@ internal fun LauncherScaffold(
|
|||||||
var pauseTime = 0L
|
var pauseTime = 0L
|
||||||
lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||||
try {
|
try {
|
||||||
if (pauseTime > 0L && System.currentTimeMillis() - pauseTime > 5000L) {
|
if (pauseTime > 0L && System.currentTimeMillis() - pauseTime < 50L && (activity as? SharedLauncherActivity)?.isNewIntent == true) {
|
||||||
|
if (!state.isLocked) {
|
||||||
|
if (state.currentProgress > 0f) {
|
||||||
|
state.onPredictiveBackEnd()
|
||||||
|
} else {
|
||||||
|
state.onHomeButtonPress()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
activity.onBackPressedDispatcher.onBackPressed()
|
||||||
|
}
|
||||||
|
} else if (pauseTime > 0L && System.currentTimeMillis() - pauseTime > 5000L) {
|
||||||
if (!state.isLocked) {
|
if (!state.isLocked) {
|
||||||
state.reset()
|
state.reset()
|
||||||
searchVM.reset()
|
searchVM.reset()
|
||||||
|
|||||||
@ -204,6 +204,27 @@ fun GestureSettingsScreen() {
|
|||||||
onAppChanged = { viewModel.setLongPressApp(it) }
|
onAppChanged = { viewModel.setLongPressApp(it) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
val homeButton by viewModel.homeButton.collectAsStateWithLifecycle(null)
|
||||||
|
val homeButtonApp by viewModel.homeButtonApp.collectAsState(null)
|
||||||
|
val homeButtonAppIcon by remember(homeButtonApp?.key) {
|
||||||
|
viewModel.getIcon(homeButtonApp, appIconSize.toInt())
|
||||||
|
}.collectAsState(null)
|
||||||
|
GuardedPreference(
|
||||||
|
locked = hasPermission == false && requiresAccessibilityService(homeButton),
|
||||||
|
description = stringResource(R.string.missing_permission_accessibility_gesture_settings),
|
||||||
|
onUnlock = { viewModel.requestPermission(context as AppCompatActivity) },
|
||||||
|
) {
|
||||||
|
GesturePreference(
|
||||||
|
title = stringResource(R.string.preference_gesture_home_button),
|
||||||
|
icon = Icons.Rounded.Home,
|
||||||
|
value = homeButton,
|
||||||
|
onValueChanged = { viewModel.setHomeButton(it) },
|
||||||
|
options = options,
|
||||||
|
app = homeButtonApp,
|
||||||
|
appIcon = homeButtonAppIcon,
|
||||||
|
onAppChanged = { viewModel.setHomeButtonApp(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import de.mm20.launcher2.icons.IconService
|
|||||||
import de.mm20.launcher2.icons.LauncherIcon
|
import de.mm20.launcher2.icons.LauncherIcon
|
||||||
import de.mm20.launcher2.permissions.PermissionGroup
|
import de.mm20.launcher2.permissions.PermissionGroup
|
||||||
import de.mm20.launcher2.permissions.PermissionsManager
|
import de.mm20.launcher2.permissions.PermissionsManager
|
||||||
|
import de.mm20.launcher2.preferences.BaseLayout
|
||||||
import de.mm20.launcher2.preferences.GestureAction
|
import de.mm20.launcher2.preferences.GestureAction
|
||||||
import de.mm20.launcher2.preferences.ui.GestureSettings
|
import de.mm20.launcher2.preferences.ui.GestureSettings
|
||||||
import de.mm20.launcher2.preferences.ui.UiSettings
|
import de.mm20.launcher2.preferences.ui.UiSettings
|
||||||
@ -19,6 +20,7 @@ import kotlinx.coroutines.flow.flatMapLatest
|
|||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
|
|
||||||
@ -44,6 +46,8 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent {
|
|||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||||
val longPress = gestureSettings.longPress
|
val longPress = gestureSettings.longPress
|
||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||||
|
val homeButton = gestureSettings.homeButton
|
||||||
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||||
|
|
||||||
fun setSwipeDown(action: GestureAction) {
|
fun setSwipeDown(action: GestureAction) {
|
||||||
gestureSettings.setSwipeDown(action)
|
gestureSettings.setSwipeDown(action)
|
||||||
@ -69,6 +73,10 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent {
|
|||||||
gestureSettings.setLongPress(action)
|
gestureSettings.setLongPress(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setHomeButton(action: GestureAction) {
|
||||||
|
gestureSettings.setHomeButton(action)
|
||||||
|
}
|
||||||
|
|
||||||
val swipeLeftApp: Flow<SavableSearchable?> = swipeLeft
|
val swipeLeftApp: Flow<SavableSearchable?> = swipeLeft
|
||||||
.flatMapLatest {
|
.flatMapLatest {
|
||||||
if (it !is GestureAction.Launch || it.key == null) flowOf(null)
|
if (it !is GestureAction.Launch || it.key == null) flowOf(null)
|
||||||
@ -153,6 +161,21 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent {
|
|||||||
setDoubleTap(GestureAction.Launch(searchable.key))
|
setDoubleTap(GestureAction.Launch(searchable.key))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val homeButtonApp: Flow<SavableSearchable?> = homeButton
|
||||||
|
.flatMapLatest {
|
||||||
|
if (it !is GestureAction.Launch || it.key == null) flowOf(null)
|
||||||
|
else searchableRepository.getByKeys(listOf(it.key!!)).map {
|
||||||
|
it.firstOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(stopTimeoutMillis = 10000), null)
|
||||||
|
|
||||||
|
fun setHomeButtonApp(searchable: SavableSearchable?) {
|
||||||
|
searchable?.let { searchableRepository.insert(it) } ?: return
|
||||||
|
setHomeButton(GestureAction.Launch(searchable.key))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun requestPermission(context: AppCompatActivity) {
|
fun requestPermission(context: AppCompatActivity) {
|
||||||
permissionsManager.requestPermission(context, PermissionGroup.Accessibility)
|
permissionsManager.requestPermission(context, PermissionGroup.Accessibility)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,6 +138,7 @@ data class LauncherSettingsData internal constructor(
|
|||||||
val gesturesSwipeUp: GestureAction = GestureAction.Widgets,
|
val gesturesSwipeUp: GestureAction = GestureAction.Widgets,
|
||||||
val gesturesDoubleTap: GestureAction = GestureAction.ScreenLock,
|
val gesturesDoubleTap: GestureAction = GestureAction.ScreenLock,
|
||||||
val gesturesLongPress: GestureAction = GestureAction.NoAction,
|
val gesturesLongPress: GestureAction = GestureAction.NoAction,
|
||||||
|
val gesturesHomeButton: GestureAction = GestureAction.NoAction,
|
||||||
|
|
||||||
val animationsCharging: Boolean = true,
|
val animationsCharging: Boolean = true,
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ data class GestureSettingsData(
|
|||||||
val swipeUp: GestureAction,
|
val swipeUp: GestureAction,
|
||||||
val doubleTap: GestureAction,
|
val doubleTap: GestureAction,
|
||||||
val longPress: GestureAction,
|
val longPress: GestureAction,
|
||||||
|
val homeButton: GestureAction,
|
||||||
)
|
)
|
||||||
|
|
||||||
class GestureSettings internal constructor(
|
class GestureSettings internal constructor(
|
||||||
@ -26,6 +27,7 @@ class GestureSettings internal constructor(
|
|||||||
swipeUp = it.gesturesSwipeUp,
|
swipeUp = it.gesturesSwipeUp,
|
||||||
doubleTap = it.gesturesDoubleTap,
|
doubleTap = it.gesturesDoubleTap,
|
||||||
longPress = it.gesturesLongPress,
|
longPress = it.gesturesLongPress,
|
||||||
|
homeButton = it.gesturesHomeButton,
|
||||||
)
|
)
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
) {
|
) {
|
||||||
@ -47,6 +49,9 @@ class GestureSettings internal constructor(
|
|||||||
val longPress: Flow<GestureAction> = dataStore.data.map { it.gesturesLongPress }
|
val longPress: Flow<GestureAction> = dataStore.data.map { it.gesturesLongPress }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
val homeButton: Flow<GestureAction> = dataStore.data.map { it.gesturesHomeButton }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
fun setSwipeDown(action: GestureAction) {
|
fun setSwipeDown(action: GestureAction) {
|
||||||
dataStore.update {
|
dataStore.update {
|
||||||
it.copy(gesturesSwipeDown = action)
|
it.copy(gesturesSwipeDown = action)
|
||||||
@ -82,4 +87,12 @@ class GestureSettings internal constructor(
|
|||||||
it.copy(gesturesLongPress = action)
|
it.copy(gesturesLongPress = action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setHomeButton(action: GestureAction) {
|
||||||
|
dataStore.update {
|
||||||
|
it.copy(gesturesHomeButton = action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user