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:
parent
194be50337
commit
989e0e81b3
38
lib/app_settings.dart
Normal file
38
lib/app_settings.dart
Normal 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();
|
||||
}
|
@ -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,14 +40,24 @@ class BarcodeHandler {
|
||||
QRViewController _controller;
|
||||
BuildContext _context;
|
||||
|
||||
void successTone() {
|
||||
AudioCache player = AudioCache();
|
||||
player.play("sounds/barcode_scan.mp3");
|
||||
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() {
|
||||
AudioCache player = AudioCache();
|
||||
player.play("sounds/barcode_error.mp3");
|
||||
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) {
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
AudioCache player = AudioCache();
|
||||
player.play("sounds/server_error.mp3");
|
||||
final bool tones = await InvenTreeSettingsManager().getValue("serverSounds", true) as bool;
|
||||
|
||||
if (tones) {
|
||||
AudioCache player = AudioCache();
|
||||
player.play("sounds/server_error.mp3");
|
||||
}
|
||||
|
||||
showSnackIcon(
|
||||
title,
|
||||
|
Loading…
x
Reference in New Issue
Block a user