-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feat/on off for tablet #1464
Feat/on off for tablet #1464
Changes from 9 commits
69e6049
243ae96
da6736a
6679d80
6601d42
fca6226
30b5587
523e477
29793bb
ba478c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ class MosqueManager extends ChangeNotifier with WeatherMixin, AudioMixin, Mosque | |
bool isToggleScreenActivated = false; | ||
int minuteBefore = 0; | ||
int minuteAfter = 0; | ||
bool isIshaFajrOnly = false; | ||
|
||
/// get current home url | ||
String buildUrl(String languageCode) { | ||
|
@@ -102,6 +103,11 @@ class MosqueManager extends ChangeNotifier with WeatherMixin, AudioMixin, Mosque | |
return prefs.getInt(_minuteAfterKey) ?? 10; | ||
} | ||
|
||
static Future<bool> getisIshaFajr() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
return prefs.getBool(TurnOnOffTvConstant.kisFajrIshaOnly) ?? false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't forget to fix the typo |
||
} | ||
|
||
static Future<bool> checkRoot() async { | ||
try { | ||
final result = await MethodChannel(TurnOnOffTvConstant.kNativeMethodsChannel).invokeMethod( | ||
|
@@ -123,7 +129,7 @@ class MosqueManager extends ChangeNotifier with WeatherMixin, AudioMixin, Mosque | |
isEventsSet = await ToggleScreenFeature.checkEventsScheduled(); | ||
minuteBefore = await getMinuteBefore(); | ||
minuteAfter = await getMinuteAfter(); | ||
|
||
isIshaFajrOnly = await getisIshaFajr(); | ||
notifyListeners(); | ||
} | ||
|
||
|
@@ -220,6 +226,7 @@ class MosqueManager extends ChangeNotifier with WeatherMixin, AudioMixin, Mosque | |
ToggleScreenFeature.checkEventsScheduled().then((_) { | ||
if (!isEventsSet) { | ||
ToggleScreenFeature.scheduleToggleScreen( | ||
isIshaFajrOnly, | ||
e.dayTimesStrings(today, salahOnly: false), | ||
minuteBefore, | ||
minuteAfter, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before scheduling a new timer, cancel any existing timers for that prayer time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; | |
import 'package:mawaqit/main.dart'; | ||
import 'package:mawaqit/src/const/constants.dart'; | ||
import 'package:mawaqit/src/helpers/AppDate.dart'; | ||
import 'package:mawaqit/src/helpers/TimeShiftManager.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class ToggleScreenFeature { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Multiple calls to SharedPreferences.getInstance() in can be inefficient. Recommendation: Cache the SharedPreferences instance.
|
||
|
@@ -18,11 +19,14 @@ class ToggleScreenFeature { | |
static final Map<String, List<Timer>> _scheduledTimers = {}; | ||
|
||
static Future<void> scheduleToggleScreen( | ||
List<String> timeStrings, int beforeDelayMinutes, int afterDelayMinutes) async { | ||
for (String timeString in timeStrings) { | ||
final parts = timeString.split(':'); | ||
final hour = int.parse(parts[0]); | ||
final minute = int.parse(parts[1]); | ||
bool isfajrIshaonly, List<String> timeStrings, int beforeDelayMinutes, int afterDelayMinutes) async { | ||
final timeShiftManager = TimeShiftManager(); | ||
|
||
if (isfajrIshaonly) { | ||
String fajrTime = timeStrings[0]; | ||
List<String> parts = fajrTime.split(':'); | ||
int hour = int.parse(parts[0]); | ||
int minute = int.parse(parts[1]); | ||
|
||
final now = AppDateTime.now(); | ||
DateTime scheduledDateTime = DateTime(now.year, now.month, now.day, hour, minute); | ||
|
@@ -32,19 +36,60 @@ class ToggleScreenFeature { | |
} | ||
|
||
final beforeDelay = scheduledDateTime.difference(now) - Duration(minutes: beforeDelayMinutes); | ||
if (beforeDelay.isNegative) { | ||
continue; | ||
|
||
if (!beforeDelay.isNegative) { | ||
final beforeTimer = Timer(beforeDelay, () { | ||
timeShiftManager.isLauncherInstalled ? _toggleBoxScreenOn() : _toggleTabletScreenOn(); | ||
}); | ||
_scheduledTimers[fajrTime] = [beforeTimer]; | ||
} | ||
|
||
String ishaTime = timeStrings[5]; | ||
parts = ishaTime.split(':'); | ||
hour = int.parse(parts[0]); | ||
minute = int.parse(parts[1]); | ||
|
||
scheduledDateTime = DateTime(now.year, now.month, now.day, hour, minute); | ||
|
||
if (scheduledDateTime.isBefore(now)) { | ||
scheduledDateTime = scheduledDateTime.add(Duration(days: 1)); | ||
} | ||
final beforeTimer = Timer(beforeDelay, () { | ||
_toggleBoxScreenOn(); | ||
}); | ||
|
||
final afterDelay = scheduledDateTime.difference(now) + Duration(minutes: afterDelayMinutes); | ||
|
||
final afterTimer = Timer(afterDelay, () { | ||
_toggleBoxScreenOff(); | ||
timeShiftManager.isLauncherInstalled ? _toggleBoxScreenOff() : _toggleTabletScreenOff(); | ||
}); | ||
_scheduledTimers[ishaTime] = [afterTimer]; | ||
} else { | ||
// Original logic for all prayer times | ||
for (String timeString in timeStrings) { | ||
final parts = timeString.split(':'); | ||
final hour = int.parse(parts[0]); | ||
final minute = int.parse(parts[1]); | ||
|
||
final now = AppDateTime.now(); | ||
DateTime scheduledDateTime = DateTime(now.year, now.month, now.day, hour, minute); | ||
|
||
if (scheduledDateTime.isBefore(now)) { | ||
scheduledDateTime = scheduledDateTime.add(Duration(days: 1)); | ||
} | ||
|
||
_scheduledTimers[timeString] = [beforeTimer, afterTimer]; | ||
final beforeDelay = scheduledDateTime.difference(now) - Duration(minutes: beforeDelayMinutes); | ||
if (beforeDelay.isNegative) { | ||
continue; | ||
} | ||
final beforeTimer = Timer(beforeDelay, () { | ||
_toggleBoxScreenOn(); | ||
}); | ||
|
||
final afterDelay = scheduledDateTime.difference(now) + Duration(minutes: afterDelayMinutes); | ||
final afterTimer = Timer(afterDelay, () { | ||
_toggleBoxScreenOff(); | ||
}); | ||
|
||
_scheduledTimers[timeString] = [beforeTimer, afterTimer]; | ||
} | ||
} | ||
await _saveScheduledTimersToPrefs(); | ||
} | ||
|
@@ -76,7 +121,6 @@ class ToggleScreenFeature { | |
}).toList(), | ||
); | ||
}); | ||
|
||
await prefs.setString(_scheduledTimersKey, json.encode(timersMap)); | ||
} | ||
|
||
|
@@ -90,6 +134,11 @@ class ToggleScreenFeature { | |
return prefs.getBool(TurnOnOffTvConstant.kActivateToggleFeature) ?? false; | ||
} | ||
|
||
static Future<bool> getToggleFeatureishaFajrState() async { | ||
final SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
return prefs.getBool(TurnOnOffTvConstant.kisFajrIshaOnly) ?? false; | ||
} | ||
|
||
static Future<void> cancelAllScheduledTimers() async { | ||
_scheduledTimers.forEach((timeString, timers) { | ||
for (final timer in timers) { | ||
|
@@ -120,6 +169,24 @@ class ToggleScreenFeature { | |
} | ||
} | ||
|
||
static Future<void> _toggleTabletScreenOn() async { | ||
try { | ||
await MethodChannel(TurnOnOffTvConstant.kNativeMethodsChannel) | ||
.invokeMethod(TurnOnOffTvConstant.kToggleTabletScreenOn); | ||
} on PlatformException catch (e) { | ||
logger.e(e); | ||
} | ||
} | ||
|
||
static Future<void> _toggleTabletScreenOff() async { | ||
try { | ||
await MethodChannel(TurnOnOffTvConstant.kNativeMethodsChannel) | ||
.invokeMethod(TurnOnOffTvConstant.kToggleTabletScreenOff); | ||
} on PlatformException catch (e) { | ||
logger.e(e); | ||
} | ||
} | ||
|
||
static Future<bool> checkEventsScheduled() async { | ||
final SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
logger.d("value${prefs.getBool("isEventsSet")}"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.