mirror of
https://github.com/spotiflacapp/SpotiFLAC-Mobile.git
synced 2026-05-31 19:05:05 +07:00
83 lines
2.1 KiB
Dart
83 lines
2.1 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:spotiflac_android/models/settings.dart';
|
|
|
|
const _settingsKey = 'app_settings';
|
|
|
|
class SettingsNotifier extends Notifier<AppSettings> {
|
|
@override
|
|
AppSettings build() {
|
|
_loadSettings();
|
|
return const AppSettings();
|
|
}
|
|
|
|
Future<void> _loadSettings() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final json = prefs.getString(_settingsKey);
|
|
if (json != null) {
|
|
state = AppSettings.fromJson(jsonDecode(json));
|
|
}
|
|
}
|
|
|
|
Future<void> _saveSettings() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(_settingsKey, jsonEncode(state.toJson()));
|
|
}
|
|
|
|
void setDefaultService(String service) {
|
|
state = state.copyWith(defaultService: service);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setAudioQuality(String quality) {
|
|
state = state.copyWith(audioQuality: quality);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setFilenameFormat(String format) {
|
|
state = state.copyWith(filenameFormat: format);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setDownloadDirectory(String directory) {
|
|
state = state.copyWith(downloadDirectory: directory);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setAutoFallback(bool enabled) {
|
|
state = state.copyWith(autoFallback: enabled);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setEmbedLyrics(bool enabled) {
|
|
state = state.copyWith(embedLyrics: enabled);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setMaxQualityCover(bool enabled) {
|
|
state = state.copyWith(maxQualityCover: enabled);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setFirstLaunchComplete() {
|
|
state = state.copyWith(isFirstLaunch: false);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setConcurrentDownloads(int count) {
|
|
// Clamp between 1 and 3
|
|
final clamped = count.clamp(1, 3);
|
|
state = state.copyWith(concurrentDownloads: clamped);
|
|
_saveSettings();
|
|
}
|
|
|
|
void setCheckForUpdates(bool enabled) {
|
|
state = state.copyWith(checkForUpdates: enabled);
|
|
_saveSettings();
|
|
}
|
|
}
|
|
|
|
final settingsProvider = NotifierProvider<SettingsNotifier, AppSettings>(
|
|
SettingsNotifier.new,
|
|
);
|