fix: Save time to database when foreground service is closed
Potentially fixes #10, I still need to test it though
This commit is contained in:
@@ -46,10 +46,11 @@ class DefaultAppContainer(context: Context) : AppContainer {
|
|||||||
override val notificationBuilder: NotificationCompat.Builder by lazy {
|
override val notificationBuilder: NotificationCompat.Builder by lazy {
|
||||||
NotificationCompat.Builder(context, "timer")
|
NotificationCompat.Builder(context, "timer")
|
||||||
.setSmallIcon(R.drawable.tomato_logo_notification)
|
.setSmallIcon(R.drawable.tomato_logo_notification)
|
||||||
.setOngoing(true)
|
|
||||||
.setColor(Color.Red.toArgb())
|
.setColor(Color.Red.toArgb())
|
||||||
.setRequestPromotedOngoing(true)
|
.setShowWhen(true)
|
||||||
|
.setSilent(true)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
|
.setRequestPromotedOngoing(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val timerState: MutableStateFlow<TimerState> by lazy {
|
override val timerState: MutableStateFlow<TimerState> by lazy {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.nsh07.pomodoro.TomatoApplication
|
import org.nsh07.pomodoro.TomatoApplication
|
||||||
import org.nsh07.pomodoro.data.AppContainer
|
import org.nsh07.pomodoro.data.AppContainer
|
||||||
import org.nsh07.pomodoro.data.StatRepository
|
import org.nsh07.pomodoro.data.StatRepository
|
||||||
@@ -216,9 +217,7 @@ class TimerService : Service() {
|
|||||||
(totalTime - remainingTime) + ((cycles + 1) / 2) * timerRepository.focusTime.toInt() + (cycles / 2) * timerRepository.shortBreakTime.toInt()
|
(totalTime - remainingTime) + ((cycles + 1) / 2) * timerRepository.focusTime.toInt() + (cycles / 2) * timerRepository.shortBreakTime.toInt()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setShowWhen(true)
|
|
||||||
.setWhen(System.currentTimeMillis() + remainingTime) // Sets the Live Activity/Now Bar chip time
|
.setWhen(System.currentTimeMillis() + remainingTime) // Sets the Live Activity/Now Bar chip time
|
||||||
.setSilent(true)
|
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -337,7 +336,11 @@ class TimerService : Service() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
timerJob.cancel()
|
runBlocking {
|
||||||
|
timerJob.cancel()
|
||||||
|
saveTimeToDb()
|
||||||
|
notificationManager.cancel(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Actions {
|
enum class Actions {
|
||||||
|
|||||||
Reference in New Issue
Block a user