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

Commit

Permalink
Merge pull request #274 from MXCzkEVM/blueberry_ring
Browse files Browse the repository at this point in the history
Blueberry ring
  • Loading branch information
reasje authored Aug 2, 2024
2 parents 3d988d0 + 5678925 commit 7918c52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {

Future<void> checkActivityReminder() async {
final data = await _blueberryRingUseCase.readSteps();
print(
'checkActivityReminder:data ${data.map((e) => e.toJson()).toList()}');
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
// Below 5000
Expand All @@ -41,8 +40,7 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {
now.month == lastDate.month &&
now.day == lastDate.day;

// isToday &&
if (latestData.step < 5000) {
if (isToday && latestData.step < 5000) {
AXSNotification().showNotification(
cTranslate('activity_reminder'),
cTranslate('blueberry_ring_inactive_alert_text'),
Expand All @@ -52,23 +50,23 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {

Future<void> checkSleepInsight() async {
final data = await _blueberryRingUseCase.readSleep();
print(
'checkSleepInsight:data ${data.map((e) => e.toJson()).toList()}');
print('checkSleepInsight:data ${data.map((e) => e.toJson()).toList()}');
// If sleeps is below standard level
// loop throug all and get average
final now = DateTime.now();

final todaysData = data.where((element) {
// final date = DateTime.fromMillisecondsSinceEpoch(
// element.date * 1000,
// );
// final isToday = now.year == date.year &&
// now.month == date.month &&
// now.day == date.day;
// return isToday;
return true;
final date = DateTime.fromMillisecondsSinceEpoch(
element.date * 1000,
);
final isToday = now.year == date.year &&
now.month == date.month &&
now.day == date.day;
return isToday;
});

print(
'checkSleepInsight:todaysData ${todaysData.map((e) => e.toJson()).toList()}');
if (todaysData.isEmpty) {
return;
}
Expand Down Expand Up @@ -97,8 +95,7 @@ class BlueberryRingBackgroundNotificationsUseCase extends ReactiveUseCase {
now.month == lastDate.month &&
now.day == lastDate.day;

// isToday &&
if (latestData.value >= 100) {
if (isToday && latestData.value >= 100) {
AXSNotification().showNotification(
cTranslate('heart_alert'),
cTranslate('blueberry_ring_heart_rate_alert_text'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ class BlueberryRingUseCase extends ReactiveUseCase {
stream.listen((element) {
if (element.isNotEmpty && element.first == command.first) {
timer?.cancel();
collectLog('read$dataName:value $element');
collectLog('read$dataName:element $element');
data.addAll(element);
collectLog('read$dataName:value $data');

if (!completer.isCompleted && !isFrag) {
completer.complete(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class BlueberryCommandsUtils {
static List<List<T>> splitArrayByLength<T>(List<T> arr, int length) {
List<List<T>> result = [];
for (int i = 0; i < arr.length; i += length) {
result.add(arr.sublist(i, i + length));
int end = (i + length < arr.length) ? i + length : arr.length;
result.add(arr.sublist(i, end));
}
return result;
}
Expand Down

0 comments on commit 7918c52

Please sign in to comment.