Skip to content

Commit

Permalink
Merge pull request #147 from lamarios/feature/select_theme_option
Browse files Browse the repository at this point in the history
Feature/select theme option
  • Loading branch information
lamarios authored Apr 24, 2023
2 parents 6229830 + 43c771f commit 64c801a
Show file tree
Hide file tree
Showing 10 changed files with 787 additions and 580 deletions.
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/261.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add option to choose app language
Add option to choose app theme
14 changes: 1 addition & 13 deletions fastlane/metadata/android/en-US/full_description.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
<p>
<i>Clipious</i> is an Android client for Invidious, the privacy focused video player.
</p>
<p><b>Features:</b></p>
<ul>
<li>Use own or public server</li>
<li>Subscription management</li>
<li>SponsorBlock</li>
<li>Video view/progress tracking</li>
<li>User playlists</li>
<li>Background playback</li>
<li>Live stream support</li>
</ul>
<p><i>Clipious</i>is an Android client for Invidious, the privacy focused video player.</p><p><b>Features:</b></p><ul><li>Use own or public server</li><li>Subscription management</li><li>SponsorBlock</li><li>Video view/progress tracking</li><li>User playlists</li><li>Background playback</li><li>Live stream support</li></ul>
51 changes: 51 additions & 0 deletions lib/controllers/settingsController.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:get/get.dart';
import 'package:invidious/controllers/homeController.dart';
import 'package:locale_names/locale_names.dart';
import 'package:logging/logging.dart';
import 'package:package_info_plus/package_info_plus.dart';

Expand Down Expand Up @@ -27,6 +30,8 @@ class SettingsController extends GetxController {
bool blackBackground = db.getSettings(BLACK_BACKGROUND)?.value == 'true';
double subtitleSize = double.parse(db.getSettings(SUBTITLE_SIZE)?.value ?? subtitleDefaultSize);
bool skipSslVerification = db.getSettings(SKIP_SSL_VERIFICATION)?.value == 'true';
ThemeMode themeMode = ThemeMode.values.firstWhere((element) => element.name == db.getSettings(THEME_MODE)?.value, orElse: () => ThemeMode.system);
String? locale = db.getSettings(LOCALE)?.value;

@override
onReady() {
Expand Down Expand Up @@ -107,4 +112,50 @@ class SettingsController extends GetxController {
update();
db.saveSetting(SettingsValue(SUBTITLE_SIZE, subtitleSize.toString()));
}

String getThemeLabel(AppLocalizations locals, ThemeMode theme) {
switch (theme) {
case ThemeMode.dark:
return locals.themeDark;
case ThemeMode.light:
return locals.themeLight;
case ThemeMode.system:
return locals.followSystem;
}
}

setThemeMode(ThemeMode? theme) {
if (theme != null) {
themeMode = theme;
db.saveSetting(SettingsValue(THEME_MODE, theme.name));
}
update();
}

setLocale(List<Locale> locals, List<String> localStrings, String? locale) {
if (locale == null) {
db.deleteSetting(LOCALE);
this.locale = null;
} else {
var selectedIndex = localStrings.indexOf(locale);

Locale selectedLocale = locals[selectedIndex];

String toSave = selectedLocale.languageCode;
if (selectedLocale.scriptCode != null) {
toSave += '_${selectedLocale.scriptCode}';
}

this.locale = toSave;
db.saveSetting(SettingsValue(LOCALE, toSave));
}
update();
}

String? getLocaleDisplayName() {
List<String>? localeString = locale?.split('_');
Locale? l = localeString != null ? Locale.fromSubtags(languageCode: localeString[0], scriptCode: localeString.length >= 2 ? localeString[1] : null) : null;

return l?.nativeDisplayLanguageScript;
}
}
2 changes: 2 additions & 0 deletions lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const USE_PROXY = 'use-proxy';
const BLACK_BACKGROUND = 'black-background';
const SUBTITLE_SIZE = 'subtitles-size';
const SKIP_SSL_VERIFICATION = 'skip-ssl-verification';
const THEME_MODE = 'theme-mode';
const LOCALE = 'locale';

const ON_OPEN = "on-open";

Expand Down
Loading

0 comments on commit 64c801a

Please sign in to comment.