-
Notifications
You must be signed in to change notification settings - Fork 203
Customizable Time Limits for Alarm Challenges #734
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
Open
mahendra-918
wants to merge
11
commits into
CCExtractor:main
Choose a base branch
from
mahendra-918:challenge-time-limit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1fff9bb
Create time_imit_view.dart
mahendra-918 2b64c38
Update time_imit_view.dart
mahendra-918 54005c7
Update settings_view.dart
mahendra-918 15d32c1
Update settings_controller.dart
mahendra-918 93a7ceb
Update alarm_challenge_controller.dart
mahendra-918 76ca871
Update alarm_challenge_view.dart
mahendra-918 e43d8de
Update secure_storage_provider.dart
mahendra-918 1c285d5
final code
mahendra-918 8d134d5
changes
mahendra-918 64d61ef
Merge branch 'CCExtractor:main' into challenge-time-limit
mahendra-918 a228fdd
changes
mahendra-918 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import 'package:ultimate_alarm_clock/app/data/models/alarm_model.dart'; | |
import 'package:ultimate_alarm_clock/app/utils/audio_utils.dart'; | ||
import 'package:ultimate_alarm_clock/app/utils/constants.dart'; | ||
import 'package:ultimate_alarm_clock/app/utils/utils.dart'; | ||
import 'package:ultimate_alarm_clock/app/data/providers/secure_storage_provider.dart'; // Import secure storage provider | ||
|
||
class AlarmChallengeController extends GetxController { | ||
AlarmModel alarmRecord = Get.arguments; | ||
|
@@ -42,6 +43,7 @@ class AlarmChallengeController extends GetxController { | |
bool shouldProcessStepCount = false; | ||
|
||
late Stream<StepCount> _stepCountStream; | ||
Timer? _timer; | ||
|
||
void onButtonPressed(String buttonText) { | ||
displayValue.value += buttonText; | ||
|
@@ -89,7 +91,7 @@ class AlarmChallengeController extends GetxController { | |
@override | ||
void onInit() async { | ||
super.onInit(); | ||
_startTimer(); | ||
await _startTimer(); | ||
|
||
String ringtoneName = alarmRecord.ringtoneName; | ||
|
||
|
@@ -199,29 +201,23 @@ class AlarmChallengeController extends GetxController { | |
} | ||
} | ||
|
||
void _startTimer() async { | ||
const duration = Duration(seconds: 15); | ||
const totalIterations = 1500000; | ||
const decrement = 0.000001; | ||
|
||
for (var i = totalIterations; i > 0; i--) { | ||
if (!isTimerEnabled) { | ||
debugPrint('THIS IS THE BUG'); | ||
break; | ||
} | ||
if (progress.value <= 0.0) { | ||
Future<void> _startTimer() async { | ||
int challengeTimeLimit = await SecureStorageProvider().readChallengeTimeLimit(); | ||
progress.value = 1.0; | ||
_timer = Timer.periodic(Duration(milliseconds: 100), (timer) { | ||
if (progress.value > 0) { | ||
progress.value -= 1 / (challengeTimeLimit * 10); | ||
} else { | ||
timer.cancel(); | ||
shouldProcessStepCount = false; | ||
Get.until((route) => route.settings.name == '/alarm-ring'); | ||
break; | ||
} | ||
await Future.delayed(duration ~/ i); | ||
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. It was done like this to keep the timer decreasing smoothly. |
||
progress.value -= decrement; | ||
} | ||
}); | ||
} | ||
|
||
restartTimer() { | ||
progress.value = 1.0; // Reset the progress to its initial value | ||
_startTimer(); // Start a new timer | ||
_timer?.cancel(); | ||
_startTimer(); | ||
} | ||
|
||
isChallengesComplete() { | ||
|
@@ -235,7 +231,7 @@ class AlarmChallengeController extends GetxController { | |
@override | ||
void onClose() async { | ||
super.onClose(); | ||
|
||
_timer?.cancel(); | ||
shouldProcessStepCount = false; | ||
|
||
String ringtoneName = alarmRecord.ringtoneName; | ||
|
@@ -255,4 +251,3 @@ class AlarmChallengeController extends GetxController { | |
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
|
||
import 'package:ultimate_alarm_clock/app/data/models/user_model.dart'; | ||
|
||
import 'package:ultimate_alarm_clock/app/data/providers/secure_storage_provider.dart'; | ||
import 'package:ultimate_alarm_clock/app/modules/home/controllers/home_controller.dart'; | ||
import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; | ||
|
@@ -22,6 +20,7 @@ class SettingsController extends GetxController { | |
final _hapticFeedbackKey = 'haptic_feedback'; | ||
var is24HrsEnabled = false.obs; | ||
final _f24HrsEnabledKey = '24_hours_format'; | ||
final RxInt challengeTimeLimit = 30.obs; | ||
var isSortedAlarmListEnabled = true.obs; | ||
final _sortedAlarmListKey = 'sorted_alarm_list'; | ||
var currentLanguage = 'en_US'.obs; | ||
|
@@ -74,10 +73,21 @@ class SettingsController extends GetxController { | |
userModel.value = await _secureStorageProvider.retrieveUserModel(); | ||
} | ||
_loadPreference(); | ||
_loadChallengeSettings(); | ||
} | ||
|
||
// Logins user using GoogleSignIn | ||
void _loadChallengeSettings() async { | ||
// Store the retrieved challenge time limit from secure storage | ||
int storedTimeLimit = await _secureStorageProvider.readChallengeTimeLimit(); | ||
challengeTimeLimit.value = storedTimeLimit; | ||
} | ||
|
||
void updateTimeLimit(int newLimit) { | ||
challengeTimeLimit.value = newLimit; | ||
_secureStorageProvider.writeChallengeTimeLimit(newLimit); | ||
} | ||
|
||
// Logins user using GoogleSignIn | ||
Future<void> logoutGoogle() async { | ||
await GoogleCloudProvider.logoutGoogle(); | ||
await SecureStorageProvider().deleteUserModel(); | ||
|
@@ -94,21 +104,18 @@ class SettingsController extends GetxController { | |
getKey(ApiKeys key) async { | ||
return await _secureStorageProvider.retrieveApiKey(key); | ||
} | ||
|
||
// Add weather state to the flutter secure storage | ||
|
||
addWeatherState(String weatherState) async { | ||
await _secureStorageProvider.storeWeatherState(weatherState); | ||
} | ||
|
||
// Get weather state from the flutter secure storage | ||
|
||
getWeatherState() async { | ||
return await _secureStorageProvider.retrieveWeatherState(); | ||
} | ||
|
||
Future<bool> isApiKeyValid(String apiKey) async { | ||
final weather = WeatherFactory(apiKey); | ||
try { | ||
// ignore: unused_local_variable | ||
final currentWeather = await weather.currentWeatherByLocation( | ||
currentPoint.value.latitude, | ||
currentPoint.value.longitude, | ||
|
@@ -135,28 +142,22 @@ class SettingsController extends GetxController { | |
|
||
Future<bool> _checkAndRequestPermission({bool? background}) async { | ||
if (!await FlLocation.isLocationServicesEnabled) { | ||
// Location services are disabled. | ||
return false; | ||
} | ||
|
||
var locationPermission = await FlLocation.checkLocationPermission(); | ||
if (locationPermission == LocationPermission.deniedForever) { | ||
// Cannot request runtime permission because location permission is | ||
// denied forever. | ||
return false; | ||
} else if (locationPermission == LocationPermission.denied) { | ||
// Ask the user for location permission. | ||
locationPermission = await FlLocation.requestLocationPermission(); | ||
if (locationPermission == LocationPermission.denied || | ||
locationPermission == LocationPermission.deniedForever) return false; | ||
locationPermission == LocationPermission.deniedForever) | ||
return false; | ||
} | ||
|
||
// Location permission must always be allowed (LocationPermission.always) | ||
// to collect location data in the background. | ||
if (background == true && | ||
locationPermission == LocationPermission.whileInUse) return false; | ||
locationPermission == LocationPermission.whileInUse) | ||
return false; | ||
|
||
// Location services has been enabled and permission have been granted. | ||
return true; | ||
} | ||
|
||
|
@@ -185,11 +186,7 @@ class SettingsController extends GetxController { | |
|
||
// Store the retrieved weather state from the flutter secure storage | ||
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. please add back these comments |
||
String? retrievedWeatherState = await getWeatherState(); | ||
|
||
// If the weather state has been previously stored there | ||
if (retrievedWeatherState != null) { | ||
// Assign the weatherKeyState to the previously stored weather state, | ||
// but first convert the stored string to the WeatherKeyState enum | ||
weatherKeyState.value = WeatherKeyState.values.firstWhereOrNull( | ||
(weatherState) => weatherState.name == retrievedWeatherState, | ||
) ?? | ||
|
@@ -242,4 +239,4 @@ class SettingsController extends GetxController { | |
storage.writeCurrentLanguage(local.value); | ||
storage.writeLocale(languageCode, countryCode); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bring back these comments, helps us keep track of the logic.