Skip to content

Commit

Permalink
Initial audio page, allows adding & deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 30, 2024
1 parent 9d8ec4b commit 9f410f9
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 16 deletions.
11 changes: 11 additions & 0 deletions lib/Frontend/go_router_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_hive/sentry_hive.dart';
import 'package:tail_app/Backend/Definitions/Device/device_definition.dart';
import 'package:tail_app/Frontend/pages/action_selector.dart';
import 'package:tail_app/Frontend/pages/custom_audio.dart';
import 'package:tail_app/Frontend/pages/developer/bluetooth_console.dart';
import 'package:tail_app/Frontend/pages/developer/developer_menu.dart';
import 'package:tail_app/Frontend/pages/developer/developer_pincode.dart';
Expand Down Expand Up @@ -157,6 +158,16 @@ final GoRouter router = GoRouter(
return null;
},
),
GoRoute(
name: 'CustomAudio',
path: '/customAudio',
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: (BuildContext context, GoRouterState state) => MaterialPage(
key: state.pageKey,
name: 'CustomAudio',
child: const CustomAudio(),
),
),
GoRoute(
name: 'Sequences',
path: '/moveLists',
Expand Down
29 changes: 13 additions & 16 deletions lib/Frontend/intn_defs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,30 @@ import 'package:intl/intl.dart';
// dart run intl_translation:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/Frontend/intn_defs.dart lib/l10n/*.arb
String title() => Intl.message('The Tail Company', name: 'title', desc: 'The name of the app');

String subTitle() => Intl.message('All of the Tails', name: 'subTitle', desc: 'The sub-title which displays in the navigation drawer');

String homeNewsTitle() => Intl.message('Fresh from the Tail Blog', name: 'homeNewsTitle', desc: 'The title header for the news in the home screen when no gear is connected');

String homeWelcomeMessageTitle() => Intl.message('Welcome to the Tail Company App', name: 'homeWelcomeMessageTitle', desc: 'The welcome message title on the home screen when no gear is connected');

String homeContinuousScanningOffTitle() => Intl.message('Always scanning disabled', name: 'homeContinuousScanningOffTitle', desc: 'The welcome message title on the home screen when no gear is connected');

String homeContinuousScanningOffDescription() =>
Intl.message('Swipe horizontally on the known device area above to begin scanning. You can turn on continuous scanning in settings.', name: 'homeContinuousScanningOffDescription', desc: 'The welcome message title on the home screen when no gear is connected');

String homeWelcomeMessage() => Intl.message('You can control, explore and update all your Tail Co gear right here in this app. There are also instructions and guides available too. Happy Wagging!', name: 'homeWelcomeMessage', desc: 'The welcome message on the home screen when no gear is connected');

String shellDeviceBarToggleLabel() => Intl.message('Toggle Gear Bar', name: 'shellDeviceBarToggleLabel', desc: 'Tooltip for the Gear bar display button on the shell / main UI app bar');

String joyStickPage() => Intl.message('Joystick', name: 'joyStickPage', desc: 'The label and title of the joystick page');

String joyStickPageDescription() => Intl.message('Directly control the gear position.', name: 'joyStickPageDescription', desc: 'The description of the joystick page on the more page');

String feedbackPage() => Intl.message('Send Feedback', name: 'feedbackPage', desc: 'The label and title of the feedback page');

String audioPage() => Intl.message('Custom Sounds', name: 'audioPage', desc: 'The label and title of the custom audio management page');

String aboutPage() => Intl.message('About', name: 'aboutPage', desc: 'The label and title of the about page');

String settingsPage() => Intl.message('Settings', name: 'settingsPage', desc: 'The label and title of the settings page');

String settingsDescription() => Intl.message('Change app color, configure Haptics, and more', name: 'settingsDescription', desc: 'The description of the settings page on the more page');

String actionsPage() => Intl.message('Actions', name: 'actionsPage', desc: 'The label and title of the action page');
//String actionsPage() => Intl.message('Actions', name: 'actionsPage', desc: 'The label and title of the action page');

String homePage() => Intl.message('Actions', name: 'actionsPage', desc: 'The label and title of the action page');

Expand Down Expand Up @@ -158,12 +154,6 @@ String settingsNewsletterToggleSubTitle() => Intl.message('Automatically receive

String settingsAppColor() => Intl.message('App Color', name: 'settingsAppColor', desc: 'Settings page app color picker button title');

String manageDevicesAutoMoveGroupsFast() => Intl.message('Fast', name: 'manageDevicesAutoMoveGroupsFast', desc: 'Auto move group fast option label when managing a device');

String manageDevicesAutoMoveGroupsCalm() => Intl.message('Calm', name: 'manageDevicesAutoMoveGroupsCalm', desc: 'Auto move group calm option label when managing a device');

String manageDevicesAutoMoveGroupsFrustrated() => Intl.message('Frustrated', name: 'manageDevicesAutoMoveGroupsFrustrated', desc: 'Auto move group frustrated option label when managing a device');

String manageDevicesBatteryGraphTitle() => Intl.message('Battery Graph', name: 'manageDevicesBatteryGraphTitle', desc: 'battery graph expansion tile title');

String manageDevicesDisconnect() => Intl.message('Disconnect', name: 'manageDevicesDisconnect', desc: 'manage devices disconnect button title when managing a device');
Expand Down Expand Up @@ -249,8 +239,6 @@ String moreManualResponsibleWaggingTitle() => Intl.message("Responsible Wagging"

String moreManualMiTailTitle() => Intl.message("MiTail Manual", name: 'moreManualMiTailTitle', desc: 'Title for MiTail manual button on More page');

String moreManualDigitailTitle() => Intl.message("DigiTail Manual", name: 'moreManualDigitailTitle', desc: 'Title for Digitail manual button on More page');

String moreManualEargearTitle() => Intl.message("EarGear Manual", name: 'moreManualEargearTitle', desc: 'Title for EarGear manual button on More page');

String moreManualFlutterWingsTitle() => Intl.message("FlutterWings Manual", name: 'moreManualFlutterWingsTitle', desc: 'Title for FlutterWings manual button on More page');
Expand Down Expand Up @@ -320,4 +308,13 @@ String mandatoryOtaRequired() => Intl.message("A firmware update is required for
String actionsFavoriteTip() => Intl.message("Long press an action to favorite", name: 'actionsFavoriteTip', desc: 'tip message which appears when no actions are favorited on the actions page');

String moreSourceCode() => Intl.message("Source Code", name: 'moreSourceCode', desc: 'Label for the github and dev mode button on the more tab');
String audioActionCategory() => Intl.message("Sound", name: 'audioActionCategory', desc: 'Label for sound files');

String audioActionCategory() => Intl.message("Sound Effects", name: 'audioActionCategory', desc: 'Label for sound files');

String audioEditDescription() => Intl.message("Manage custom sound effects", name: 'audioEditDescription', desc: 'Label for sound files');

String audioEdit() => Intl.message("Rename Sound Effect", name: 'audioEdit', desc: 'Label for sound files');

String audioDelete() => Intl.message("Delete Sound Effect", name: 'audioDelete', desc: 'Label for sound files');

String audioAdd() => Intl.message("Add Sound Effect", name: 'audioAdd', desc: 'Label for sound files');
90 changes: 90 additions & 0 deletions lib/Frontend/pages/custom_audio.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';
import 'package:tail_app/Backend/Definitions/Action/base_action.dart';
import 'package:tail_app/Backend/audio.dart';
import 'package:uuid/uuid.dart';

import '../intn_defs.dart';

final Logger _audioLogger = Logger('Audio');

class CustomAudio extends ConsumerStatefulWidget {
const CustomAudio({super.key});

@override
ConsumerState<CustomAudio> createState() => _CustomAudioState();
}

class _CustomAudioState extends ConsumerState<CustomAudio> {
@override
Widget build(BuildContext context) {
List<AudioAction> userAudioActions = ref.watch(userAudioActionsProvider);
return Scaffold(
appBar: AppBar(
title: Text(audioPage()),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () async {
_audioLogger.info("Opening file dialog");
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.audio,
);
if (result != null) {
_audioLogger.info("Selected file");
PlatformFile file = result.files.first;
final Directory appDir = await getApplicationSupportDirectory();
Directory audioDir = Directory("${appDir.path}/audio");
await audioDir.create();
File storedAudioFilePath = File("${audioDir.path}/${file.name}");
_audioLogger.info("File path ${storedAudioFilePath.path}");
File selectedFile = File(file.path!);
_audioLogger.info("Selected file Path ${selectedFile.path}");
Stream<List<int>> openRead = selectedFile.openRead();
IOSink ioSinkWrite = storedAudioFilePath.openWrite();
await ioSinkWrite.addStream(openRead);
ioSinkWrite.close();
_audioLogger.info("Wrote file to app storage");
AudioAction action = AudioAction(name: file.name, uuid: const Uuid().v4(), file: storedAudioFilePath.path);
ref.read(userAudioActionsProvider.notifier).add(action);
}
//Open File Picker
},
icon: const Icon(Icons.add),
label: Text(audioAdd())),
body: ListView.builder(
itemCount: userAudioActions.length,
itemBuilder: (context, index) {
AudioAction audioAction = userAudioActions[index];
return ListTile(
title: Text(audioAction.name),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () {},
tooltip: audioEdit(), //TODO: Edit record name
icon: const Icon(Icons.edit),
),
IconButton(
onPressed: () async {
ref.read(userAudioActionsProvider.notifier).remove(audioAction);
File storedAudioFilePath = File(audioAction.file);
await storedAudioFilePath.delete();
_audioLogger.info("Deleted audio file");
}, //TODO: Show dialog, then delete record and file.
tooltip: audioDelete(),
icon: const Icon(Icons.delete),
)
],
),
);
},
),
);
}
}
8 changes: 8 additions & 0 deletions lib/Frontend/pages/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class _MoreState extends ConsumerState<More> {
context.push('/moveLists');
},
),
ListTile(
title: Text(audioPage()),
subtitle: Text(audioEditDescription()),
leading: const Icon(Icons.audio_file),
onTap: () {
context.push('/customAudio');
},
),
ListTile(
title: Text(settingsPage()),
subtitle: Text(settingsDescription()),
Expand Down

0 comments on commit 9f410f9

Please sign in to comment.