diff --git a/app/src/main/java/io/timelimit/android/integration/platform/PlatformIntegration.kt b/app/src/main/java/io/timelimit/android/integration/platform/PlatformIntegration.kt index 1884ec9..efc5251 100644 --- a/app/src/main/java/io/timelimit/android/integration/platform/PlatformIntegration.kt +++ b/app/src/main/java/io/timelimit/android/integration/platform/PlatformIntegration.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2023 Jonas Lochmann + * TimeLimit Copyright 2019 - 2024 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,6 +56,7 @@ abstract class PlatformIntegration( abstract fun setShowNotificationToRevokeTemporarilyAllowedApps(show: Boolean) abstract fun showRemoteResetNotification() abstract fun showTimeWarningNotification(title: String, text: String) + abstract fun showExtraTimeStartedNotification(categoryId: String, categoryTitle: String) // returns package names for which it was set abstract fun setSuspendedApps(packageNames: List, suspend: Boolean): List abstract fun stopSuspendingForAllApps() diff --git a/app/src/main/java/io/timelimit/android/integration/platform/android/AndroidIntegration.kt b/app/src/main/java/io/timelimit/android/integration/platform/android/AndroidIntegration.kt index a546450..7e40e5b 100644 --- a/app/src/main/java/io/timelimit/android/integration/platform/android/AndroidIntegration.kt +++ b/app/src/main/java/io/timelimit/android/integration/platform/android/AndroidIntegration.kt @@ -441,6 +441,26 @@ class AndroidIntegration(context: Context): PlatformIntegration(maximumProtectio ) } + override fun showExtraTimeStartedNotification(categoryId: String, categoryTitle: String) { + NotificationChannels.createNotificationChannels(notificationManager, context) + + notificationManager.notify( + categoryId, + NotificationIds.EXTRA_TIME_STARTED, + NotificationCompat.Builder(context, NotificationChannels.EXTRA_TIME_STARTED) + .setSmallIcon(R.drawable.ic_stat_timelapse) + .setContentTitle(context.getString(R.string.notification_extra_time_started)) + .setContentText(categoryTitle) + .setWhen(System.currentTimeMillis()) + .setShowWhen(true) + .setLocalOnly(true) + .setAutoCancel(false) + .setOngoing(false) + .setPriority(NotificationCompat.PRIORITY_HIGH) + .build() + ) + } + override fun disableDeviceAdmin() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (policyManager.isDeviceOwnerApp(context.packageName)) { diff --git a/app/src/main/java/io/timelimit/android/integration/platform/android/Notification.kt b/app/src/main/java/io/timelimit/android/integration/platform/android/Notification.kt index 6595b0a..f979373 100644 --- a/app/src/main/java/io/timelimit/android/integration/platform/android/Notification.kt +++ b/app/src/main/java/io/timelimit/android/integration/platform/android/Notification.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2022 Jonas Lochmann + * TimeLimit Copyright 2019 - 2024 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,7 @@ object NotificationIds { const val WORKER_REPORT_UNINSTALL = 8 const val WORKER_SYNC_BACKGROUND = 9 const val NEW_DEVICE = 10 + const val EXTRA_TIME_STARTED = 11 } object NotificationChannels { @@ -47,6 +48,7 @@ object NotificationChannels { const val TEMP_ALLOWED_APP = "temporarily allowed App" const val APP_RESET = "app reset" const val NEW_DEVICE = "new device" + const val EXTRA_TIME_STARTED = "extra time started" private fun createAppStatusChannel(notificationManager: NotificationManager, context: Context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -214,6 +216,20 @@ object NotificationChannels { } } + private fun createExtraTimeStartedNotificationChannel(notificationManager: NotificationManager, context: Context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + notificationManager.createNotificationChannel( + NotificationChannel( + EXTRA_TIME_STARTED, + context.getString(R.string.notification_channel_extra_time_started_title), + NotificationManager.IMPORTANCE_HIGH + ).apply { + description = context.getString(R.string.notification_channel_extra_time_started_description) + } + ) + } + } + fun createNotificationChannels(notificationManager: NotificationManager, context: Context) { createAppStatusChannel(notificationManager, context) createBlockedNotificationChannel(notificationManager, context) @@ -225,6 +241,7 @@ object NotificationChannels { createTempAllowedAppChannel(notificationManager, context) createAppResetChannel(notificationManager, context) createNewDeviceChannel(notificationManager, context) + createExtraTimeStartedNotificationChannel(notificationManager, context) } } diff --git a/app/src/main/java/io/timelimit/android/integration/platform/dummy/DummyIntegration.kt b/app/src/main/java/io/timelimit/android/integration/platform/dummy/DummyIntegration.kt index 65cc4c2..4c86606 100644 --- a/app/src/main/java/io/timelimit/android/integration/platform/dummy/DummyIntegration.kt +++ b/app/src/main/java/io/timelimit/android/integration/platform/dummy/DummyIntegration.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2023 Jonas Lochmann + * TimeLimit Copyright 2019 - 2024 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -153,6 +153,10 @@ class DummyIntegration( // nothing to do } + override fun showExtraTimeStartedNotification(categoryId: String, categoryTitle: String) { + // nothing to do + } + override fun disableDeviceAdmin() { // nothing to do } diff --git a/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt b/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt index e209331..e8e07ed 100644 --- a/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt +++ b/app/src/main/java/io/timelimit/android/logic/BackgroundTaskLogic.kt @@ -1,5 +1,5 @@ /* - * TimeLimit Copyright 2019 - 2023 Jonas Lochmann + * TimeLimit Copyright 2019 - 2024 Jonas Lochmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -436,6 +436,9 @@ class BackgroundTaskLogic(val appLogic: AppLogic) { val oldRemainingTime = nowRemaining.includingExtraTime - timeToSubtractForCategory val newRemainingTime = oldRemainingTime - timeToSubtract + val oldRemainingNonExtraTime = nowRemaining.default - timeToSubtractForCategory + val newRemainingNonExtraTime = oldRemainingNonExtraTime - timeToSubtract + val commitedSessionDuration = handling.remainingSessionDuration val oldSessionDuration = handling.remainingSessionDuration?.let { it - timeToSubtractForCategory } @@ -476,6 +479,10 @@ class BackgroundTaskLogic(val appLogic: AppLogic) { ) } + if (oldRemainingNonExtraTime > 0 && newRemainingNonExtraTime <= 0) { + appLogic.platformIntegration.showExtraTimeStartedNotification(categoryId, category.title) + } + if (oldSessionDuration != null) { val newSessionDuration = oldSessionDuration - timeToSubtract diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 32db0bc..881f9d4 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1207,6 +1207,9 @@ neue Geräte Zeigt eine Benachrichtigung an, wenn TimeLimit mit Vernetzung verwendet wird und ein neues Gerät verknüpft wurde + Extrazeit beginnt + Informiert, wenn des reguläre Zeitkontingent verbraucht ist und nun Extrazeit verwendet wird + TimeLimit hat eine Benachrichtigung blockiert TimeLimit konnte eine Benachrichtigung nicht blockieren @@ -1222,6 +1225,8 @@ Gerät hinzugefügt + Extrazeit beginnt + Sie verwenden TimeLimit auf einer älteren Android-Version. Das kann funktionieren, aber es wird nicht empfohlen. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38fbfbb..79a5e6b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1256,6 +1256,9 @@ New Device Shows a notification if the connected mode is used and a new device was linked + Extra time starts + Informs when the regular time contingent was consumed and the extra time starts + TimeLimit has blocked a notification TimeLimit could not block a notification @@ -1271,6 +1274,8 @@ Device added + Extra time starts + You are using TimeLimit at a obsolete Android version. Although this can work, it is not recommend.