Skip to content

Commit 58c15ca

Browse files
committed
#1637 feat: show a home screen error if notification permission is not granted
1 parent 6bf9e99 commit 58c15ca

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#### TO BE RELEASED
44

5+
## Added
6+
7+
- #1637 show a home screen error if notification permission is not granted.
8+
59
## Bug fixes
610

711
- Do not automatically select the key mapper keyboard when the accessibility service starts.

app/src/main/java/io/github/sds100/keymapper/home/ShowHomeScreenAlertsUseCase.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class ShowHomeScreenAlertsUseCaseImpl(
5252
override fun disableLogging() {
5353
preferences.set(Keys.log, false)
5454
}
55+
56+
override val isNotificationPermissionGranted: Flow<Boolean> =
57+
permissions.isGrantedFlow(Permission.POST_NOTIFICATIONS)
58+
59+
override fun requestNotificationPermission() {
60+
permissions.request(Permission.POST_NOTIFICATIONS)
61+
}
5562
}
5663

5764
interface ShowHomeScreenAlertsUseCase {
@@ -68,4 +75,7 @@ interface ShowHomeScreenAlertsUseCase {
6875

6976
val isLoggingEnabled: Flow<Boolean>
7077
fun disableLogging()
78+
79+
val isNotificationPermissionGranted: Flow<Boolean>
80+
fun requestNotificationPermission()
7181
}

app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapListViewModel.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class KeyMapListViewModel(
9494
const val ID_ACCESSIBILITY_SERVICE_CRASHED_LIST_ITEM = "accessibility_service_crashed"
9595
const val ID_BATTERY_OPTIMISATION_LIST_ITEM = "battery_optimised"
9696
const val ID_LOGGING_ENABLED_LIST_ITEM = "logging_enabled"
97+
const val ID_NOTIFICATION_PERMISSION_DENIED_LIST_ITEM = "notification_permission_denied"
9798
}
9899

99100
val sortViewModel = SortViewModel(coroutineScope, sortKeyMaps)
@@ -152,7 +153,8 @@ class KeyMapListViewModel(
152153
showAlertsUseCase.accessibilityServiceState,
153154
showAlertsUseCase.hideAlerts,
154155
showAlertsUseCase.isLoggingEnabled,
155-
) { isBatteryOptimised, serviceState, isHidden, isLoggingEnabled ->
156+
showAlertsUseCase.isNotificationPermissionGranted,
157+
) { isBatteryOptimised, serviceState, isHidden, isLoggingEnabled, isNotificationPermissionGranted ->
156158
if (isHidden) {
157159
return@combine emptyList()
158160
}
@@ -187,6 +189,15 @@ class KeyMapListViewModel(
187189
)
188190
} // don't show a success message for this
189191

192+
if (!isNotificationPermissionGranted) {
193+
add(
194+
HomeWarningListItem(
195+
ID_NOTIFICATION_PERMISSION_DENIED_LIST_ITEM,
196+
getString(R.string.home_error_notification_permission),
197+
),
198+
)
199+
}
200+
190201
if (isLoggingEnabled) {
191202
add(
192203
HomeWarningListItem(
@@ -672,6 +683,7 @@ class KeyMapListViewModel(
672683

673684
ID_BATTERY_OPTIMISATION_LIST_ITEM -> showAlertsUseCase.disableBatteryOptimisation()
674685
ID_LOGGING_ENABLED_LIST_ITEM -> showAlertsUseCase.disableLogging()
686+
ID_NOTIFICATION_PERMISSION_DENIED_LIST_ITEM -> showAlertsUseCase.requestNotificationPermission()
675687
}
676688
}
677689
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<string name="home_success_accessibility_service_is_enabled">The accessibility service is enabled! Your key maps should work.</string>
9191
<string name="home_error_logging_enabled">Extra logging is turned on! Turn this off if you aren\'t trying to fix an issue.</string>
9292
<string name="home_error_logging_enabled_button">Turn off</string>
93+
<string name="home_error_notification_permission">Turn on notifications for better on-screen messages, more actions and service updates.</string>
9394

9495
<string name="title_about">About</string>
9596
<!-- Action descriptions -->

0 commit comments

Comments
 (0)