From bf84f97698e8a7c688839c3238eeeb9c65be15b2 Mon Sep 17 00:00:00 2001 From: Pawan Nagar Date: Thu, 3 Oct 2024 16:31:06 +0530 Subject: [PATCH] Removed 5 minute limit on short content timer --- .../services/MindfulAccessibilityService.java | 5 ++--- lib/l10n/app_en.arb | 1 - lib/providers/wellbeing_provider.dart | 11 ++--------- .../home/wellbeing/shorts_timer_chart.dart | 18 ++---------------- .../screens/home/wellbeing/tab_wellbeing.dart | 17 ++++++++++------- 5 files changed, 16 insertions(+), 36 deletions(-) diff --git a/android/app/src/main/java/com/mindful/android/services/MindfulAccessibilityService.java b/android/app/src/main/java/com/mindful/android/services/MindfulAccessibilityService.java index d64ff5d..d2caddd 100644 --- a/android/app/src/main/java/com/mindful/android/services/MindfulAccessibilityService.java +++ b/android/app/src/main/java/com/mindful/android/services/MindfulAccessibilityService.java @@ -78,7 +78,7 @@ public class MindfulAccessibilityService extends AccessibilityService implements *

* If the difference between last time shorts check and current time exceeds this then the short content is considered to be closed */ - private static final long SHORT_CONTENT_ACTIVITY_APPROX = 60 * 1000; + private static final long SHORT_CONTENT_ACTIVITY_APPROX = 30 * 1000; /** @@ -168,7 +168,6 @@ public void onAccessibilityEvent(@NonNull AccessibilityEvent event) { // Return if not enough information about node if (node == null || node.getClassName() == null) return; - logNodeInfoRecursively(node); switch (packageName) { case INSTAGRAM_PACKAGE: if (mWellBeingSettings.blockInstaReels && ShortsBlockingHelper.isInstaReelsOpen(node)) { @@ -330,7 +329,7 @@ private String extractBrowserUrl(@NonNull AccessibilityNodeInfo node, String pac * Checks the total screen time for short-form content and blocks access if the allowed time has been exceeded. */ private void checkTimerAndBlockShortContent() { - if (mTotalShortsScreenTimeMs > (mWellBeingSettings.allowedShortContentTimeMs + SHARED_PREF_INVOKE_INTERVAL_MS)) { + if (mWellBeingSettings.allowedShortContentTimeMs < 0 || mTotalShortsScreenTimeMs > (mWellBeingSettings.allowedShortContentTimeMs + SHARED_PREF_INVOKE_INTERVAL_MS)) { goBackWithToast(); return; } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 924853b..84dcf77 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -186,7 +186,6 @@ } } }, - "short_content_minimum_time_snack_alert": "Please ensure the timer for short content is set to a minimum of 5 minutes.", "short_content_invincible_mode_info": "You have exhausted the daily short content quota time. Due to invincible mode, modifications to settings related to short content are not allowed.", "block_insta_reels_title": "Block reels", "block_insta_reels_subtitle": "Restrict reels on instagram.", diff --git a/lib/providers/wellbeing_provider.dart b/lib/providers/wellbeing_provider.dart index 1f23675..65a5818 100644 --- a/lib/providers/wellbeing_provider.dart +++ b/lib/providers/wellbeing_provider.dart @@ -13,8 +13,6 @@ import 'package:mindful/core/services/isar_db_service.dart'; import 'package:mindful/core/services/method_channel_service.dart'; import 'package:mindful/models/isar/wellbeing_settings.dart'; -/// Minimum short content time is 5 minutes. -const int minimumShortTimerSecs = 5 * 60; /// A Riverpod state notifier provider that manages well-being related settings. final wellBeingProvider = @@ -32,11 +30,6 @@ class WellBeingNotifier extends StateNotifier { void _init() async { state = await IsarDbService.instance.loadWellBeingSettings(); - /// Update timer if it is less than minimum time - if (state.allowedShortContentTimeSec < minimumShortTimerSecs) { - setAllowedShortContentTime(minimumShortTimerSecs); - } - /// Listen to provider and save changes to Isar database and platform service addListener((state) async { await IsarDbService.instance.saveWellBeingSettings(state); @@ -77,6 +70,6 @@ class WellBeingNotifier extends StateNotifier { ); /// Sets the allowed time limit for short content consumption. - void setAllowedShortContentTime(int timeSec) => - state = state.copyWith(allowedShortContentTimeSec: timeSec); + void setAllowedShortContentTime(int timeSec) => state = + state.copyWith(allowedShortContentTimeSec: timeSec > 0 ? timeSec : -1); } diff --git a/lib/ui/screens/home/wellbeing/shorts_timer_chart.dart b/lib/ui/screens/home/wellbeing/shorts_timer_chart.dart index 9259e46..455630e 100644 --- a/lib/ui/screens/home/wellbeing/shorts_timer_chart.dart +++ b/lib/ui/screens/home/wellbeing/shorts_timer_chart.dart @@ -8,8 +8,6 @@ * */ -import 'dart:math'; - import 'package:fluentui_system_icons/fluentui_system_icons.dart'; import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; @@ -45,16 +43,6 @@ class ShortsTimerChart extends ConsumerWidget { ); if (newTime == allowedTimeSec) return; - - if (newTime < minimumShortTimerSecs) { - if (context.mounted) { - context.showSnackAlert( - context.locale.short_content_minimum_time_snack_alert, - ); - } - return; - } - ref.read(wellBeingProvider.notifier).setAllowedShortContentTime(newTime); } @@ -62,10 +50,8 @@ class ShortsTimerChart extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { const double squareDimension = 208; - final progressValue = max( - 0.0001, - (remainingTimeSec / allowedTimeSec), - ); + final double progressValue = + allowedTimeSec > 0 ? (remainingTimeSec / allowedTimeSec) : 0; final lerpedColor = Color.lerp( Theme.of(context).colorScheme.errorContainer, diff --git a/lib/ui/screens/home/wellbeing/tab_wellbeing.dart b/lib/ui/screens/home/wellbeing/tab_wellbeing.dart index 27fb73f..9cf9f79 100644 --- a/lib/ui/screens/home/wellbeing/tab_wellbeing.dart +++ b/lib/ui/screens/home/wellbeing/tab_wellbeing.dart @@ -77,17 +77,20 @@ class _TabWellBeingState extends ConsumerState { permissionProvider.select((v) => v.haveAccessibilityPermission), ); - final remainingTimeSec = max( - 0, - (allowedShortContentTimeSec - _shortsScreenTimeSec), - ); + final remainingTimeSec = allowedShortContentTimeSec.isNegative + ? 0 + : max( + 0, + (allowedShortContentTimeSec - _shortsScreenTimeSec), + ); final isInvincibleModeOn = ref.watch( settingsProvider.select((v) => v.isInvincibleModeOn), ); - final isModifiable = - !isInvincibleModeOn || (isInvincibleModeOn && remainingTimeSec > 0); + final isModifiable = allowedShortContentTimeSec.isNegative || + !isInvincibleModeOn || + (isInvincibleModeOn && remainingTimeSec > 0); return CustomScrollView( physics: const BouncingScrollPhysics(), @@ -103,7 +106,7 @@ class _TabWellBeingState extends ConsumerState { /// Short usage progress bar ShortsTimerChart( isModifiable: isModifiable && haveAccessibilityPermission, - allowedTimeSec: max(allowedShortContentTimeSec, 1), + allowedTimeSec: max(allowedShortContentTimeSec, 0), remainingTimeSec: remainingTimeSec, ).sliver,