mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-06 11:59:57 +02:00
Add notification when extra time starts
This commit is contained in:
parent
de9be70480
commit
82e8f65f0d
7 changed files with 63 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 - 2023 Jonas Lochmann
|
||||
* TimeLimit Copyright <C> 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<String>, suspend: Boolean): List<String>
|
||||
abstract fun stopSuspendingForAllApps()
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 - 2022 Jonas Lochmann
|
||||
* TimeLimit Copyright <C> 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 - 2023 Jonas Lochmann
|
||||
* TimeLimit Copyright <C> 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
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 - 2023 Jonas Lochmann
|
||||
* TimeLimit Copyright <C> 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
|
||||
|
||||
|
|
|
@ -1207,6 +1207,9 @@
|
|||
<string name="notification_channel_new_device_title">neue Geräte</string>
|
||||
<string name="notification_channel_new_device_description">Zeigt eine Benachrichtigung an, wenn TimeLimit mit Vernetzung verwendet wird und ein neues Gerät verknüpft wurde</string>
|
||||
|
||||
<string name="notification_channel_extra_time_started_title">Extrazeit beginnt</string>
|
||||
<string name="notification_channel_extra_time_started_description">Informiert, wenn des reguläre Zeitkontingent verbraucht ist und nun Extrazeit verwendet wird</string>
|
||||
|
||||
<string name="notification_filter_not_blocked_title">TimeLimit hat eine Benachrichtigung blockiert</string>
|
||||
<string name="notification_filter_blocking_failed_title">TimeLimit konnte eine Benachrichtigung nicht blockieren</string>
|
||||
|
||||
|
@ -1222,6 +1225,8 @@
|
|||
|
||||
<string name="notification_new_device_title">Gerät hinzugefügt</string>
|
||||
|
||||
<string name="notification_extra_time_started">Extrazeit beginnt</string>
|
||||
|
||||
<string name="obsolete_message">Sie verwenden TimeLimit auf einer älteren Android-Version.
|
||||
Das kann funktionieren, aber es wird nicht empfohlen.
|
||||
</string>
|
||||
|
|
|
@ -1256,6 +1256,9 @@
|
|||
<string name="notification_channel_new_device_title">New Device</string>
|
||||
<string name="notification_channel_new_device_description">Shows a notification if the connected mode is used and a new device was linked</string>
|
||||
|
||||
<string name="notification_channel_extra_time_started_title">Extra time starts</string>
|
||||
<string name="notification_channel_extra_time_started_description">Informs when the regular time contingent was consumed and the extra time starts</string>
|
||||
|
||||
<string name="notification_filter_not_blocked_title">TimeLimit has blocked a notification</string>
|
||||
<string name="notification_filter_blocking_failed_title">TimeLimit could not block a notification</string>
|
||||
|
||||
|
@ -1271,6 +1274,8 @@
|
|||
|
||||
<string name="notification_new_device_title">Device added</string>
|
||||
|
||||
<string name="notification_extra_time_started">Extra time starts</string>
|
||||
|
||||
<string name="obsolete_message">You are using TimeLimit at a obsolete Android version.
|
||||
Although this can work, it is not recommend.
|
||||
</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue