Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsRefsgaard committed Sep 25, 2023
1 parent c738ba9 commit dae54f9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 47 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_activity_recognition: 5c3b026997742b01e82424ef257db9640822ad77
flutter_blue_plus: 5cb46a0d66c6cacebf7551e0e5a6bfa345ccc224
flutter_inappwebview: 50b55a88f5dddadc9e741a7caf72f378116e2156
flutter_inappwebview: 0fd654db805825eae42bd8ee7c428890cdaf7ff1
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
flutter_sound: c60effa2a350fb977885f0db2fbc4c1ad5160900
flutter_sound_core: 26c10e5832e76aaacfae252d8925232281c486ae
Expand Down Expand Up @@ -248,4 +248,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 42054b155feb53182d53e51787077e2e6389a1c1

COCOAPODS: 1.12.1
COCOAPODS: 1.13.0
35 changes: 0 additions & 35 deletions lib/blocs/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,41 +174,6 @@ class StudyAppBLoC {
_state = StudyAppState.configured;
}

/// Does this app use location permissions?
bool get usingLocationPermissions =>
SamplingPackageRegistry().permissions.any((permission) =>
permission == Permission.location ||
permission == Permission.locationWhenInUse ||
permission == Permission.locationAlways);

/// Configuration of permissions.
///
/// If a [context] is provided, this method also opens the [LocationUsageDialog]
/// if location permissions are needed and not yet granted.
Future<void> configurePermissions(BuildContext? context) async {
if (usingLocationPermissions && context != null) {
var status = await Permission.locationAlways.status;
if (!status.isGranted && Platform.isAndroid && context.mounted) {
await showGeneralDialog(
context: context,
barrierDismissible: false,
barrierColor: Colors.black38,
transitionBuilder: (ctx, anim1, anim2, child) => BackdropFilter(
filter: ui.ImageFilter.blur(
sigmaX: 4 * anim1.value, sigmaY: 4 * anim1.value),
child: FadeTransition(
opacity: anim1,
child: child,
),
),
pageBuilder: (context, anim1, anim2) => LocationUsageDialog().build(
context,
"ic.location.content",
));
await LocationManager().requestPermission();
}
}
}

/// Has the informed consent been shown to, and accepted by the user?
bool get hasInformedConsentBeenAccepted =>
Expand Down
3 changes: 0 additions & 3 deletions lib/sensing/sensing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,4 @@ class Sensing {

info("Study protocol translated to locale '${localization.locale}'");
}

Future<void> askForPermissions() async =>
await SmartPhoneClientManager().askForAllPermissions();
}
2 changes: 1 addition & 1 deletion lib/ui/pages/bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
bloc.configurePermissions(context);
// bloc.configurePermissions(context);
bloc.configureStudy().then((_) => bloc.start());
}

Expand Down
10 changes: 10 additions & 0 deletions lib/ui/pages/devices_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class DevicesPageState extends State<DevicesPage> {
delegate:
SliverChildBuilderDelegate((BuildContext context, int index) {
DeviceModel service = onlineServices[index];
service.deviceManager.hasPermissions().then((value) {
service.status =
value ? DeviceStatus.connected : DeviceStatus.connecting;
});
return devicesPageCardStream(
service.deviceEvents,
() => cardListBuilder(
Expand All @@ -153,6 +157,8 @@ class DevicesPageState extends State<DevicesPage> {
color: Theme.of(context).primaryColor))
: service.getServiceStatusIcon,
isThreeLine: false,
onTap: () async =>
await service.deviceManager.requestPermissions(),
),
DeviceStatus.unknown);
}, childCount: onlineServices.length),
Expand Down Expand Up @@ -214,6 +220,10 @@ class DevicesPageState extends State<DevicesPage> {
);

void physicalDeviceClicked(DeviceModel device) async {
if (!(await device.deviceManager.hasPermissions())) {
await device.deviceManager.requestPermissions();
}

if (await FlutterBluePlus.isAvailable == false) {
warning("Bluetooth not supported by this device");
return;
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/pages/task_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class TaskListPageState extends State<TaskListPage> {
@override
Widget build(BuildContext context) {
RPLocalizations locale = RPLocalizations.of(context)!;
bloc.configurePermissions(context);

return Scaffold(
backgroundColor: Theme.of(context).colorScheme.secondary,
body: SafeArea(
Expand Down
8 changes: 4 additions & 4 deletions lib/view_models/devices_page_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DeviceModel {

String? get type => deviceManager.type;
DeviceStatus get status => deviceManager.status;
set status(DeviceStatus status) => deviceManager.status = status;

/// Stream of [DeviceStatus] events
Stream<DeviceStatus> get deviceEvents => deviceManager.statusEvents;
Expand All @@ -33,9 +34,7 @@ class DeviceModel {

/// A printer-friendly description of this device.
String get description =>
'${deviceTypeDescription[type!]} - $statusString\n$batteryLevel% battery remaining.';

String get statusString => status.toString().split('.').last;
'${deviceTypeDescription[type!]} - ${status.name}\n$batteryLevel% battery remaining.';

/// The battery level of this device.
///
Expand Down Expand Up @@ -109,7 +108,8 @@ class DeviceModel {
};

static Map<DeviceStatus, dynamic> get serviceStatusIcon => {
DeviceStatus.initialized: "pages.devices.status.action.connect",
DeviceStatus.initialized:
const Icon(Icons.error_outline, color: CACHET.RED_1, size: 30),
DeviceStatus.connecting: const Icon(Icons.sensors_off_rounded,
color: CACHET.GREEN_1, size: 30),
DeviceStatus.connected:
Expand Down

0 comments on commit dae54f9

Please sign in to comment.