Skip to content

Commit

Permalink
add About your gear section and update check button
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Dec 22, 2024
1 parent 757a6d0 commit d270b1c
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 55 deletions.
1 change: 1 addition & 0 deletions lib/Backend/Definitions/Device/device_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ String getNameFromBTName(String bluetoothDeviceName) {
return bluetoothDeviceName;
}

//todo: convert into a proper provider
class CommandQueue {
final PriorityQueue<BluetoothMessage> state = PriorityQueue();
final BaseStatefulDevice device;
Expand Down
270 changes: 215 additions & 55 deletions lib/Frontend/Widgets/manage_gear.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tail_app/Backend/firmware_update.dart';
import 'package:tail_app/Backend/move_lists.dart';
import 'package:tail_app/Frontend/Widgets/tutorial_card.dart';

Expand Down Expand Up @@ -75,64 +76,73 @@ class _ManageGearState extends ConsumerState<ManageGear> {
),
),
],
if (device!.mandatoryOtaRequired.value) ...[
BaseCard(
elevation: 3,
color: Colors.red,
child: InkWell(
onTap: () async {
OtaUpdateRoute(device: device!.baseStoredDevice.btMACAddress).push(context);
},
child: ListTile(
leading: const Icon(
Icons.warning,
color: Colors.white,
),
trailing: const Icon(
Icons.warning,
color: Colors.white,
),
title: Text(
mandatoryOtaRequired(),
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Colors.white),
textAlign: TextAlign.center,
),
),
),
),
],
if (device!.hasUpdate.value) ...[
Padding(
padding: const EdgeInsets.all(16.0),
child: FilledButton(
onPressed: () async {
OtaUpdateRoute(device: device!.baseStoredDevice.btMACAddress).push(context);
},
style: ElevatedButton.styleFrom(
foregroundColor: getTextColor(color!),
elevation: 1,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.system_update,
color: getTextColor(color!),
),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 4),
),
Text(
manageDevicesOtaButton(),
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: getTextColor(color!),
ValueListenableBuilder(
valueListenable: device!.hasUpdate,
builder: (context, value, child) {
return Column(
children: [
if (device!.mandatoryOtaRequired.value) ...[
BaseCard(
elevation: 3,
color: Colors.red,
child: InkWell(
onTap: () async {
OtaUpdateRoute(device: device!.baseStoredDevice.btMACAddress).push(context);
},
child: ListTile(
leading: const Icon(
Icons.warning,
color: Colors.white,
),
trailing: const Icon(
Icons.warning,
color: Colors.white,
),
title: Text(
mandatoryOtaRequired(),
style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Colors.white),
textAlign: TextAlign.center,
),
),
),
),
],
),
),
),
],
if (device!.hasUpdate.value) ...[
Padding(
padding: const EdgeInsets.all(16.0),
child: FilledButton(
onPressed: () async {
OtaUpdateRoute(device: device!.baseStoredDevice.btMACAddress).push(context);
},
style: ElevatedButton.styleFrom(
foregroundColor: getTextColor(color!),
elevation: 1,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.system_update,
color: getTextColor(color!),
),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 4),
),
Text(
manageDevicesOtaButton(),
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: getTextColor(color!),
),
),
],
),
),
),
],
],
);
},
),
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
Expand Down Expand Up @@ -190,6 +200,13 @@ class _ManageGearState extends ConsumerState<ManageGear> {
ManageGearConventionMode(device: device!),
ManageGearDebug(device: device!),
],
// We only know this info if the gear is connected
if (device!.deviceConnectionState.value == ConnectivityState.connected) ...[
ManageGearAbout(
device: device!,
color: color!,
),
],
OverflowBar(
alignment: MainAxisAlignment.end,
children: [
Expand Down Expand Up @@ -250,6 +267,95 @@ class _ManageGearState extends ConsumerState<ManageGear> {
}
}

class ManageGearUpdateCheckButton extends ConsumerStatefulWidget {
final BaseStatefulDevice device;
final Color color;

const ManageGearUpdateCheckButton({super.key, required this.device, required this.color});

@override
ConsumerState<ConsumerStatefulWidget> createState() => _ManageGearUpdateCheckButtonState();
}

class _ManageGearUpdateCheckButtonState extends ConsumerState<ManageGearUpdateCheckButton> {
Future<bool>? _otaAvailable;

@override
Widget build(BuildContext context) {
return OverflowBar(
alignment: MainAxisAlignment.center,
children: [
FutureBuilder(
future: _otaAvailable,
builder: (context, snapshot) {
String buttonText = "";
IconData iconData = Icons.device_unknown;
if (snapshot.connectionState == ConnectionState.none) {
buttonText = manageDevicesOtaCheckButtonLabel();
iconData = Icons.question_mark;
} else if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) {
if (snapshot.data == true) {
buttonText = manageDevicesOtaButton();
iconData = Icons.system_update;
} else {
buttonText = manageDevicesOtaUpToDateButtonLabel();
iconData = Icons.check;
}
} else if (snapshot.hasError) {
buttonText = manageDevicesOtaCheckErrorButtonLabel();
iconData = Icons.error;
} else if (snapshot.connectionState == ConnectionState.active || snapshot.connectionState == ConnectionState.waiting) {
buttonText = manageDevicesOtaCheckInProgressButtonLabel();
}
return FilledButton(
onPressed: (snapshot.connectionState == ConnectionState.active || snapshot.connectionState == ConnectionState.waiting)
? null
: () {
if (snapshot.data == true) {
OtaUpdateRoute(device: widget.device.baseStoredDevice.btMACAddress).push(context);
} else {
setState(() {
_otaAvailable = ref.watch(hasOtaUpdateProvider(widget.device).future);
});
}
},
style: ElevatedButton.styleFrom(
foregroundColor: getTextColor(widget.color),
elevation: 1,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
if (snapshot.connectionState == ConnectionState.active || snapshot.connectionState == ConnectionState.waiting) ...[
CircularProgressIndicator(
color: getTextColor(widget.color),
)
] else ...[
Icon(
iconData,
color: getTextColor(widget.color),
)
],
const Padding(
padding: EdgeInsets.symmetric(horizontal: 4),
),
Text(
buttonText,
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: getTextColor(widget.color),
),
),
],
),
);
},
)
],
);
}
}

class ManageGearConventionMode extends ConsumerWidget {
final BaseStatefulDevice device;

Expand Down Expand Up @@ -301,6 +407,60 @@ class ManageGearConventionMode extends ConsumerWidget {
}
}

class ManageGearAbout extends StatelessWidget {
final BaseStatefulDevice device;
final Color color;

const ManageGearAbout({super.key, required this.device, required this.color});

@override
Widget build(BuildContext context) {
return ExpansionTile(
title: Text(manageDevicesAboutLabel()),
children: [
ListTile(
dense: true,
title: Text(
manageDevicesAboutSoftwareVersionLabel(),
style: Theme.of(context).textTheme.bodyMedium,
),
trailing: ValueListenableBuilder(
valueListenable: device.fwVersion,
builder: (context, value, child) {
return Text(
"${value.major}.${value.minor}.${value.patch}",
);
},
),
),
ListTile(
dense: true,
title: Text(
manageDevicesAboutHardwareVersionLabel(),
style: Theme.of(context).textTheme.bodyMedium,
),
trailing: ValueListenableBuilder(
valueListenable: device.hwVersion,
builder: (context, value, child) {
return Text(
value,
);
},
),
),
OverflowBar(
children: [
ManageGearUpdateCheckButton(
device: device,
color: color,
),
],
)
],
);
}
}

class ManageGearBatteryGraph extends StatelessWidget {
final BaseStatefulDevice device;

Expand Down
14 changes: 14 additions & 0 deletions lib/Frontend/translation_string_definitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ String manageDevicesForget() => Intl.message('Forget', name: 'manageDevicesForge

String manageDevicesOtaButton() => Intl.message('Tap to update firmware', name: 'manageDevicesOtaButton', desc: 'manage devices ota available button');

String manageDevicesOtaCheckButtonLabel() => Intl.message('Check for update', name: 'manageDevicesOtaCheckButtonLabel', desc: 'manage devices button to check if an update is available');

String manageDevicesOtaUpToDateButtonLabel() => Intl.message('Gear is up to date!', name: 'manageDevicesOtaUpToDateButtonLabel', desc: 'manage devices button label if gear is up to date');

String manageDevicesOtaCheckInProgressButtonLabel() => Intl.message('Checking', name: 'manageDevicesOtaCheckInProgressButtonLabel', desc: 'manage devices button label if gear is checking for an update');

String manageDevicesOtaCheckErrorButtonLabel() => Intl.message('Please try again later', name: 'manageDevicesOtaCheckErrorButtonLabel', desc: 'manage devices button label if an error occured while checking for an update');

String manageDevicesAboutLabel() => Intl.message('About your gear', name: 'manageDevicesAboutLabel', desc: 'label for the about your gear section in the manage devices area');

String manageDevicesAboutHardwareVersionLabel() => Intl.message('Hardware Version', name: 'manageDevicesAboutHardwareVersionLabel', desc: 'label for the hardware version on the manage devices page');

String manageDevicesAboutSoftwareVersionLabel() => Intl.message('Software Version', name: 'manageDevicesAboutSoftwareVersionLabel', desc: 'label for the software version on the manage devices page');

String scanDevicesTitle() => Intl.message('Scan For New Gear', name: 'scanDevicesTitle', desc: 'button which opens the scan window');

String scanDevicesFoundTitle() => Intl.message('Found Gear. Tap the gear name to connect', name: 'scanDevicesFoundTitle', desc: 'Title when gear is found on the scan for new gear page');
Expand Down

0 comments on commit d270b1c

Please sign in to comment.