Skip to content

Commit

Permalink
Merge pull request #84 from akaMrNagar/dev
Browse files Browse the repository at this point in the history
Removed 5 minute limit on short content timer
  • Loading branch information
akaMrNagar authored Oct 3, 2024
2 parents 4aa5f80 + bf84f97 commit e1b9e35
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class MindfulAccessibilityService extends AccessibilityService implements
* <p>
* 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;


/**
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
11 changes: 2 additions & 9 deletions lib/providers/wellbeing_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -32,11 +30,6 @@ class WellBeingNotifier extends StateNotifier<WellBeingSettings> {
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);
Expand Down Expand Up @@ -77,6 +70,6 @@ class WellBeingNotifier extends StateNotifier<WellBeingSettings> {
);

/// 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);
}
18 changes: 2 additions & 16 deletions lib/ui/screens/home/wellbeing/shorts_timer_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -45,27 +43,15 @@ 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);
}

@override
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,
Expand Down
17 changes: 10 additions & 7 deletions lib/ui/screens/home/wellbeing/tab_wellbeing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,20 @@ class _TabWellBeingState extends ConsumerState<TabWellBeing> {
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(),
Expand All @@ -103,7 +106,7 @@ class _TabWellBeingState extends ConsumerState<TabWellBeing> {
/// Short usage progress bar
ShortsTimerChart(
isModifiable: isModifiable && haveAccessibilityPermission,
allowedTimeSec: max(allowedShortContentTimeSec, 1),
allowedTimeSec: max(allowedShortContentTimeSec, 0),
remainingTimeSec: remainingTimeSec,
).sliver,

Expand Down

0 comments on commit e1b9e35

Please sign in to comment.