Skip to content

Commit

Permalink
Merge pull request #1689 from matthiasn/feat/health_import_date_range
Browse files Browse the repository at this point in the history
feat: date range in health import without lib
  • Loading branch information
matthiasn authored Mar 16, 2024
2 parents 574b239 + 707083f commit 3d84018
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 118 deletions.
4 changes: 2 additions & 2 deletions lib/blocs/journal/entry_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class EntryCubit extends Cubit<EntryState> {
);

focusNode.addListener(() {
_isFocused = focusNode.hasFocus;
if (_isFocused) {
_isFocused = true;
if (focusNode.hasFocus) {
hotKeyManager.register(
saveHotKey,
keyDownHandler: (hotKey) => save(),
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
"settingsHabitsStoryLabel": "Habit completion story",
"settingsHabitsTitle": "Habits",
"settingsHealthImportTitle": "Health Import",
"settingsHealthImportFromDate": "Start",
"settingsHealthImportToDate": "End",
"settingsLogsTitle": "Logs",
"settingsMaintenanceTitle": "Maintenance",
"settingsMatrixDeleteLabel": "Delete",
Expand Down
183 changes: 90 additions & 93 deletions lib/pages/settings/health_import_page.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// ignore_for_file: avoid_dynamic_calls

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intersperse/intersperse.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/logic/health_import.dart';
import 'package:lotti/pages/settings/sliver_box_adapter_page.dart';
import 'package:lotti/themes/colors.dart';
import 'package:lotti/widgets/date_time/datetime_field.dart';
import 'package:lotti/widgets/misc/buttons.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
import 'package:tinycolor2/tinycolor2.dart';

const spaceBetweenButtons = 10.0;

class HealthImportPage extends StatefulWidget {
const HealthImportPage({super.key});
Expand All @@ -30,99 +25,101 @@ class _HealthImportPageState extends State<HealthImportPage> {
super.initState();
}

void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
setState(() {
if (args.value is PickerDateRange) {
_dateFrom = args.value.startDate as DateTime;
_dateTo = (args.value.endDate ?? args.value.startDate) as DateTime;
}
});
}

@override
Widget build(BuildContext context) {
final localizations = AppLocalizations.of(context)!;

return SliverBoxAdapterPage(
title: localizations.settingsHealthImportTitle,
showBackButton: true,
child: Column(
children: <Widget>[
SfDateRangePicker(
backgroundColor: cardColor.lighten(40),
onSelectionChanged: _onSelectionChanged,
enableMultiView: true,
selectionMode: DateRangePickerSelectionMode.range,
initialSelectedRange: PickerDateRange(
_dateFrom,
_dateTo,
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
children: <Widget>[
DateTimeField(
dateTime: _dateFrom,
labelText: localizations.settingsHealthImportFromDate,
setDateTime: (DateTime value) {
setState(() {
_dateFrom = value;
});
},
mode: CupertinoDatePickerMode.date,
),
const SizedBox(height: 20),
DateTimeField(
dateTime: _dateTo,
labelText: localizations.settingsHealthImportToDate,
setDateTime: (DateTime value) {
setState(() {
_dateTo = value;
});
},
mode: CupertinoDatePickerMode.date,
),
),
const SizedBox(height: 20),
RoundedButton(
'Import Activity Data',
onPressed: () {
_healthImport.getActivityHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
);
},
),
const SizedBox(height: spaceBetweenButtons),
RoundedButton(
'Import Sleep Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: sleepTypes,
);
},
),
const SizedBox(height: spaceBetweenButtons),
RoundedButton(
'Import Heart Rate Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: heartRateTypes,
);
},
),
const SizedBox(height: spaceBetweenButtons),
RoundedButton(
'Import Blood Pressure Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: bpTypes,
);
},
),
const SizedBox(height: spaceBetweenButtons),
RoundedButton(
'Import Body Measurement Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: bodyMeasurementTypes,
);
},
),
const SizedBox(height: spaceBetweenButtons),
RoundedButton(
'Import Workout Data',
onPressed: () {
_healthImport.getWorkoutsHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
);
},
),
],
const SizedBox(height: 20),
...<Widget>[
RoundedButton(
'Import Activity Data',
onPressed: () {
_healthImport.getActivityHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
);
},
),
RoundedButton(
'Import Sleep Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: sleepTypes,
);
},
),
RoundedButton(
'Import Heart Rate Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: heartRateTypes,
);
},
),
RoundedButton(
'Import Blood Pressure Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: bpTypes,
);
},
),
RoundedButton(
'Import Body Measurement Data',
onPressed: () {
_healthImport.fetchHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
types: bodyMeasurementTypes,
);
},
),
RoundedButton(
'Import Workout Data',
onPressed: () {
_healthImport.getWorkoutsHealthData(
dateFrom: _dateFrom,
dateTo: _dateTo,
);
},
),
].intersperse(const SizedBox(height: 5)),
],
),
),
);
}
Expand Down
7 changes: 3 additions & 4 deletions lib/widgets/misc/buttons.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_fadein/flutter_fadein.dart';
import 'package:lotti/utils/platform.dart';

class Button extends StatelessWidget {
const Button(
Expand Down Expand Up @@ -63,9 +62,9 @@ class RoundedButton extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100),
),
padding: EdgeInsets.symmetric(
vertical: isMobile ? 20 : 30,
horizontal: isMobile ? 30 : 45,
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 20,
),
),
child: Text(label),
Expand Down
16 changes: 0 additions & 16 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2476,22 +2476,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.1"
syncfusion_flutter_core:
dependency: transitive
description:
name: syncfusion_flutter_core
sha256: "7666506885ebc8f62bb928ad4588a73e20caaff2b2cf2b2b56f67d98f4113525"
url: "https://pub.dev"
source: hosted
version: "24.2.9"
syncfusion_flutter_datepicker:
dependency: "direct main"
description:
name: syncfusion_flutter_datepicker
sha256: c010440ccef2beecb988684af3557c57ade8ea300d1177536f01059e3a16ce5d
url: "https://pub.dev"
source: hosted
version: "24.2.9"
synchronized:
dependency: transitive
description:
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: Achieve your goals and keep your data private with Lotti.
publish_to: 'none'
version: 0.9.434+2398
version: 0.9.435+2400

msix_config:
display_name: LottiApp
Expand Down Expand Up @@ -140,7 +140,6 @@ dependencies:
share_plus: ^7.0.0
sqflite: ^2.0.1
sqlite3_flutter_libs: ^0.5.15
syncfusion_flutter_datepicker: ^24.1.43
timezone: ^0.9.1
tinycolor2: ^3.0.0
url_launcher: ^6.1.2
Expand Down
1 change: 0 additions & 1 deletion test/pages/settings/health_import_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ void main() {
).called(1);

await tester.tap(heartRateButtonFinder);
await tester.scrollUntilVisible(workoutButtonFinder, 30);
await tester.tap(bpButtonFinder);
await tester.tap(bodyButtonFinder);
await tester.tap(workoutButtonFinder);
Expand Down

0 comments on commit 3d84018

Please sign in to comment.