Add settings for home button gesture
This commit is contained in:
@@ -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) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -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<SavableSearchable?> = 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<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) {
|
||||
|
||||
Reference in New Issue
Block a user