Skip to content

Commit

Permalink
feat: add restore default settings button
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Sep 27, 2023
1 parent 101c325 commit 94c3866
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 27 deletions.
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,6 @@
"use_amoled_dark_theme": "Use AMOLED (Pitch Black) dark theme",
"normalize_audio": "Normalize audio",
"change_cover": "Change cover",
"add_cover": "Add cover"
"add_cover": "Add cover",
"restore_defaults": "Restore defaults"
}
9 changes: 8 additions & 1 deletion lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SettingsPage extends HookConsumerWidget {

@override
Widget build(BuildContext context, ref) {
final UserPreferences preferences = ref.watch(userPreferencesProvider);
final preferences = ref.watch(userPreferencesProvider);
final auth = ref.watch(AuthenticationNotifier.provider);
final theme = Theme.of(context);
final mediaQuery = MediaQuery.of(context);
Expand Down Expand Up @@ -602,6 +602,13 @@ class SettingsPage extends HookConsumerWidget {
)
],
),
Center(
child: FilledButton(
onPressed: preferences.reset,
child: Text(context.l10n.restore_defaults),
),
),
const SizedBox(height: 10),
],
),
),
Expand Down
42 changes: 30 additions & 12 deletions lib/provider/user_preferences_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class UserPreferences extends PersistedChangeNotifier {
bool checkUpdate;
AudioQuality audioQuality;

SpotubeColor accentColorScheme;
late SpotubeColor accentColorScheme;
bool albumColorSync;

String downloadLocation;
Expand Down Expand Up @@ -78,10 +78,9 @@ class UserPreferences extends PersistedChangeNotifier {

UserPreferences(
this.ref, {
required this.recommendationMarket,
required this.themeMode,
required this.layoutMode,
required this.accentColorScheme,
this.recommendationMarket = Market.US,
this.themeMode = ThemeMode.system,
this.layoutMode = LayoutMode.adaptive,
this.albumColorSync = true,
this.saveTrackLyrics = false,
this.checkUpdate = true,
Expand All @@ -97,7 +96,10 @@ class UserPreferences extends PersistedChangeNotifier {
this.systemTitleBar = false,
this.amoledDarkTheme = false,
this.normalizeAudio = true,
SpotubeColor? accentColorScheme,
}) : super() {
this.accentColorScheme =
accentColorScheme ?? SpotubeColor(Colors.blue.value, name: "Blue");
if (downloadLocation.isEmpty && !kIsWeb) {
_getDefaultDownloadDirectory().then(
(value) {
Expand All @@ -107,6 +109,28 @@ class UserPreferences extends PersistedChangeNotifier {
}
}

void reset() {
setRecommendationMarket(Market.US);
setThemeMode(ThemeMode.system);
setLayoutMode(LayoutMode.adaptive);
setAlbumColorSync(true);
setSaveTrackLyrics(false);
setCheckUpdate(true);
setAudioQuality(AudioQuality.high);
setDownloadLocation("");
setCloseBehavior(CloseBehavior.close);
setShowSystemTrayIcon(true);
setLocale(const Locale("system", "system"));
setPipedInstance("https://pipedapi.kavin.rocks");
setSearchMode(SearchMode.youtube);
setSkipNonMusic(true);
setYoutubeApiType(YoutubeApiType.youtube);
setSystemTitleBar(false);
setAmoledDarkTheme(false);
setNormalizeAudio(true);
setAccentColorScheme(SpotubeColor(Colors.blue.value, name: "Blue"));
}

void setThemeMode(ThemeMode mode) {
themeMode = mode;
notifyListeners();
Expand Down Expand Up @@ -372,11 +396,5 @@ class UserPreferences extends PersistedChangeNotifier {
}

final userPreferencesProvider = ChangeNotifierProvider(
(ref) => UserPreferences(
ref,
accentColorScheme: SpotubeColor(Colors.blue.value, name: "Blue"),
recommendationMarket: Market.US,
themeMode: ThemeMode.system,
layoutMode: LayoutMode.adaptive,
),
(ref) => UserPreferences(ref),
);
39 changes: 26 additions & 13 deletions untranslated_messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,103 @@
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"bn": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"ca": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"de": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"es": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"fr": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"hi": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"ja": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"pl": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"pt": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"ru": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"uk": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
],

"zh": [
"use_amoled_dark_theme",
"normalize_audio",
"change_cover",
"add_cover"
"add_cover",
"restore_defaults"
]
}

0 comments on commit 94c3866

Please sign in to comment.