mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 01:39:22 +02:00
Add handling if notification blocking is enabled
This commit is contained in:
parent
d7fd43685b
commit
29b919b94f
5 changed files with 25 additions and 14 deletions
|
@ -93,6 +93,7 @@ class NotificationListener: NotificationListenerService() {
|
|||
BlockingReason.BlockedAtThisTime -> getString(R.string.lock_reason_short_blocked_time_area)
|
||||
BlockingReason.MissingNetworkTime -> getString(R.string.lock_reason_short_missing_network_time)
|
||||
BlockingReason.RequiresCurrentDevice -> getString(R.string.lock_reason_short_requires_current_device)
|
||||
BlockingReason.NotificationsAreBlocked -> getString(R.string.lock_reason_short_notification_blocking)
|
||||
BlockingReason.None -> throw IllegalStateException()
|
||||
}
|
||||
)
|
||||
|
@ -115,7 +116,10 @@ class NotificationListener: NotificationListenerService() {
|
|||
return BlockingReason.None
|
||||
}
|
||||
|
||||
val blockingReason = blockingReasonUtil.getBlockingReason(sbn.packageName).waitForNonNullValue()
|
||||
val blockingReason = blockingReasonUtil.getBlockingReason(
|
||||
packageName = sbn.packageName,
|
||||
forNotification = true
|
||||
).waitForNonNullValue()
|
||||
|
||||
if (blockingReason == BlockingReason.None) {
|
||||
return BlockingReason.None
|
||||
|
|
|
@ -39,7 +39,8 @@ enum class BlockingReason {
|
|||
TimeOver,
|
||||
TimeOverExtraTimeCanBeUsedLater,
|
||||
MissingNetworkTime,
|
||||
RequiresCurrentDevice
|
||||
RequiresCurrentDevice,
|
||||
NotificationsAreBlocked
|
||||
}
|
||||
|
||||
class BlockingReasonUtil(private val appLogic: AppLogic) {
|
||||
|
@ -47,7 +48,7 @@ class BlockingReasonUtil(private val appLogic: AppLogic) {
|
|||
private const val LOG_TAG = "BlockingReason"
|
||||
}
|
||||
|
||||
fun getBlockingReason(packageName: String): LiveData<BlockingReason> {
|
||||
fun getBlockingReason(packageName: String, forNotification: Boolean): LiveData<BlockingReason> {
|
||||
// check precondition that the app is running
|
||||
|
||||
return appLogic.enable.switchMap {
|
||||
|
@ -62,14 +63,14 @@ class BlockingReasonUtil(private val appLogic: AppLogic) {
|
|||
if (user == null || user.type != UserType.Child) {
|
||||
liveDataFromValue(BlockingReason.None)
|
||||
} else {
|
||||
getBlockingReasonStep2(packageName, user, TimeZone.getTimeZone(user.timeZone))
|
||||
getBlockingReasonStep2(packageName, user, TimeZone.getTimeZone(user.timeZone), forNotification)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBlockingReasonStep2(packageName: String, child: User, timeZone: TimeZone): LiveData<BlockingReason> {
|
||||
private fun getBlockingReasonStep2(packageName: String, child: User, timeZone: TimeZone, forNotification: Boolean): LiveData<BlockingReason> {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(LOG_TAG, "step 2")
|
||||
}
|
||||
|
@ -80,11 +81,11 @@ class BlockingReasonUtil(private val appLogic: AppLogic) {
|
|||
} else if (AndroidIntegrationApps.ignoredApps.contains(packageName)) {
|
||||
return liveDataFromValue(BlockingReason.None)
|
||||
} else {
|
||||
return getBlockingReasonStep3(packageName, child, timeZone)
|
||||
return getBlockingReasonStep3(packageName, child, timeZone, forNotification)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBlockingReasonStep3(packageName: String, child: User, timeZone: TimeZone): LiveData<BlockingReason> {
|
||||
private fun getBlockingReasonStep3(packageName: String, child: User, timeZone: TimeZone, forNotification: Boolean): LiveData<BlockingReason> {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(LOG_TAG, "step 3")
|
||||
}
|
||||
|
@ -102,12 +103,12 @@ class BlockingReasonUtil(private val appLogic: AppLogic) {
|
|||
if (temporarilyAllowedApps.contains(packageName)) {
|
||||
liveDataFromValue(BlockingReason.None)
|
||||
} else {
|
||||
getBlockingReasonStep4(packageName, child, timeZone)
|
||||
getBlockingReasonStep4(packageName, child, timeZone, forNotification)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBlockingReasonStep4(packageName: String, child: User, timeZone: TimeZone): LiveData<BlockingReason> {
|
||||
private fun getBlockingReasonStep4(packageName: String, child: User, timeZone: TimeZone, forNotification: Boolean): LiveData<BlockingReason> {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(LOG_TAG, "step 4")
|
||||
}
|
||||
|
@ -137,20 +138,24 @@ class BlockingReasonUtil(private val appLogic: AppLogic) {
|
|||
if (categoryEntry2 == null) {
|
||||
liveDataFromValue(BlockingReason.NotPartOfAnCategory)
|
||||
} else {
|
||||
getBlockingReasonStep4Point5(categoryEntry2, child, timeZone, false)
|
||||
getBlockingReasonStep4Point5(categoryEntry2, child, timeZone, false, forNotification)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getBlockingReasonStep4Point5(categoryEntry, child, timeZone, false)
|
||||
getBlockingReasonStep4Point5(categoryEntry, child, timeZone, false, forNotification)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBlockingReasonStep4Point5(category: Category, child: User, timeZone: TimeZone, isParentCategory: Boolean): LiveData<BlockingReason> {
|
||||
private fun getBlockingReasonStep4Point5(category: Category, child: User, timeZone: TimeZone, isParentCategory: Boolean, forNotification: Boolean): LiveData<BlockingReason> {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(LOG_TAG, "step 4.5")
|
||||
}
|
||||
|
||||
if (forNotification && category.blockAllNotifications) {
|
||||
return liveDataFromValue(BlockingReason.NotificationsAreBlocked)
|
||||
}
|
||||
|
||||
if (category.temporarilyBlocked) {
|
||||
return liveDataFromValue(BlockingReason.TemporarilyBlocked)
|
||||
}
|
||||
|
@ -181,7 +186,7 @@ class BlockingReasonUtil(private val appLogic: AppLogic) {
|
|||
if (parentCategory == null) {
|
||||
liveDataFromValue(BlockingReason.None)
|
||||
} else {
|
||||
getBlockingReasonStep4Point5(parentCategory, child, timeZone, true)
|
||||
getBlockingReasonStep4Point5(parentCategory, child, timeZone, true, forNotification)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -72,7 +72,7 @@ class LockFragment : Fragment() {
|
|||
private val auth: ActivityViewModel by lazy { getActivityViewModel(activity!!) }
|
||||
private val logic: AppLogic by lazy { DefaultAppLogic.with(context!!) }
|
||||
private val title: String? by lazy { logic.platformIntegration.getLocalAppTitle(packageName) }
|
||||
private val blockingReason: LiveData<BlockingReason> by lazy { BlockingReasonUtil(logic).getBlockingReason(packageName) }
|
||||
private val blockingReason: LiveData<BlockingReason> by lazy { BlockingReasonUtil(logic).getBlockingReason(packageName, forNotification = false) }
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
val binding = LockFragmentBinding.inflate(layoutInflater, container, false)
|
||||
|
|
|
@ -82,4 +82,5 @@
|
|||
<string name="lock_reason_short_blocked_time_area">Sperrzeit</string>
|
||||
<string name="lock_reason_short_missing_network_time">Netzwerkzeit erforderlich</string>
|
||||
<string name="lock_reason_short_requires_current_device">nicht als aktuelles Gerät gewählt</string>
|
||||
<string name="lock_reason_short_notification_blocking">alle Benachrichtigungen werden blockiert</string>
|
||||
</resources>
|
||||
|
|
|
@ -86,4 +86,5 @@
|
|||
<string name="lock_reason_short_blocked_time_area">blocked time area</string>
|
||||
<string name="lock_reason_short_missing_network_time">missing network time</string>
|
||||
<string name="lock_reason_short_requires_current_device">device must be the current device</string>
|
||||
<string name="lock_reason_short_notification_blocking">all notifications are blocked</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue