Add settings for home button gesture

This commit is contained in:
MM20 2023-06-23 17:17:08 +02:00
parent e350e0f640
commit 918f340dd2
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
4 changed files with 57 additions and 0 deletions

View File

@ -195,6 +195,29 @@ fun GestureSettingsScreen() {
appIcon = swipeRightAppIcon, appIcon = swipeRightAppIcon,
onAppChanged = { viewModel.setSwipeRightApp(it) } 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) }
)
} }
} }
} }

View File

@ -53,6 +53,8 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent {
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
val longPress = dataStore.data.map { it.gestures.longPress } val longPress = dataStore.data.map { it.gestures.longPress }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null) .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
val homeButton = dataStore.data.map { it.gestures.homeButton }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
fun setSwipeDown(action: GestureAction) { fun setSwipeDown(action: GestureAction) {
viewModelScope.launch { 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<SavableSearchable?> = dataStore.data.map { it.gestures.swipeLeftApp } val swipeLeftApp: Flow<SavableSearchable?> = dataStore.data.map { it.gestures.swipeLeftApp }
.map { .map {
if (it.isEmpty()) null else searchableRepository.getByKeys(listOf(it)).firstOrNull() if (it.isEmpty()) null else searchableRepository.getByKeys(listOf(it)).firstOrNull()
@ -199,6 +210,26 @@ class GestureSettingsScreenVM : ViewModel(), KoinComponent {
} }
} }
val homeButtonApp: Flow<SavableSearchable?> = 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) { fun requestPermission(context: AppCompatActivity) {

View File

@ -775,6 +775,7 @@
<string name="preference_gesture_swipe_right">Swipe right</string> <string name="preference_gesture_swipe_right">Swipe right</string>
<string name="preference_gesture_double_tap">Double tap</string> <string name="preference_gesture_double_tap">Double tap</string>
<string name="preference_gesture_long_press">Long press</string> <string name="preference_gesture_long_press">Long press</string>
<string name="preference_gesture_home_button">Home button/gesture</string>
<string name="gesture_action_none">None</string> <string name="gesture_action_none">None</string>
<string name="gesture_action_open_search">Open search</string> <string name="gesture_action_open_search">Open search</string>
<string name="gesture_action_launch_app">Launch app</string> <string name="gesture_action_launch_app">Launch app</string>

View File

@ -329,6 +329,8 @@ message Settings {
string swipe_right_app = 8; string swipe_right_app = 8;
string double_tap_app = 9; string double_tap_app = 9;
string long_press_app = 10; string long_press_app = 10;
GestureAction home_button = 11;
string home_button_app = 12;
} }
GestureSettings gestures = 28; GestureSettings gestures = 28;