Skip to content

Commit

Permalink
Wakelock (#189)
Browse files Browse the repository at this point in the history
* Wakelock

* Some renaming

* Some renaming

* And there too
  • Loading branch information
Foxushka authored Sep 1, 2023
1 parent cfc775d commit a8268fa
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 192 deletions.
6 changes: 3 additions & 3 deletions chameleonultragui/lib/gui/component/slot_changer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SlotChangerState extends State<SlotChanger> {
}

Future<List<Icon>> getFutureData() async {
var appState = context.read<MyAppState>();
var appState = context.read<ChameleonGUIState>();
List<(TagType, TagType)> usedSlots;

try {
Expand All @@ -35,7 +35,7 @@ class SlotChangerState extends State<SlotChanger> {
}

Future<List<Icon>> getSlotIcons(List<(TagType, TagType)> usedSlots) async {
var appState = context.read<MyAppState>();
var appState = context.read<ChameleonGUIState>();
List<Icon> icons = [];

try {
Expand Down Expand Up @@ -77,7 +77,7 @@ class SlotChangerState extends State<SlotChanger> {

@override
Widget build(BuildContext context) {
var appState = context.read<MyAppState>();
var appState = context.read<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;
return FutureBuilder(
future: getFutureData(),
Expand Down
23 changes: 11 additions & 12 deletions chameleonultragui/lib/gui/menu/card_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CardEditMenuState extends State<CardEditMenu> {

@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var appState = context.watch<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;
return AlertDialog(
title: Text(localizations.edit_card),
Expand Down Expand Up @@ -78,8 +78,7 @@ class CardEditMenuState extends State<CardEditMenu> {
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(localizations
.pick_color),
title: Text(localizations.pick_color),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: pickerColor,
Expand All @@ -98,19 +97,16 @@ class CardEditMenuState extends State<CardEditMenu> {
pickerColor = Colors.deepOrange);
Navigator.pop(context);
},
child: Text(localizations
.reset_default),
child: Text(localizations.reset_default),
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(localizations
.cancel),
child: Text(localizations.cancel),
),
TextButton(
child: Text(localizations
.ok),
child: Text(localizations.ok),
onPressed: () {
setState(() => currentColor = pickerColor);
Navigator.pop(context);
Expand Down Expand Up @@ -154,7 +150,8 @@ class CardEditMenuState extends State<CardEditMenu> {
TextFormField(
controller: uidController,
decoration: InputDecoration(
labelText: localizations.uid, hintText: localizations.enter_something("UID")),
labelText: localizations.uid,
hintText: localizations.enter_something("UID")),
validator: (value) {
if (value == null || value.isEmpty) {
return localizations.please_enter_something("UID");
Expand All @@ -180,7 +177,8 @@ class CardEditMenuState extends State<CardEditMenu> {
child: TextFormField(
controller: sak4Controller,
decoration: InputDecoration(
labelText: localizations.sak, hintText: localizations.enter_something("SAK")),
labelText: localizations.sak,
hintText: localizations.enter_something("SAK")),
validator: (value) {
if (value == null ||
value.isEmpty &&
Expand All @@ -204,7 +202,8 @@ class CardEditMenuState extends State<CardEditMenu> {
child: TextFormField(
controller: atqa4Controller,
decoration: InputDecoration(
labelText: localizations.atqa, hintText: localizations.enter_something("ATQA")),
labelText: localizations.atqa,
hintText: localizations.enter_something("ATQA")),
validator: (value) {
if (value == null ||
value.isEmpty &&
Expand Down
42 changes: 26 additions & 16 deletions chameleonultragui/lib/gui/menu/chameleon_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
}

Future<AnimationSetting> getAnimationMode() async {
var appState = context.read<MyAppState>();
var appState = context.read<ChameleonGUIState>();

try {
return await appState.communicator!.getAnimationMode();
Expand All @@ -35,7 +35,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
}

Future<ButtonConfig> getButtonConfig(ButtonType type) async {
var appState = context.read<MyAppState>();
var appState = context.read<ChameleonGUIState>();
try {
return await appState.communicator!.getButtonConfig(type);
} catch (_) {
Expand All @@ -44,7 +44,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
}

Future<ButtonConfig> getLongButtonConfig(ButtonType type) async {
var appState = context.read<MyAppState>();
var appState = context.read<ChameleonGUIState>();
try {
return await appState.communicator!.getLongButtonConfig(type);
} catch (_) {
Expand Down Expand Up @@ -72,7 +72,7 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
// ignore_for_file: use_build_context_synchronously
@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var appState = context.watch<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;
return FutureBuilder(
future: getSettingsData(),
Expand All @@ -85,7 +85,8 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
appState.connector.performDisconnect();
return AlertDialog(
title: Text(localizations.device_settings),
content: Text('${localizations.error}: ${snapshot.error.toString()}'));
content: Text(
'${localizations.error}: ${snapshot.error.toString()}'));
} else {
var (
animationMode,
Expand Down Expand Up @@ -136,7 +137,8 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
} catch (e) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
snackBar = SnackBar(
content: Text('${localizations.update_error}: ${e.toString()}'),
content: Text(
'${localizations.update_error}: ${e.toString()}'),
action: SnackBarAction(
label: localizations.close,
onPressed: () {},
Expand Down Expand Up @@ -168,7 +170,11 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
Text("${localizations.animations}:"),
const SizedBox(height: 10),
ToggleButtonsWrapper(
items: [localizations.full, localizations.mini, localizations.none],
items: [
localizations.full,
localizations.mini,
localizations.none
],
selectedValue: animationMode.value,
onChange: (int index) async {
var animation = AnimationSetting.full;
Expand All @@ -187,7 +193,8 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
const SizedBox(height: 10),
Text("${localizations.button_config}:"),
const SizedBox(height: 7),
Text("${localizations.button_x("A")}:", textScaleFactor: 0.8),
Text("${localizations.button_x("A")}:",
textScaleFactor: 0.8),
const SizedBox(height: 7),
ToggleButtonsWrapper(
items: [
Expand All @@ -214,7 +221,8 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
appState.changesMade();
}),
const SizedBox(height: 7),
Text("${localizations.button_x("B")}:", textScaleFactor: 0.8),
Text("${localizations.button_x("B")}:",
textScaleFactor: 0.8),
const SizedBox(height: 7),
ToggleButtonsWrapper(
items: [
Expand Down Expand Up @@ -243,7 +251,8 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
const SizedBox(height: 7),
Text(localizations.long_press, textScaleFactor: 0.9),
const SizedBox(height: 7),
Text("${localizations.button_x("A")}:", textScaleFactor: 0.8),
Text("${localizations.button_x("A")}:",
textScaleFactor: 0.8),
const SizedBox(height: 7),
ToggleButtonsWrapper(
items: [
Expand All @@ -270,7 +279,8 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
appState.changesMade();
}),
const SizedBox(height: 7),
Text("${localizations.button_x("B")}:", textScaleFactor: 0.8),
Text("${localizations.button_x("B")}:",
textScaleFactor: 0.8),
const SizedBox(height: 7),
ToggleButtonsWrapper(
items: [
Expand Down Expand Up @@ -319,22 +329,22 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(localizations.factory_reset),
content: Text(
localizations.factory_sure),
content: Text(localizations.factory_sure),
actions: <Widget>[
TextButton(
onPressed: () async {
await appState.communicator!.factoryReset();
await appState.connector
.performDisconnect();
Navigator.pop(context, localizations.cancel);
Navigator.pop(
context, localizations.cancel);
appState.changesMade();
},
child: Text(localizations.yes),
),
TextButton(
onPressed: () =>
Navigator.pop(context, localizations.cancel),
onPressed: () => Navigator.pop(
context, localizations.cancel),
child: Text(localizations.no),
),
],
Expand Down
3 changes: 1 addition & 2 deletions chameleonultragui/lib/gui/menu/dictionary_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:chameleonultragui/helpers/general.dart';
// Localizations
import 'package:flutter_gen/gen_l10n/app_localizations.dart';


class DictionaryEditMenu extends StatefulWidget {
final Dictionary dict;

Expand Down Expand Up @@ -65,7 +64,7 @@ class DictionaryEditMenuState extends State<DictionaryEditMenu> {

@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var appState = context.watch<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;
return AlertDialog(
title: Text(localizations.edit_dictionary),
Expand Down
28 changes: 19 additions & 9 deletions chameleonultragui/lib/gui/menu/slot_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SlotSettingsState extends State<SlotSettings> {
}

Future<void> fetchInfo() async {
var appState = context.read<MyAppState>();
var appState = context.read<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;
if (hfName.isEmpty) {
try {
Expand Down Expand Up @@ -86,7 +86,7 @@ class SlotSettingsState extends State<SlotSettings> {

@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var appState = context.watch<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;

return FutureBuilder(
Expand All @@ -101,7 +101,8 @@ class SlotSettingsState extends State<SlotSettings> {
appState.connector.performDisconnect();
return AlertDialog(
title: Text(localizations.slot_settings),
content: Text('${localizations.error}: ${snapshot.error.toString()}'));
content: Text(
'${localizations.error}: ${snapshot.error.toString()}'));
} else {
return AlertDialog(
title: Text(localizations.slot_settings),
Expand All @@ -122,7 +123,9 @@ class SlotSettingsState extends State<SlotSettings> {
await appState.communicator!
.deleteSlotInfo(widget.slot, TagFrequency.hf);
await appState.communicator!.setSlotTagName(
widget.slot, localizations.empty, TagFrequency.hf);
widget.slot,
localizations.empty,
TagFrequency.hf);
await appState.communicator!.saveSlotData();

setState(() {
Expand Down Expand Up @@ -151,7 +154,9 @@ class SlotSettingsState extends State<SlotSettings> {
await appState.communicator!
.deleteSlotInfo(widget.slot, TagFrequency.lf);
await appState.communicator!.setSlotTagName(
widget.slot, localizations.empty, TagFrequency.lf);
widget.slot,
localizations.empty,
TagFrequency.lf);
await appState.communicator!.saveSlotData();

setState(() {
Expand Down Expand Up @@ -238,8 +243,7 @@ class SlotSettingsState extends State<SlotSettings> {
...(detectionCount == 0)
? [
const SizedBox(height: 8),
Text(
localizations.present_cham_reader_keys,
Text(localizations.present_cham_reader_keys,
textScaleFactor: 0.8)
]
: [
Expand All @@ -257,7 +261,8 @@ class SlotSettingsState extends State<SlotSettings> {
child: Row(
children: [
const Icon(Icons.lock_open),
Text(localizations.recover_keys),
Text(
localizations.recover_keys),
],
)),
]),
Expand All @@ -272,7 +277,12 @@ class SlotSettingsState extends State<SlotSettings> {
Text(localizations.write_mode),
const SizedBox(height: 8),
ToggleButtonsWrapper(
items: [localizations.normal, localizations.decline, localizations.deceive, localizations.shadow],
items: [
localizations.normal,
localizations.decline,
localizations.deceive,
localizations.shadow
],
selectedValue: writeMode.value,
onChange: (int index) async {
await appState.communicator!.activateSlot(widget.slot);
Expand Down
2 changes: 1 addition & 1 deletion chameleonultragui/lib/gui/page/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConnectPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>(); // Get State
var appState = context.watch<ChameleonGUIState>(); // Get State
var localizations = AppLocalizations.of(context)!;
return FutureBuilder(
future:
Expand Down
3 changes: 1 addition & 2 deletions chameleonultragui/lib/gui/page/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DebugPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>(); // Get State
var appState = context.watch<ChameleonGUIState>(); // Get State
var localizations = AppLocalizations.of(context)!;
return Center(
child: Column(
Expand All @@ -47,7 +47,6 @@ class DebugPage extends StatelessWidget {
),
Text('⚠️ ${localizations.warned} ⚠️', textScaleFactor: 3),
Text('${localizations.platform}: ${Platform.operatingSystem}'),
Text('${localizations.android}: ${appState.onAndroid}'),
Text('${localizations.serial_protocol}: ${appState.connector}'),
Text(
'${localizations.chameleon_connected}: ${appState.connector.connected}'),
Expand Down
2 changes: 1 addition & 1 deletion chameleonultragui/lib/gui/page/flashing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FlashingPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var appState = context.watch<ChameleonGUIState>();
var localizations = AppLocalizations.of(context)!;
return Scaffold(
appBar: AppBar(
Expand Down
Loading

0 comments on commit a8268fa

Please sign in to comment.