2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Add settings to control sounds

This commit is contained in:
Oliver Walters 2021-03-03 21:39:46 +11:00
parent 194be50337
commit 989e0e81b3
4 changed files with 106 additions and 25 deletions

38
lib/app_settings.dart Normal file
View File

@ -0,0 +1,38 @@
/*
* Class for managing app-level configuration options
*/
import 'package:sembast/sembast.dart';
import 'package:InvenTree/preferences.dart';
class InvenTreeSettingsManager {
final store = StoreRef("settings");
Future<Database> get _db async => await InvenTreePreferencesDB.instance.database;
Future<dynamic> getValue(String key, dynamic backup) async {
final value = await store.record(key).get(await _db);
if (value == null) {
return backup;
}
return value;
}
Future<void> setValue(String key, dynamic value) async {
await store.record(key).put(await _db, value);
}
// Ensure we only ever create a single instance of this class
static final InvenTreeSettingsManager _manager = new InvenTreeSettingsManager._internal();
factory InvenTreeSettingsManager() {
return _manager;
}
InvenTreeSettingsManager._internal();
}

View File

@ -1,3 +1,4 @@
import 'package:InvenTree/app_settings.dart';
import 'package:InvenTree/widget/dialogs.dart';
import 'package:InvenTree/widget/snacks.dart';
import 'package:audioplayers/audio_cache.dart';
@ -39,15 +40,25 @@ class BarcodeHandler {
QRViewController _controller;
BuildContext _context;
void successTone() {
void successTone() async {
final bool en = await InvenTreeSettingsManager().getValue("barcodeSounds", true) as bool;
if (en) {
AudioCache player = AudioCache();
player.play("sounds/barcode_scan.mp3");
}
}
void failureTone() {
void failureTone() async {
final bool en = await InvenTreeSettingsManager().getValue("barcodeSounds", true) as bool;
if (en) {
AudioCache player = AudioCache();
player.play("sounds/barcode_error.mp3");
}
}
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
// Called when the server "matches" a barcode

View File

@ -5,6 +5,8 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:InvenTree/app_settings.dart';
class InvenTreeAppSettingsWidget extends StatefulWidget {
@override
_InvenTreeAppSettingsState createState() => _InvenTreeAppSettingsState();
@ -15,10 +17,43 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
final GlobalKey<_InvenTreeAppSettingsState> _settingsKey = GlobalKey<_InvenTreeAppSettingsState>();
_InvenTreeAppSettingsState() {
}
bool a = false;
bool barcodeSounds = true;
bool serverSounds = true;
@override
void initState() {
super.initState();
loadSettings();
}
void loadSettings() async {
barcodeSounds = await InvenTreeSettingsManager().getValue("barcodeSounds", true) as bool;
serverSounds = await InvenTreeSettingsManager().getValue("serverSounds", true) as bool;
setState(() {
});
}
void setBarcodeSounds(bool en) async {
await InvenTreeSettingsManager().setValue("barcodeSounds", en);
barcodeSounds = await InvenTreeSettingsManager().getValue("barcodeSounds", true);
setState(() {
});
}
void setServerSounds(bool en) async {
await InvenTreeSettingsManager().setValue("serverSounds", en);
serverSounds = await InvenTreeSettingsManager().getValue("serverSounds", true);
setState(() {
});
}
@override
Widget build(BuildContext context) {
@ -33,35 +68,27 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
children: [
ListTile(
title: Text(
"Sounds",
I18N.of(context).sounds,
style: TextStyle(fontWeight: FontWeight.bold),
),
leading: FaIcon(FontAwesomeIcons.volumeUp),
),
ListTile(
title: Text("Server Error"),
title: Text(I18N.of(context).serverError),
subtitle: Text("Play audible tone on server error"),
leading: FaIcon(FontAwesomeIcons.server),
trailing: Switch(
value: false,
onChanged: (value) {
setState(() {
// TODO
});
},
value: serverSounds,
onChanged: setServerSounds,
),
),
ListTile(
title: Text("Barcode Tones"),
title: Text(I18N.of(context).barcodeTones),
subtitle: Text("Play audible tones for barcode actions"),
leading: FaIcon(FontAwesomeIcons.qrcode),
trailing: Switch(
value: a,
onChanged: (value) {
setState(() {
a = value;
});
},
value: barcodeSounds,
onChanged: setBarcodeSounds,
),
),
Divider(height: 1),

View File

@ -1,4 +1,5 @@
import 'package:InvenTree/app_settings.dart';
import 'package:InvenTree/widget/snacks.dart';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
@ -116,8 +117,12 @@ Future<void> showServerError(String title, String description) async {
}
// Play a sound
final bool tones = await InvenTreeSettingsManager().getValue("serverSounds", true) as bool;
if (tones) {
AudioCache player = AudioCache();
player.play("sounds/server_error.mp3");
}
showSnackIcon(
title,