From 2333bb98aaeda9fb630af3b561a7f4d9972d1b36 Mon Sep 17 00:00:00 2001 From: Nishant Mishra Date: Mon, 15 Sep 2025 19:30:00 +0530 Subject: [PATCH] fix: Use correct material 3 colors for notification --- .../java/org/nsh07/pomodoro/MainActivity.kt | 6 ++ .../nsh07/pomodoro/data/TimerRepository.kt | 6 ++ .../nsh07/pomodoro/service/TimerService.kt | 99 ++++++++++--------- 3 files changed, 65 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/org/nsh07/pomodoro/MainActivity.kt b/app/src/main/java/org/nsh07/pomodoro/MainActivity.kt index 7811dc4..c6e55b6 100644 --- a/app/src/main/java/org/nsh07/pomodoro/MainActivity.kt +++ b/app/src/main/java/org/nsh07/pomodoro/MainActivity.kt @@ -6,6 +6,7 @@ import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels import androidx.compose.material3.MaterialTheme.colorScheme +import androidx.compose.runtime.LaunchedEffect import org.nsh07.pomodoro.ui.AppScreen import org.nsh07.pomodoro.ui.NavItem import org.nsh07.pomodoro.ui.Screen @@ -27,6 +28,11 @@ class MainActivity : ComponentActivity() { enableEdgeToEdge() setContent { TomatoTheme { + val colorScheme = colorScheme + LaunchedEffect(colorScheme) { + appContainer.appTimerRepository.colorScheme = colorScheme + } + timerViewModel.setCompositionLocals(colorScheme) AppScreen(timerViewModel = timerViewModel, statsViewModel = statsViewModel) } diff --git a/app/src/main/java/org/nsh07/pomodoro/data/TimerRepository.kt b/app/src/main/java/org/nsh07/pomodoro/data/TimerRepository.kt index e7284e6..850919c 100644 --- a/app/src/main/java/org/nsh07/pomodoro/data/TimerRepository.kt +++ b/app/src/main/java/org/nsh07/pomodoro/data/TimerRepository.kt @@ -7,6 +7,9 @@ package org.nsh07.pomodoro.data +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.lightColorScheme + /** * Interface that holds the timer durations for each timer type. This repository maintains a single * source of truth for the timer durations for the various ViewModels in the app. @@ -19,6 +22,8 @@ interface TimerRepository { var timerFrequency: Float var alarmEnabled: Boolean var vibrateEnabled: Boolean + + var colorScheme: ColorScheme } /** @@ -32,4 +37,5 @@ class AppTimerRepository : TimerRepository { override var timerFrequency: Float = 10f override var alarmEnabled = true override var vibrateEnabled = true + override var colorScheme = lightColorScheme() } \ No newline at end of file diff --git a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt index 4045491..f11debe 100644 --- a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt +++ b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt @@ -11,8 +11,6 @@ import android.os.VibrationEffect import android.os.Vibrator import android.os.VibratorManager import android.provider.Settings -import androidx.compose.material3.ColorScheme -import androidx.compose.material3.lightColorScheme import androidx.compose.ui.graphics.toArgb import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat @@ -74,7 +72,7 @@ class TimerService : Service() { } } - private var cs: ColorScheme = lightColorScheme() + private val cs by lazy { timerRepository.colorScheme } override fun onBind(intent: Intent?): IBinder? { return null @@ -185,52 +183,61 @@ class TimerService : Service() { else (remainingTime.toFloat() / 60000f).toInt() notificationManager.notify( - 1, notificationBuilder.setContentTitle( - if (!complete) { - "$currentTimer $middleDot $remainingTimeString min remaining" + if (paused) " $middleDot Paused" else "" - } else "$currentTimer $middleDot Completed" - ).setContentText("Up next: $nextTimer (${timerState.value.nextTimeStr})") - .setStyle(NotificationCompat.ProgressStyle().also { - // Add all the Focus, Short break and long break intervals in order - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) { - // Android 16 and later supports live updates - // Set progress bar sections if on Baklava or later - for (i in 0.. timerRepository.focusTime.toInt() - TimerMode.SHORT_BREAK -> timerRepository.shortBreakTime.toInt() - else -> timerRepository.longBreakTime.toInt() + 1, + notificationBuilder + .setContentTitle( + if (!complete) { + "$currentTimer $middleDot $remainingTimeString min remaining" + if (paused) " $middleDot Paused" else "" + } else "$currentTimer $middleDot Completed" + ) + .setContentText("Up next: $nextTimer (${timerState.value.nextTimeStr})") + .setStyle( + NotificationCompat.ProgressStyle() + .also { + // Add all the Focus, Short break and long break intervals in order + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) { + // Android 16 and later supports live updates + // Set progress bar sections if on Baklava or later + for (i in 0.. timerRepository.focusTime.toInt() + TimerMode.SHORT_BREAK -> timerRepository.shortBreakTime.toInt() + else -> timerRepository.longBreakTime.toInt() + } + ) + ) + } + } + .setProgress( // Set the current progress by filling the previous intervals and part of the current interval + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) { + (totalTime - remainingTime) + ((cycles + 1) / 2) * timerRepository.focusTime.toInt() + (cycles / 2) * timerRepository.shortBreakTime.toInt() + } else (totalTime - remainingTime) ) - } - } - .setProgress( // Set the current progress by filling the previous intervals and part of the current interval - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) { - (totalTime - remainingTime) + ((cycles + 1) / 2) * timerRepository.focusTime.toInt() + (cycles / 2) * timerRepository.shortBreakTime.toInt() - } else (totalTime - remainingTime) - )) + ) .setWhen(System.currentTimeMillis() + remainingTime) // Sets the Live Activity/Now Bar chip time - .setShortCriticalText(millisecondsToStr(time.coerceAtLeast(0))).build()) + .setShortCriticalText(millisecondsToStr(time.coerceAtLeast(0))) + .build() + ) if (complete) { startAlarm()