Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ on off update new selected minutes value to restore schedule #1568

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions lib/src/services/mosque_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,6 @@ class MosqueManager extends ChangeNotifier with WeatherMixin, AudioMixin, Mosque
return 'https://mawaqit.net/$languageCode/id/${mosque?.id}?view=desktop';
}

static const String _minuteBeforeKey = 'selectedMinuteBefore';
static const String _minuteAfterKey = 'selectedMinuteAfter';

static Future<int> getMinuteBefore() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getInt(_minuteBeforeKey) ?? 10;
}

static Future<int> getMinuteAfter() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getInt(_minuteAfterKey) ?? 10;
}

static Future<bool> getisIshaFajr() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getBool(TurnOnOffTvConstant.kisFajrIshaOnly) ?? false;
Expand Down Expand Up @@ -139,8 +126,7 @@ class MosqueManager extends ChangeNotifier with WeatherMixin, AudioMixin, Mosque
isDeviceRooted = await checkRoot();
isToggleScreenActivated = await ToggleScreenFeature.getToggleFeatureState();
isEventsSet = await ToggleScreenFeature.checkEventsScheduled();
minuteBefore = await getMinuteBefore();
minuteAfter = await getMinuteAfter();

isIshaFajrOnly = await getisIshaFajr();
notifyListeners();
}
Expand Down Expand Up @@ -225,17 +211,19 @@ class MosqueManager extends ChangeNotifier with WeatherMixin, AudioMixin, Mosque
);

_timesSubscription = timesStream.listen(
(e) {
(e) async {
times = e;
final today = useTomorrowTimes ? AppDateTime.tomorrow() : AppDateTime.now();
final timeShiftManager = TimeShiftManager();

if (isDeviceRooted && isToggleScreenActivated) {
final newMinuteBefore = await ToggleScreenFeature.getBeforeDelayMinutes();
final newMinuteAfter = await ToggleScreenFeature.getAfterDelayMinutes();

ToggleScreenFeature.handleDailyRescheduling(
isIshaFajrOnly: isIshaFajrOnly,
timeStrings: e.dayTimesStrings(today, salahOnly: false),
minuteBefore: minuteBefore,
minuteAfter: minuteAfter,
minuteBefore: newMinuteBefore,
minuteAfter: newMinuteAfter,
);
}

Expand Down
29 changes: 27 additions & 2 deletions lib/src/services/toggle_screen_feature_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,39 @@ class ToggleScreenFeature {
}
}

await Future.wait([saveScheduledEventsToLocale(), toggleFeatureState(true), setLastEventDate(now)]);
await Future.wait([
saveScheduledEventsToLocale(),
toggleFeatureState(true),
setLastEventDate(now),
saveBeforeDelayMinutes(beforeDelayMinutes),
saveAfterDelayMinutes(afterDelayMinutes),
]);
} catch (e) {
logger.e('Failed to schedule toggle screen: $e');
throw ScheduleToggleScreenException(e.toString());
}
}

static Future<int> getBeforeDelayMinutes() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getInt(TurnOnOffTvConstant.kMinuteBeforeKey) ?? 0;
}

static Future<int> getAfterDelayMinutes() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getInt(TurnOnOffTvConstant.kMinuteAfterKey) ?? 0;
}

static Future<void> saveBeforeDelayMinutes(int minutes) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setInt(TurnOnOffTvConstant.kMinuteBeforeKey, minutes);
}

static Future<void> saveAfterDelayMinutes(int minutes) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setInt(TurnOnOffTvConstant.kMinuteAfterKey, minutes);
}

static Future<bool> shouldReschedule() async {
final lastEventDate = await getLastEventDate();
final today = AppDateTime.now();
Expand All @@ -116,7 +142,6 @@ class ToggleScreenFeature {
}) async {
try {
final shouldSchedule = await shouldReschedule();

if (shouldSchedule) {
await cancelAllScheduledTimers();
await toggleFeatureState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class ScreenLockNotifier extends AsyncNotifier<ScreenLockState> {
ToggleScreenFeature.toggleFeatureState(true);

final prefs = await SharedPreferences.getInstance();
prefs.setInt(TurnOnOffTvConstant.kMinuteBeforeKey, state.value!.selectedMinuteBefore);
prefs.setInt(TurnOnOffTvConstant.kMinuteAfterKey, state.value!.selectedMinuteAfter);
prefs.setBool(TurnOnOffTvConstant.kisFajrIshaOnly, isIshaFajrOnly);
}
}
Expand Down