Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ class SettingsRepository(
const val KEY_ISLAND_NOTIF_KEEP_PROGRESS = "island_notif_keep_progress"
const val KEY_ISLAND_NOTIF_QUEUE = "island_notif_queue"
const val KEY_ISLAND_NOTIF_SKIP_SILENT = "island_notif_skip_silent"
const val KEY_ISLAND_NOTIF_FOLLOW_DND = "island_notif_follow_dnd"
const val KEY_ISLAND_NOTIF_FILTER_APPS = "island_notif_filter_apps"
const val KEY_ISLAND_NOTIF_FILTER_APPS_LIST = "island_notif_filter_apps_list"
const val KEY_ISLAND_SHOW_NOTIFICATIONS = "island_show_notifications"
Expand Down Expand Up @@ -4165,6 +4166,9 @@ class SettingsRepository(
fun isIslandNotifSkipSilentEnabled(): Boolean = getBoolean(KEY_ISLAND_NOTIF_SKIP_SILENT, true)
fun setIslandNotifSkipSilentEnabled(enabled: Boolean) = putBoolean(KEY_ISLAND_NOTIF_SKIP_SILENT, enabled)

fun isIslandNotifFollowDndEnabled(): Boolean = getBoolean(KEY_ISLAND_NOTIF_FOLLOW_DND, true)
fun setIslandNotifFollowDndEnabled(enabled: Boolean) = putBoolean(KEY_ISLAND_NOTIF_FOLLOW_DND, enabled)

fun isIslandNotifFilterAppsEnabled(): Boolean = getBoolean(KEY_ISLAND_NOTIF_FILTER_APPS, false)
fun setIslandNotifFilterAppsEnabled(enabled: Boolean) = putBoolean(KEY_ISLAND_NOTIF_FILTER_APPS, enabled)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ data class ActiveNotificationAlert(
val actions: List<NotificationActionItem> = emptyList(),
val chatIcon: Bitmap? = null,
val isSilent: Boolean = false,
val blockedByDnd: Boolean = false,
)

Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,11 @@ object FeatureRegistry {
R.string.island_notif_skip_silent_desc,
"island_notif_skip_silent",
),
SearchSetting(
R.string.island_notif_follow_dnd_title,
R.string.island_notif_follow_dnd_desc,
"island_notif_follow_dnd",
),
SearchSetting(
R.string.island_notif_keep_progress_title,
R.string.island_notif_keep_progress_desc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class NotificationsPlugin : BaseIslandPlugin() {
SettingsRepository.KEY_ISLAND_SHOW_GLOW,
SettingsRepository.KEY_ISLAND_NOTIF_QUEUE,
SettingsRepository.KEY_ISLAND_NOTIF_SKIP_SILENT,
SettingsRepository.KEY_ISLAND_NOTIF_FOLLOW_DND,
SettingsRepository.KEY_ISLAND_NOTIF_FILTER_APPS,
SettingsRepository.KEY_ISLAND_NOTIF_FILTER_APPS_LIST,
SettingsRepository.KEY_ISLAND_NOTIF_TAP_TO_OPEN,
Expand Down Expand Up @@ -162,6 +163,7 @@ class NotificationsPlugin : BaseIslandPlugin() {

private fun passesFilters(alert: ActiveNotificationAlert): Boolean {
if (alert.isSilent && settings.isIslandNotifSkipSilentEnabled()) return false
if (alert.blockedByDnd && settings.isIslandNotifFollowDndEnabled()) return false
if (!settings.isIslandNotifFilterAppsEnabled()) return true
return settings.loadIslandNotifFilterApps().any { it.isEnabled && it.packageName == alert.packageName }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ class NotificationListener : NotificationListenerService() {
return false
}

// Do Not Disturb holds this notification back or suppresses its peek; apps and conversations allowed through still pass.
fun isBlockedByDnd(
sbn: StatusBarNotification,
rankingMap: RankingMap? = null,
): Boolean {
val map = rankingMap ?: currentRanking ?: return false
val ranking = Ranking()
if (!map.getRanking(sbn.key, ranking)) return false
val peekSuppressed =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P &&
ranking.suppressedVisualEffects and NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK != 0
return !ranking.matchesInterruptionFilter() || peekSuppressed
}

private fun populateActiveUnreadNotifications() {
unreadNotifications.clear()
try {
Expand Down Expand Up @@ -1013,7 +1027,10 @@ class NotificationListener : NotificationListenerService() {
}

if (!isRepost && isHeadsUpNotification(sbn, rankingMap, allowSilent = true)) {
val alert = extractNotificationAlert(sbn)?.copy(isSilent = isSilentNotification(sbn, rankingMap))
val alert = extractNotificationAlert(sbn)?.copy(
isSilent = isSilentNotification(sbn, rankingMap),
blockedByDnd = isBlockedByDnd(sbn, rankingMap),
)
if (alert != null) {
notifyAlertPosted(alert)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,18 @@ fun IslandNotificationSettingsUI(
modifier = Modifier.highlight(highlightSetting == "island_notif_skip_silent"),
)

IconToggleItem(
iconRes = R.drawable.rounded_do_not_disturb_on_24,
title = stringResource(R.string.island_notif_follow_dnd_title),
description = stringResource(R.string.island_notif_follow_dnd_desc),
isChecked = viewModel.isIslandNotifFollowDnd.value,
onCheckedChange = { checked ->
HapticUtil.performVirtualKeyHaptic(view)
viewModel.setIslandNotifFollowDnd(checked)
},
modifier = Modifier.highlight(highlightSetting == "island_notif_follow_dnd"),
)

IconToggleItem(
iconRes = R.drawable.rounded_downloading_24,
title = stringResource(R.string.island_notif_keep_progress_title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class MainViewModel : ViewModel() {
val isIslandNotifKeepProgress = mutableStateOf(true)
val isIslandNotifQueue = mutableStateOf(true)
val isIslandNotifSkipSilent = mutableStateOf(true)
val isIslandNotifFollowDnd = mutableStateOf(true)
val isIslandNotifFilterApps = mutableStateOf(false)
val isIslandShowNotifications = mutableStateOf(true)
val isIslandNotifTapToOpen = mutableStateOf(false)
Expand Down Expand Up @@ -924,6 +925,9 @@ class MainViewModel : ViewModel() {
SettingsRepository.KEY_ISLAND_NOTIF_SKIP_SILENT ->
isIslandNotifSkipSilent.value = settingsRepository.isIslandNotifSkipSilentEnabled()

SettingsRepository.KEY_ISLAND_NOTIF_FOLLOW_DND ->
isIslandNotifFollowDnd.value = settingsRepository.isIslandNotifFollowDndEnabled()

SettingsRepository.KEY_ISLAND_NOTIF_FILTER_APPS ->
isIslandNotifFilterApps.value = settingsRepository.isIslandNotifFilterAppsEnabled()

Expand Down Expand Up @@ -2433,6 +2437,7 @@ class MainViewModel : ViewModel() {
isIslandNotifKeepProgress.value = settingsRepository.isIslandNotifKeepProgressEnabled()
isIslandNotifQueue.value = settingsRepository.isIslandNotifQueueEnabled()
isIslandNotifSkipSilent.value = settingsRepository.isIslandNotifSkipSilentEnabled()
isIslandNotifFollowDnd.value = settingsRepository.isIslandNotifFollowDndEnabled()
isIslandNotifFilterApps.value = settingsRepository.isIslandNotifFilterAppsEnabled()
isIslandShowNotifications.value = settingsRepository.isIslandShowNotificationsEnabled()
isIslandNotifTapToOpen.value = settingsRepository.isIslandNotifTapToOpenEnabled()
Expand Down Expand Up @@ -5735,6 +5740,11 @@ class MainViewModel : ViewModel() {
settingsRepository.setIslandNotifSkipSilentEnabled(enabled)
}

fun setIslandNotifFollowDnd(enabled: Boolean) {
isIslandNotifFollowDnd.value = enabled
settingsRepository.setIslandNotifFollowDndEnabled(enabled)
}

fun setIslandNotifFilterApps(enabled: Boolean) {
isIslandNotifFilterApps.value = enabled
settingsRepository.setIslandNotifFilterAppsEnabled(enabled)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3221,6 +3221,8 @@
<string name="island_notif_section_lock_screen">Lock screen</string>
<string name="island_notif_filter_apps_desc">Only show notifications from the apps you pick</string>
<string name="island_notif_skip_silent_desc">Ignore notifications that arrive without sound</string>
<string name="island_notif_follow_dnd_title">Follow Do Not Disturb</string>
<string name="island_notif_follow_dnd_desc">Hide notifications that Do Not Disturb silences</string>
<string name="island_notif_keep_progress_desc">Show downloads and other ongoing progress</string>
<string name="island_notif_queue_desc">Keep several notifications instead of replacing the current one</string>
<string name="island_notif_tap_to_open_desc">Tap an expanded notification to open its app</string>
Expand Down
Loading