refactor: voice_*-Prefs hinter VoicePrefs-Fassade in settings_prefs (M2 storage-Leitplanke, gleiche Keys/Semantik)
This commit is contained in:
@@ -19,11 +19,6 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
bool _loading = true;
|
||||
String? _loadError;
|
||||
|
||||
static const _kMic = 'voice_mic_device';
|
||||
static const _kSpeaker = 'voice_speaker_device';
|
||||
static const _kCamera = 'voice_camera_device';
|
||||
static const _kOutputVolume = 'voice_output_volume';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -31,7 +26,8 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
}
|
||||
|
||||
Future<void> _init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final devicePrefs = await VoicePrefs.loadDevices();
|
||||
final outputVolume = await VoicePrefs.loadOutputVolume();
|
||||
List<MediaDeviceInfo> devices = [];
|
||||
String? loadError;
|
||||
try {
|
||||
@@ -76,10 +72,10 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
_audioInputs = devices.where((d) => d.kind?.toLowerCase() == 'audioinput').toList();
|
||||
_audioOutputs = devices.where((d) => d.kind?.toLowerCase() == 'audiooutput').toList();
|
||||
_videoInputs = devices.where((d) => d.kind?.toLowerCase() == 'videoinput').toList();
|
||||
_selectedMic = prefs.getString(_kMic);
|
||||
_selectedSpeaker = prefs.getString(_kSpeaker);
|
||||
_selectedCamera = prefs.getString(_kCamera);
|
||||
_outputVolume = prefs.getDouble(_kOutputVolume) ?? 1.0;
|
||||
_selectedMic = devicePrefs.mic;
|
||||
_selectedSpeaker = devicePrefs.speaker;
|
||||
_selectedCamera = devicePrefs.camera;
|
||||
_outputVolume = outputVolume;
|
||||
_loadError = loadError;
|
||||
_loading = false;
|
||||
});
|
||||
@@ -87,8 +83,7 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
|
||||
Future<void> _setOutputVolume(double v) async {
|
||||
setState(() => _outputVolume = v);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setDouble(_kOutputVolume, v);
|
||||
await VoicePrefs.saveOutputVolume(v);
|
||||
// Live auf laufende Calls anwenden (über die Modul-Fassaden).
|
||||
ref.read(voiceChannelProvider).setOutputVolume(v).catchError((_) {});
|
||||
try {
|
||||
@@ -96,15 +91,6 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
} catch (_) {} // Instanz existiert evtl. noch nicht
|
||||
}
|
||||
|
||||
Future<void> _save(String key, String? value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (value == null || value.isEmpty) {
|
||||
await prefs.remove(key);
|
||||
} else {
|
||||
await prefs.setString(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _deviceDropdown({
|
||||
required List<MediaDeviceInfo> devices,
|
||||
required String? selected,
|
||||
@@ -227,7 +213,7 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
icon: Icons.mic_rounded,
|
||||
onChanged: (v) {
|
||||
setState(() => _selectedMic = v);
|
||||
_save(_kMic, v);
|
||||
VoicePrefs.saveMic(v);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -243,7 +229,7 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
icon: Icons.volume_up_rounded,
|
||||
onChanged: (v) {
|
||||
setState(() => _selectedSpeaker = v);
|
||||
_save(_kSpeaker, v);
|
||||
VoicePrefs.saveSpeaker(v);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -259,7 +245,7 @@ class _VoiceSectionState extends ConsumerState<_VoiceSection> {
|
||||
icon: Icons.videocam_rounded,
|
||||
onChanged: (v) {
|
||||
setState(() => _selectedCamera = v);
|
||||
_save(_kCamera, v);
|
||||
VoicePrefs.saveCamera(v);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user