From 9cb64041b4e919ff384007e9c697fcf23a9edc3a Mon Sep 17 00:00:00 2001 From: AtomicNicos Date: Tue, 11 Feb 2020 17:26:23 +0100 Subject: [PATCH] Trying to get a Dialog with All options going, Dialog should include frequent selections --- .flutter-plugins-dependencies | 2 +- THOUGHTS.md | 22 +++++++++--- lib/main.dart | 7 ++-- lib/platform/bluetooth_le_service.dart | 34 +++++++++++++++++-- lib/platform/wake_service.dart | 8 ++++- lib/ui/data_widget.dart | 19 +++++------ lib/ui/dialog/bluetooth_selection_dialog.dart | 16 +++++++++ pubspec.lock | 7 ---- pubspec.yaml | 1 - 9 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 lib/ui/dialog/bluetooth_selection_dialog.dart diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index dccde80..c502626 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"battery","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"plugin_scaffold","dependencies":[]},{"name":"rx_ble","dependencies":["plugin_scaffold"]},{"name":"sqflite","dependencies":[]}]} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"plugin_scaffold","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\plugin_scaffold-1.2.0\\\\","dependencies":[]},{"name":"rx_ble","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\rx_ble-0.6.1\\\\","dependencies":["plugin_scaffold"]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"plugin_scaffold","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\plugin_scaffold-1.2.0\\\\","dependencies":[]},{"name":"rx_ble","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\rx_ble-0.6.1\\\\","dependencies":["plugin_scaffold"]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"plugin_scaffold","dependencies":[]},{"name":"rx_ble","dependencies":["plugin_scaffold"]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-02-11 17:16:22.831677","version":"1.14.7-pre.83"} \ No newline at end of file diff --git a/THOUGHTS.md b/THOUGHTS.md index 03f4c41..d24168f 100644 --- a/THOUGHTS.md +++ b/THOUGHTS.md @@ -6,13 +6,15 @@ The idea for BLE is to use Platform specific code, ie `Platform channels`... | Platform Specific | Cross OS | | ------------------------ | ------------------------:| -| Bluetooth Read | Scan named MAC addresses | -| Stay Alive | Write to File | -| | | +| Stay Alive | Scan environment | +| | Scan named MAC addresses | +| | Write to File | | Get Battery level ✅ | | Testing procedure for background will include the backup system as well (ie. writing to files). +### [0.0.2] Android + `BatteryService`, `BTLEHandler`, `WebsocketHandler` and the likes should be `Singletons`, to reduce load on the platform. Also, `BTLEHandler` needs to follow an inverse paradigm to `BatteryService`, ie. it shouldn't request updates but listen to them. @@ -27,7 +29,17 @@ Thought of firmware implementation for obfuscation / integrity verification. See Other option for making the service run in background: make the platform side tick once per second and notify the dart framework, may need to use a sticky notification as well. -### Resources +Notification turned out to be unnecessary, oops. + +___ + +### [0.0.2] iOS + +This is a tricky one. + +Sadly, because Apple doesn't care about it's users, we will only be able to support devices running `iOS >= 7.X` (100% of iPad 1, 1.5% of iPad 2, 100% of iPhone 3GS, 8.3% of iPhone 4 and 100% of iPod Touch 4 ~= 0.1% of the ecosystem, allegedly, although the iPhone 4 is barely 7 years old). + +### [0.0.2] Resources - [Permissions aaS](https://www.filledstacks.com/snippet/request-permissions-in-flutter-as-a-service/) - [Toasts](https://www.filledstacks.com/snippet/easy-toasts-with-ok-toast/) @@ -56,7 +68,7 @@ Useful to implement at the beginning because otherwise refactoring becomes painf Based on the intl package, and uses it's generators to convert the `.arb` files (text, description, etc. in JSON format) to `.dart` files, of which only one is loaded at launch (also possible to force reload on language switch). -### Resources +### [0.0.1] Resources - [Intl package documentation](https://pub.dev/packages/intl) \[[Code](https://github.com/dart-lang/intl)\] - [Intl extensibility documentation](https://github.com/flutter/website/blob/master/examples/internationalization/add_language/lib/main.dart) diff --git a/lib/main.dart b/lib/main.dart index 433f0e0..809eab1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:device_preview/device_preview.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; @@ -10,9 +11,9 @@ import 'package:logair_application/routes/home.dart'; // TODO USED FOR DEBUGGING final bool displayMode = false; -void main() => runApp(displayMode ? DevicePreview(child: MyApp()) : MyApp()); +void main() => runApp(displayMode ? DevicePreview(child: LogAirApplication()) : LogAirApplication()); -class MyApp extends StatelessWidget { +class LogAirApplication extends StatelessWidget { static const String _title = 'LogAir Connector'; // This widget is the root of your application. @@ -20,8 +21,6 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { BTLEHandler(); - - return MaterialApp( localizationsDelegates: [ const InternalLocalizationDelegate(), diff --git a/lib/platform/bluetooth_le_service.dart b/lib/platform/bluetooth_le_service.dart index 040f49f..73750d3 100644 --- a/lib/platform/bluetooth_le_service.dart +++ b/lib/platform/bluetooth_le_service.dart @@ -1,6 +1,34 @@ -import 'package:flutter/services.dart'; -import 'package:logair_application/enums/platform_channels.dart'; +import 'dart:async'; +import 'package:logair_application/platform/wake_service.dart'; class BTLEHandler { - // TODO Tick once per second as well + static final BTLEHandler _singleton = new BTLEHandler._internal(); + static bool started = false; + + static Duration duration = new Duration(seconds: 1); + Timer t; + + factory BTLEHandler() => _singleton; + + BTLEHandler._internal(); + + bool switchState() { + if (started) + _end(); + else + _start(); + + return started; + } + + void _start() { + WakeService().modifyWakeService(true).then((value) => print('Device will stay awake $value')); + started = true; + t = new Timer.periodic(duration, (Timer t) => print("${new DateTime.now()}")); + } + + void _end() { + WakeService().modifyWakeService(false).then((value) => print('Device will stay awake $value')); + t.cancel(); + } } \ No newline at end of file diff --git a/lib/platform/wake_service.dart b/lib/platform/wake_service.dart index e828c57..0fb35ac 100644 --- a/lib/platform/wake_service.dart +++ b/lib/platform/wake_service.dart @@ -1,8 +1,14 @@ import 'package:flutter/services.dart'; import 'package:logair_application/enums/platform_channels.dart'; -class WakeService { +class WakeService { static const MethodChannel methodChannel = const MethodChannel(Channels.WAKE); + static final WakeService _singleton = new WakeService._internal(); + factory WakeService() { + return _singleton; + } + + WakeService._internal(); Future modifyWakeService(bool start) async { bool wakeServiceStatus; diff --git a/lib/ui/data_widget.dart b/lib/ui/data_widget.dart index 9b904e1..2e638f5 100644 --- a/lib/ui/data_widget.dart +++ b/lib/ui/data_widget.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -import 'package:logair_application/platform/wake_service.dart'; +import 'package:logair_application/platform/bluetooth_le_service.dart'; import 'package:logair_application/ui/carousel_card.dart'; import 'package:logair_application/platform/battery_service.dart'; +import 'package:logair_application/ui/dialog/bluetooth_selection_dialog.dart'; class DataWidget extends StatelessWidget { DataWidget(); @@ -24,21 +25,17 @@ class DataWidget extends StatelessWidget { Text("Data", style: TextStyle(fontFamily: "Consolas", fontSize: 22)), RaisedButton( onPressed: () => { - WakeService().modifyWakeService(true).then((value) => print('Device will stay awake $value')) + // await BTLEHandler().dialog(ocntext) + BTLEHandler().switchState() }, - child: Text( - 'Start BG Service Ticker', - style: TextStyle(fontSize: 20) - ), + child: Text('Toggle BTLE Service'), ), RaisedButton( onPressed: () => { - WakeService().modifyWakeService(false).then((value) => print('Device will stay awake $value')) + //showBTElements + showBluetoothSelectionDialog(context) }, - child: Text( - 'End BG Service Ticker', - style: TextStyle(fontSize: 20) - ), + child: Text("BTLE popup") ) ] ) diff --git a/lib/ui/dialog/bluetooth_selection_dialog.dart b/lib/ui/dialog/bluetooth_selection_dialog.dart new file mode 100644 index 0000000..c763c31 --- /dev/null +++ b/lib/ui/dialog/bluetooth_selection_dialog.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; + +showBluetoothSelectionDialog(BuildContext context) { + List _frequentDevices = []; // await Devices, filter with cached values + + showDialog( + context: context, + builder: (BuildContext context) { + return SimpleDialog( + children: [ + + ], + ); + } + ); +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 58e6809..fdf115d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,13 +43,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.4.0" - battery: - dependency: "direct main" - description: - name: battery - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.1+7" boolean_selector: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2783561..7b0a582 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,6 @@ dependencies: provider: null geolocator: ^5.2.1 flutter_map: ^0.8.2 - battery: ^0.3.1+7 rx_ble: permission_handler: ^4.2.0+hotfix.3 get_it: ^3.1.0 -- GitLab