Skip to content

Commit

Permalink
re-organize some known gear helpers and handle unknown battery %
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 22, 2024
1 parent a20320a commit 1259bb5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
46 changes: 46 additions & 0 deletions lib/Frontend/Widgets/known_gear.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:tail_app/Frontend/Widgets/scan_for_new_device.dart';

Expand Down Expand Up @@ -225,4 +226,49 @@ class _KnownGearCardState extends ConsumerState<KnownGearCard> {
),
);
}

Widget getSignal(int rssi) {
if (rssi < -2) {
return const Icon(Icons.signal_cellular_alt);
} else if (rssi <= -45) {
return const Icon(Icons.signal_cellular_alt_2_bar);
} else if (rssi < -65) {
return const Icon(Icons.signal_cellular_alt_1_bar);
} else {
return const Icon(Icons.signal_cellular_connected_no_internet_0_bar);
}
}

Widget getBattery(double level) {
if (SentryHive.box(settings).get(showAccurateBattery, defaultValue: showAccurateBatteryDefault)) {
if (level < 0) {
// battery level is unknown
return const Text('?%');
}
return Text('${level.toInt()}%');
}
if (level < 0) {
return const Icon(Icons.battery_unknown);
}
if (level < 12.5) {
return Flash(infinite: true, child: const Icon(Icons.battery_0_bar));
} else if (level < 25) {
return Flash(
infinite: true,
child: const Icon(Icons.battery_1_bar),
);
} else if (level < 37.5) {
return const Icon(Icons.battery_2_bar);
} else if (level < 50) {
return const Icon(Icons.battery_3_bar);
} else if (level < 62.5) {
return const Icon(Icons.battery_4_bar);
} else if (level < 75) {
return const Icon(Icons.battery_5_bar);
} else if (level < 87.5) {
return const Icon(Icons.battery_6_bar);
} else {
return const Icon(Icons.battery_full);
}
}
}
42 changes: 0 additions & 42 deletions lib/Frontend/pages/shell.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:animate_do/animate_do.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -52,47 +51,6 @@ class NavigationDrawerExample extends ConsumerStatefulWidget {
ConsumerState<NavigationDrawerExample> createState() => _NavigationDrawerExampleState();
}

Widget getSignal(int rssi) {
if (rssi < -2) {
return const Icon(Icons.signal_cellular_alt);
} else if (rssi <= -45) {
return const Icon(Icons.signal_cellular_alt_2_bar);
} else if (rssi < -65) {
return const Icon(Icons.signal_cellular_alt_1_bar);
} else {
return const Icon(Icons.signal_cellular_connected_no_internet_0_bar);
}
}

Widget getBattery(double level) {
if (SentryHive.box(settings).get(showAccurateBattery, defaultValue: showAccurateBatteryDefault)) {
return Text('${level.toInt()}%');
}
if (level < 0) {
return const Icon(Icons.battery_unknown);
}
if (level < 12.5) {
return Flash(infinite: true, child: const Icon(Icons.battery_0_bar));
} else if (level < 25) {
return Flash(
infinite: true,
child: const Icon(Icons.battery_1_bar),
);
} else if (level < 37.5) {
return const Icon(Icons.battery_2_bar);
} else if (level < 50) {
return const Icon(Icons.battery_3_bar);
} else if (level < 62.5) {
return const Icon(Icons.battery_4_bar);
} else if (level < 75) {
return const Icon(Icons.battery_5_bar);
} else if (level < 87.5) {
return const Icon(Icons.battery_6_bar);
} else {
return const Icon(Icons.battery_full);
}
}

class _NavigationDrawerExampleState extends ConsumerState<NavigationDrawerExample> {
int screenIndex = 0;
bool showAppBar = true;
Expand Down

0 comments on commit 1259bb5

Please sign in to comment.