mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +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/dialogs.dart';
|
||||||
import 'package:InvenTree/widget/snacks.dart';
|
import 'package:InvenTree/widget/snacks.dart';
|
||||||
import 'package:audioplayers/audio_cache.dart';
|
import 'package:audioplayers/audio_cache.dart';
|
||||||
@ -39,14 +40,24 @@ class BarcodeHandler {
|
|||||||
QRViewController _controller;
|
QRViewController _controller;
|
||||||
BuildContext _context;
|
BuildContext _context;
|
||||||
|
|
||||||
void successTone() {
|
void successTone() async {
|
||||||
AudioCache player = AudioCache();
|
|
||||||
player.play("sounds/barcode_scan.mp3");
|
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 {
|
||||||
AudioCache player = AudioCache();
|
|
||||||
player.play("sounds/barcode_error.mp3");
|
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) {
|
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:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
|
||||||
|
import 'package:InvenTree/app_settings.dart';
|
||||||
|
|
||||||
class InvenTreeAppSettingsWidget extends StatefulWidget {
|
class InvenTreeAppSettingsWidget extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_InvenTreeAppSettingsState createState() => _InvenTreeAppSettingsState();
|
_InvenTreeAppSettingsState createState() => _InvenTreeAppSettingsState();
|
||||||
@ -15,10 +17,43 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
final GlobalKey<_InvenTreeAppSettingsState> _settingsKey = GlobalKey<_InvenTreeAppSettingsState>();
|
final GlobalKey<_InvenTreeAppSettingsState> _settingsKey = GlobalKey<_InvenTreeAppSettingsState>();
|
||||||
|
|
||||||
_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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -33,35 +68,27 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
"Sounds",
|
I18N.of(context).sounds,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
leading: FaIcon(FontAwesomeIcons.volumeUp),
|
leading: FaIcon(FontAwesomeIcons.volumeUp),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text("Server Error"),
|
title: Text(I18N.of(context).serverError),
|
||||||
subtitle: Text("Play audible tone on server error"),
|
subtitle: Text("Play audible tone on server error"),
|
||||||
leading: FaIcon(FontAwesomeIcons.server),
|
leading: FaIcon(FontAwesomeIcons.server),
|
||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: false,
|
value: serverSounds,
|
||||||
onChanged: (value) {
|
onChanged: setServerSounds,
|
||||||
setState(() {
|
|
||||||
// TODO
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text("Barcode Tones"),
|
title: Text(I18N.of(context).barcodeTones),
|
||||||
subtitle: Text("Play audible tones for barcode actions"),
|
subtitle: Text("Play audible tones for barcode actions"),
|
||||||
leading: FaIcon(FontAwesomeIcons.qrcode),
|
leading: FaIcon(FontAwesomeIcons.qrcode),
|
||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: a,
|
value: barcodeSounds,
|
||||||
onChanged: (value) {
|
onChanged: setBarcodeSounds,
|
||||||
setState(() {
|
|
||||||
a = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
Divider(height: 1),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import 'package:InvenTree/app_settings.dart';
|
||||||
import 'package:InvenTree/widget/snacks.dart';
|
import 'package:InvenTree/widget/snacks.dart';
|
||||||
import 'package:audioplayers/audio_cache.dart';
|
import 'package:audioplayers/audio_cache.dart';
|
||||||
import 'package:audioplayers/audioplayers.dart';
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
@ -116,8 +117,12 @@ Future<void> showServerError(String title, String description) async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Play a sound
|
// Play a sound
|
||||||
AudioCache player = AudioCache();
|
final bool tones = await InvenTreeSettingsManager().getValue("serverSounds", true) as bool;
|
||||||
player.play("sounds/server_error.mp3");
|
|
||||||
|
if (tones) {
|
||||||
|
AudioCache player = AudioCache();
|
||||||
|
player.play("sounds/server_error.mp3");
|
||||||
|
}
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
title,
|
title,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user