Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Blueberry ring #261

Merged
merged 2 commits into from
Jul 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {

Future<void> checkActivityReminder() async {
final data = await _blueberryRingUseCase.readSteps();
collectLog(
print(
'checkActivityReminder:data ${data.map((e) => e.toJson()).toList()}');
// Get spteps data from cache and compare
// If steps is below a certain number then show a
Expand All @@ -52,7 +52,7 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {

Future<void> checkSleepInsight() async {
final data = await _blueberryRingUseCase.readSleep();
collectLog(
print(
'checkSleepInsight:data ${data.map((e) => e.toJson()).toList()}');
// If sleeps is below standard level
// loop throug all and get average
Expand Down Expand Up @@ -86,7 +86,7 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {

Future<void> checkHeartAlert() async {
final data = await _blueberryRingUseCase.readHeartRate();
collectLog('checkHeartAlert:data ${data.map((e) => e.toJson()).toList()}');
print('checkHeartAlert:data ${data.map((e) => e.toJson()).toList()}');
// If below standard but between person to person different
final latestData = data.first;
final lastDate = DateTime.fromMillisecondsSinceEpoch(
Expand All @@ -108,7 +108,7 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {

Future<void> checkLowBattery() async {
final data = await _blueberryRingUseCase.readLevel();
collectLog('checkLowBattery:data $data');
print('checkLowBattery:data $data');
// What si the low battery level
// Is 10 OK
if (data < 20) {
Expand Down
2 changes: 1 addition & 1 deletion lib/features/settings/presentation/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SettingsPage extends HookConsumerWidget {
height: Sizes.space2XLarge,
),
GestureDetector(
onTap: AXSFireBase.incrementBuildTap,
onTap: presenter.testOnly,
child: Text(
'${FlutterI18n.translate(context, 'app_version')}${state.appVersion ?? ''}',
style: FontTheme.of(context)
Expand Down
11 changes: 11 additions & 0 deletions lib/features/settings/presentation/settings_page_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class SettingsPresenter extends CompletePresenter<SettingsState> {
late final _webviewUseCase = WebviewUseCase();
late final _authUseCase = ref.read(authUseCaseProvider);
late final _accountUserCase = ref.read(accountUseCaseProvider);
late final blueberryRingBackgroundNotificationsUseCase =
ref.read(blueberryRingBackgroundNotificationsUseCaseProvider);
late final contextLessTranslationUseCase =
ref.read(contextLessTranslationUseCaseProvider);

@override
void initState() {
Expand Down Expand Up @@ -102,4 +106,11 @@ class SettingsPresenter extends CompletePresenter<SettingsState> {
void loadCache() {
_webviewUseCase.clearCache();
}

void testOnly() async {
await blueberryRingBackgroundNotificationsUseCase.checkActivityReminder();
await blueberryRingBackgroundNotificationsUseCase.checkSleepInsight();
await blueberryRingBackgroundNotificationsUseCase.checkHeartAlert();
await blueberryRingBackgroundNotificationsUseCase.checkLowBattery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ class DAppHooksUseCase extends ReactiveUseCase {
return false;
}
}
Future<int> stopBlueberryAutoSyncService({required bool turnOffAll}) async {
return await AXSBackgroundFetch.stopServices(
taskId: blueberryAutoSyncTask, turnOffAll: turnOffAll);
}

Future<int> stopMinerAutoClaimService({required bool turnOffAll}) async {
return await AXSBackgroundFetch.stopServices(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class BlueberryHooksHelper {
// After all enabled start service
// listen for state and stop If the bluetooth & nearby device is went off
// The Service will listen to the ad data and do the things on that
final success = await dAppHooksUseCase.scheduleAutoClaimTransaction(time);
final success =
await dAppHooksUseCase.scheduleBlueberryAutoSyncTransaction(time);

if (success) {
// Time past, need to run the auto claim
Expand Down Expand Up @@ -64,21 +65,36 @@ class BlueberryHooksHelper {
return true;
}

Future<void> changeMinerHooksEnabled(
Future<void> changeBLueberryRingHooksEnabled(
bool value,
) {
return DAppHooksHelper.shouldUpdateWrapper(() async {
late bool update;
if (value) {
update = await startBlueberryRingHooksService(
time: dAppHooksUseCase.dappHooksData.value.minerHooks.time,
time: dAppHooksUseCase.dappHooksData.value.blueberryRingHooks.time,
showBGFetchAlert: true);
} else {
update = await stopBlueberryRingService(showSnackbar: true);
}
return update;
}, () {
return dAppHooksUseCase.updateMinerHooksEnabled(value);
return dAppHooksUseCase.updateBlueberryRingHooksEnabled(value);
});
}

Future<void> changeBlueberryRingHookTiming(TimeOfDay value) async {
return DAppHooksHelper.shouldUpdateWrapper(() async {
late bool update;
final currentDateTime =
dAppHooksUseCase.dappHooksData.value.blueberryRingHooks.time;
final time = currentDateTime.copyWith(
hour: value.hour, minute: value.minute, second: 0);
update = await startBlueberryRingHooksService(
time: time, showBGFetchAlert: false);
return update;
}, () {
return dAppHooksUseCase.updateBlueberryRingHookTiming(value);
});
}
}
Loading