Skip to content

Commit

Permalink
change notification with activity switch visibility logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 16, 2024
1 parent 6c46291 commit d633a0d
Show file tree
Hide file tree
Showing 36 changed files with 89 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,8 @@ class PrefsRepoImpl @Inject constructor(
KEY_SHOW_NOTIFICATIONS_CONTROLS, true,
)

override var showNotificationWithSwitch: Boolean by prefs.delegate(
KEY_SHOW_NOTIFICATION_WITH_SWITCH, false,
)

override var showNotificationWithSwitchHide: Boolean by prefs.delegate(
KEY_SHOW_NOTIFICATION_WITH_SWITCH_HIDE, false,
override var showNotificationEvenWithNoTimers: Boolean by prefs.delegate(
KEY_SHOW_NOTIFICATION_EVEN_WITH_NO_TIMERS, false,
)

override var inactivityReminderDuration: Long by prefs.delegate(
Expand Down Expand Up @@ -581,8 +577,7 @@ class PrefsRepoImpl @Inject constructor(
const val KEY_ALLOW_MULTITASKING = "allowMultitasking"
const val KEY_SHOW_NOTIFICATIONS = "showNotifications"
const val KEY_SHOW_NOTIFICATIONS_CONTROLS = "showNotificationsControls"
const val KEY_SHOW_NOTIFICATION_WITH_SWITCH = "showNotificationWithSwitch"
const val KEY_SHOW_NOTIFICATION_WITH_SWITCH_HIDE = "showNotificationWithSwitchHide"
const val KEY_SHOW_NOTIFICATION_EVEN_WITH_NO_TIMERS = "showNotificationEvenWithNoTimers"
const val KEY_INACTIVITY_REMINDER_DURATION = "inactivityReminderDuration"
const val KEY_INACTIVITY_REMINDER_RECURRENT = "inactivityReminderRecurrent"
const val KEY_INACTIVITY_REMINDER_DND_START = "inactivityReminderDndStart"
Expand Down Expand Up @@ -638,5 +633,7 @@ class PrefsRepoImpl @Inject constructor(
private const val KEY_SORT_RECORD_TYPES_BY_COLOR = "sortRecordTypesByColor" // Boolean
private const val KEY_DARK_MODE = "darkMode"
private const val KEY_RECORD_TAG_SELECTION_EVEN_FOR_GENERAL_TAGS = "recordTagSelectionEvenForGeneralTags"
private const val KEY_SHOW_NOTIFICATION_WITH_SWITCH = "showNotificationWithSwitch" // Boolean
private const val KEY_SHOW_NOTIFICATION_WITH_SWITCH_HIDE = "showNotificationWithSwitchHide" // Boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companio
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_GOALS_SEPARATELY
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_NOTIFICATIONS
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_NOTIFICATIONS_CONTROLS
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_NOTIFICATION_WITH_SWITCH
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_NOTIFICATION_WITH_SWITCH_HIDE
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_NOTIFICATION_EVEN_WITH_NO_TIMERS
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_RECORDS_CALENDAR
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_RECORD_TAG_SELECTION
import com.example.util.simpletimetracker.data_local.repo.PrefsRepoImpl.Companion.KEY_SHOW_RECORD_TAG_SELECTION_EXCLUDE_ACTIVITIES
Expand Down Expand Up @@ -179,8 +178,7 @@ class BackupPrefsRepo @Inject constructor(
PrefsProcessor(KEY_ALLOW_MULTITASKING, ::allowMultitasking),
PrefsProcessor(KEY_SHOW_NOTIFICATIONS, ::showNotifications),
PrefsProcessor(KEY_SHOW_NOTIFICATIONS_CONTROLS, ::showNotificationsControls),
PrefsProcessor(KEY_SHOW_NOTIFICATION_WITH_SWITCH, ::showNotificationWithSwitch),
PrefsProcessor(KEY_SHOW_NOTIFICATION_WITH_SWITCH_HIDE, ::showNotificationWithSwitchHide),
PrefsProcessor(KEY_SHOW_NOTIFICATION_EVEN_WITH_NO_TIMERS, ::showNotificationEvenWithNoTimers),
PrefsProcessor(KEY_INACTIVITY_REMINDER_DURATION, ::inactivityReminderDuration),
PrefsProcessor(KEY_INACTIVITY_REMINDER_RECURRENT, ::inactivityReminderRecurrent),
PrefsProcessor(KEY_INACTIVITY_REMINDER_DND_START, ::inactivityReminderDoNotDisturbStart),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,12 @@ class PrefsInteractor @Inject constructor(
prefsRepo.showNotificationsControls = isEnabled
}

suspend fun getShowNotificationWithSwitch(): Boolean = withContext(Dispatchers.IO) {
prefsRepo.showNotificationWithSwitch
suspend fun getShowNotificationEvenWithNoTimers(): Boolean = withContext(Dispatchers.IO) {
prefsRepo.showNotificationEvenWithNoTimers
}

suspend fun setShowNotificationWithSwitch(isEnabled: Boolean) = withContext(Dispatchers.IO) {
prefsRepo.showNotificationWithSwitch = isEnabled
}

suspend fun getShowNotificationWithSwitchHide(): Boolean = withContext(Dispatchers.IO) {
prefsRepo.showNotificationWithSwitchHide
}

suspend fun setShowNotificationWithSwitchHide(isEnabled: Boolean) = withContext(Dispatchers.IO) {
prefsRepo.showNotificationWithSwitchHide = isEnabled
suspend fun setShowNotificationEvenWithNoTimers(isEnabled: Boolean) = withContext(Dispatchers.IO) {
prefsRepo.showNotificationEvenWithNoTimers = isEnabled
}

suspend fun getInactivityReminderDuration(): Long = withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class UpdateExternalViewsInteractor @Inject constructor(
)
}

suspend fun onShowNotificationWithSwitchChange() {
suspend fun onShowNotificationsEvenWithNoTimersChange() {
runUpdates(
Update.NotificationWithControls,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ interface PrefsRepo {

var showNotificationsControls: Boolean

var showNotificationWithSwitch: Boolean

var showNotificationWithSwitchHide: Boolean
var showNotificationEvenWithNoTimers: Boolean

var inactivityReminderDuration: Long // in seconds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
tagsShift: Int,
selectedTypeId: Long,
) {
if (prefsInteractor.getShowNotificationWithSwitch()) {
if (shouldCancel()) {
cancel()
} else {
show(
typesShift = typesShift,
tagsShift = tagsShift,
selectedTypeId = selectedTypeId,
)
}
val shouldShow = prefsInteractor.getShowNotifications() &&
prefsInteractor.getShowNotificationEvenWithNoTimers() &&
runningRecordInteractor.isEmpty()

if (shouldShow) {
show(
typesShift = typesShift,
tagsShift = tagsShift,
selectedTypeId = selectedTypeId,
)
} else {
cancel()
}
Expand Down Expand Up @@ -164,7 +164,6 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
color = color,
title = title,
subtitle = subtitle,
isDarkTheme = prefsInteractor.getDarkMode(),
untrackedStartedTimeStamp = untrackedTimeStarted,
prevRecordDuration = prevRecordDuration,
controls = when (controls) {
Expand All @@ -177,11 +176,4 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
private fun cancel() {
manager.hide()
}

private suspend fun shouldCancel(): Boolean {
return prefsInteractor.getShowNotificationWithSwitchHide() &&
prefsInteractor.getShowNotifications() &&
prefsInteractor.getShowNotificationsControls() &&
!runningRecordInteractor.isEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ data class NotificationActivitySwitchParams(
val color: Int,
val title: String,
val subtitle: String,
val isDarkTheme: Boolean,
val untrackedStartedTimeStamp: Long?,
val prevRecordDuration: Long?,
val controls: NotificationControlsParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class NotificationTypeInteractorImpl @Inject constructor(
private val getNotificationActivitySwitchControlsInteractor: GetNotificationActivitySwitchControlsInteractor,
) : NotificationTypeInteractor {

// TODO SWITCH merge with update function?
override suspend fun checkAndShow(
typeId: Long,
typesShift: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ enum class SettingsBlock {
NotificationsCollapse,
NotificationsShow,
NotificationsShowControls,
NotificationsWithSwitch,
NotificationsWithSwitchHide,
NotificationsShowEvenWithNoTimers,
NotificationsInactivity,
NotificationsInactivityRecurrent,
NotificationsInactivityDoNotDisturbStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class SettingsNotificationsViewDataInteractor @Inject constructor(
result += SettingsCheckboxViewData(
block = SettingsBlock.NotificationsShow,
title = resourceRepo.getString(R.string.settings_show_notifications),
subtitle = resourceRepo.getString(R.string.settings_show_notifications_hint),
subtitle = resourceRepo.getString(R.string.settings_show_notifications_hint) + "\n" +
resourceRepo.getString(R.string.settings_show_notifications_controls_hint),
isChecked = showNotifications,
bottomSpaceIsVisible = !showNotifications,
dividerIsVisible = !showNotifications,
Expand All @@ -60,32 +61,16 @@ class SettingsNotificationsViewDataInteractor @Inject constructor(
title = resourceRepo.getString(R.string.settings_show_notifications_controls),
subtitle = "",
isChecked = showNotificationsControls,
bottomSpaceIsVisible = false,
dividerIsVisible = false,
)
}

val showNotificationWithSwitch = prefsInteractor.getShowNotificationWithSwitch()
// Allows to avoid duplication of controls,
// when both separate notification with controls is shown
// and also timers with controls are shown.
// In this case separate notification will be hidden.
val showNotificationWithSwitchHide = showNotificationWithSwitch &&
showNotifications &&
showNotificationsControls
result += SettingsCheckboxViewData(
block = SettingsBlock.NotificationsWithSwitch,
title = resourceRepo.getString(R.string.settings_show_notification_with_switch),
subtitle = resourceRepo.getString(R.string.settings_show_notification_with_switch_hint),
isChecked = showNotificationWithSwitch,
bottomSpaceIsVisible = !showNotificationWithSwitchHide,
dividerIsVisible = !showNotificationWithSwitchHide,
forceBind = true,
)
if (showNotificationWithSwitchHide) {
result += SettingsCheckboxViewData(
block = SettingsBlock.NotificationsWithSwitchHide,
title = resourceRepo.getString(R.string.settings_show_notification_with_switch_hide),
block = SettingsBlock.NotificationsShowEvenWithNoTimers,
title = resourceRepo.getString(R.string.settings_show_notification_even_with_no_timers),
subtitle = "",
isChecked = prefsInteractor.getShowNotificationWithSwitchHide(),
isChecked = prefsInteractor.getShowNotificationEvenWithNoTimers(),
bottomSpaceIsVisible = true,
dividerIsVisible = true,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class SettingsNotificationsViewModelDelegate @Inject constructor(
SettingsBlock.NotificationsSystemSettings -> onSystemSettingsClicked()
SettingsBlock.NotificationsShow -> onShowNotificationsClicked()
SettingsBlock.NotificationsShowControls -> onShowNotificationsControlsClicked()
SettingsBlock.NotificationsWithSwitch -> onShowNotificationWithSwitchClicked()
SettingsBlock.NotificationsWithSwitchHide -> onShowNotificationWithSwitchHideClicked()
SettingsBlock.NotificationsShowEvenWithNoTimers -> onShowNotificationsEvenWithNoTimersClicked()
SettingsBlock.NotificationsInactivityRecurrent -> onInactivityReminderRecurrentClicked()
SettingsBlock.NotificationsActivityRecurrent -> onActivityReminderRecurrentClicked()
else -> {
Expand Down Expand Up @@ -111,31 +110,12 @@ class SettingsNotificationsViewModelDelegate @Inject constructor(
}
}

private fun onShowNotificationWithSwitchClicked() {
fun updateValue(newValue: Boolean) = delegateScope.launch {
prefsInteractor.setShowNotificationWithSwitch(newValue)
parent?.updateContent()
externalViewsInteractor.onShowNotificationWithSwitchChange()
}

delegateScope.launch {
if (prefsInteractor.getShowNotificationWithSwitch()) {
updateValue(false)
} else {
checkNotificationsPermissionInteractor.execute(
onEnabled = { updateValue(true) },
onDisabled = { updateValue(false) },
)
}
}
}

private fun onShowNotificationWithSwitchHideClicked() {
private fun onShowNotificationsEvenWithNoTimersClicked() {
delegateScope.launch {
val newValue = !prefsInteractor.getShowNotificationWithSwitchHide()
prefsInteractor.setShowNotificationWithSwitchHide(newValue)
val newValue = !prefsInteractor.getShowNotificationEvenWithNoTimers()
prefsInteractor.setShowNotificationEvenWithNoTimers(newValue)
parent?.updateContent()
externalViewsInteractor.onShowNotificationWithSwitchChange()
externalViewsInteractor.onShowNotificationsEvenWithNoTimersChange()
}
}

Expand Down
5 changes: 2 additions & 3 deletions resources/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@
<string name="settings_show_notifications">إظهار إشعارات المؤقت</string>
<string name="settings_show_notifications_hint">إظهار اﻹشعارات عند تشغيل المؤقت.</string>
<string name="settings_show_notifications_controls">تفعيل إمكانية تبديل النشاط من اﻹشعار</string>
<string name="settings_show_notification_with_switch">إظهار الإخطار مع مفتاح النشاط</string>
<string name="settings_show_notification_with_switch_hint">يمكن استخدامه أيضًا لتبديل الأنشطة من شاشة القفل.</string>
<string name="settings_show_notification_with_switch_hide">إخفاء وقت ظهور إشعار المؤقت</string>
<string name="settings_show_notifications_controls_hint">يمكن استخدامه أيضًا لتبديل الأنشطة من شاشة القفل.</string>
<string name="settings_show_notification_even_with_no_timers">تظهر حتى في حالة عدم تشغيل أي مؤقتات</string>
<string name="settings_keep_statistics_range">حافظ على نطاق الإحصائيات</string>
<string name="settings_keep_statistics_range_hint">في حال التفعيل، ستفتح الإحصائيات التفصيلية بنفس النطاق الزمني المحدد في الإحصائيات.</string>
<string name="settings_retroactive_tracking_mode">تمكين تتبع الوقت بأثر رجعي</string>
Expand Down
5 changes: 2 additions & 3 deletions resources/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@
<string name="settings_show_notifications">Mostra notificacions del temporitzador</string>
<string name="settings_show_notifications_hint">Mostra notificacions quan el temporitzador sigui actiu.</string>
<string name="settings_show_notifications_controls">Activa el canvi d\'activitat des de la notificació</string>
<string name="settings_show_notification_with_switch">Mostra la notificació amb l\'interruptor d\'activitat</string>
<string name="settings_show_notification_with_switch_hint">També es pot utilitzar per canviar les activitats des de la pantalla de bloqueig.</string>
<string name="settings_show_notification_with_switch_hide">Amaga quan es mostri la notificació del temporitzador</string>
<string name="settings_show_notifications_controls_hint">També es pot utilitzar per canviar les activitats des de la pantalla de bloqueig.</string>
<string name="settings_show_notification_even_with_no_timers">Mostra fins i tot quan no s\'executa cap temporitzador</string>
<string name="settings_keep_statistics_range">Mantingues el rang d\'estadístiques</string>
<string name="settings_keep_statistics_range_hint">Si és habilitat, les estadístiques detallades s\'obriran amb el mateix rang de temps seleccionat a les estadístiques</string>
<string name="settings_retroactive_tracking_mode">Activa el seguiment de temps retroactiu</string>
Expand Down
5 changes: 2 additions & 3 deletions resources/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@
<string name="settings_show_notifications">Timer-Benachrichtigungen anzeigen</string>
<string name="settings_show_notifications_hint">Benachrichtigungen anzeigen, wenn die Zeiten laufen.</string>
<string name="settings_show_notifications_controls">Aktivitätswechsel von der Benachrichtigung aus aktivieren</string>
<string name="settings_show_notification_with_switch">Benachrichtigung mit Aktivitätsschalter anzeigen</string>
<string name="settings_show_notification_with_switch_hint">Kann auch zum Wechseln von Aktivitäten über den Sperrbildschirm verwendet werden.</string>
<string name="settings_show_notification_with_switch_hide">Ausblenden, wenn Timer-Benachrichtigung angezeigt wird</string>
<string name="settings_show_notifications_controls_hint">Kann auch zum Wechseln von Aktivitäten über den Sperrbildschirm verwendet werden.</string>
<string name="settings_show_notification_even_with_no_timers">Auch wenn keine Timer laufen</string>
<string name="settings_keep_statistics_range">Behalten Sie den Statistikbereich bei</string>
<string name="settings_keep_statistics_range_hint">Wenn aktiviert, werden detaillierte Statistiken mit dem gleichen Zeitraum geöffnet, der in den Statistiken ausgewählt wurde.</string>
<string name="settings_retroactive_tracking_mode">Aktivieren Sie die rückwirkende Zeiterfassung</string>
Expand Down
5 changes: 2 additions & 3 deletions resources/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@
<string name="settings_show_notifications">Mostrar notificaciones del temporizador</string>
<string name="settings_show_notifications_hint">Mostrar notificaciones cuando el temporizador esté activo.</string>
<string name="settings_show_notifications_controls">Habilitar el cambio de actividad desde la notificación</string>
<string name="settings_show_notification_with_switch">Mostrar notificación con cambio de actividad</string>
<string name="settings_show_notification_with_switch_hint">También se puede utilizar para cambiar de actividad desde la pantalla de bloqueo.</string>
<string name="settings_show_notification_with_switch_hide">Ocultar cuando se muestra la notificación del temporizador</string>
<string name="settings_show_notifications_controls_hint">También se puede utilizar para cambiar de actividad desde la pantalla de bloqueo.</string>
<string name="settings_show_notification_even_with_no_timers">Mostrar incluso cuando no hay temporizadores en ejecución</string>
<string name="settings_keep_statistics_range">Mantener rango de estadísticas</string>
<string name="settings_keep_statistics_range_hint">Si está habilitado, se abrirán estadísticas detalladas con el mismo rango de tiempo seleccionado en estadísticas.</string>
<string name="settings_retroactive_tracking_mode">Habilitar seguimiento de tiempo retroactivo</string>
Expand Down
Loading

0 comments on commit d633a0d

Please sign in to comment.