diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt index d37e7971..b8e5d0a0 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreen.kt @@ -195,6 +195,29 @@ fun GestureSettingsScreen() { appIcon = swipeRightAppIcon, onAppChanged = { viewModel.setSwipeRightApp(it) } ) + + val homeButton by viewModel.homeButton.collectAsStateWithLifecycle(null) + AnimatedVisibility(hasPermission == false && requiresAccessibilityService(homeButton)) { + MissingPermissionBanner( + modifier = Modifier.padding(16.dp), + text = stringResource(R.string.missing_permission_accessibility_gesture_settings), + onClick = { viewModel.requestPermission(context as AppCompatActivity) } + ) + } + val homeButtonApp by viewModel.homeButtonApp.collectAsState(null) + val homeButtonAppIcon by remember(homeButtonApp?.key) { + viewModel.getIcon(homeButtonApp, appIconSize.toInt()) + }.collectAsState(null) + GesturePreference( + title = stringResource(R.string.preference_gesture_home_button), + value = homeButton, + onValueChanged = { viewModel.setHomeButton(it) }, + isOpenSearch = false, + options = options, + app = homeButtonApp, + appIcon = homeButtonAppIcon, + onAppChanged = { viewModel.setHomeButtonApp(it) } + ) } } } diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt index 44b0d517..3fe59bb6 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/gestures/GestureSettingsScreenVM.kt @@ -53,6 +53,8 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent { .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) val longPress = dataStore.data.map { it.gestures.longPress } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) + val homeButton = dataStore.data.map { it.gestures.homeButton } + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) fun setSwipeDown(action: GestureAction) { viewModelScope.launch { @@ -99,6 +101,15 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent { } } + fun setHomeButton(action: GestureAction) { + viewModelScope.launch { + dataStore.updateData { + it.toBuilder().setGestures(it.gestures.toBuilder().setHomeButton(action).build()) + .build() + } + } + } + val swipeLeftApp: Flow = dataStore.data.map { it.gestures.swipeLeftApp } .map { if (it.isEmpty()) null else searchableRepository.getByKeys(listOf(it)).firstOrNull() @@ -199,6 +210,26 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent { } } + val homeButtonApp: Flow = dataStore.data.map { it.gestures.homeButtonApp } + .map { + if (it.isEmpty()) null else searchableRepository.getByKeys(listOf(it)).firstOrNull() + } + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(stopTimeoutMillis = 10000), null) + + fun setHomeButtonApp(searchable: SavableSearchable?) { + viewModelScope.launch { + searchable?.let { searchableRepository.insert(it) } + dataStore.updateData { + it.toBuilder() + .setGestures(it.gestures.toBuilder() + .setHomeButtonApp(searchable?.key ?: "") + .build() + ) + .build() + } + } + } + fun requestPermission(context: AppCompatActivity) { diff --git a/core/i18n/src/main/res/values/strings.xml b/core/i18n/src/main/res/values/strings.xml index 4eabf63c..cfadd60b 100644 --- a/core/i18n/src/main/res/values/strings.xml +++ b/core/i18n/src/main/res/values/strings.xml @@ -775,6 +775,7 @@ Swipe right Double tap Long press + Home button/gesture None Open search Launch app diff --git a/core/preferences/src/main/proto/settings.proto b/core/preferences/src/main/proto/settings.proto index d40f4252..2e2b84d0 100644 --- a/core/preferences/src/main/proto/settings.proto +++ b/core/preferences/src/main/proto/settings.proto @@ -329,6 +329,8 @@ message Settings { string swipe_right_app = 8; string double_tap_app = 9; string long_press_app = 10; + GestureAction home_button = 11; + string home_button_app = 12; } GestureSettings gestures = 28;