feat: add Amoled theme #724

This commit is contained in:
Kingkor Roy Tirtho 2023-09-16 12:35:46 +06:00
parent 532248b55d
commit 5c5dbf69ec
9 changed files with 86 additions and 9 deletions

View File

@ -97,4 +97,5 @@ abstract class SpotubeIcons {
static const user = FeatherIcons.user; static const user = FeatherIcons.user;
static const edit = FeatherIcons.edit; static const edit = FeatherIcons.edit;
static const web = FeatherIcons.globe; static const web = FeatherIcons.globe;
static const amoled = FeatherIcons.sunset;
} }

View File

@ -263,5 +263,6 @@
"connection_restored": "Your internet connection was restored", "connection_restored": "Your internet connection was restored",
"use_system_title_bar": "Use system title bar", "use_system_title_bar": "Use system title bar",
"crunching_results": "Crunching results...", "crunching_results": "Crunching results...",
"search_to_get_results": "Search to get results" "search_to_get_results": "Search to get results",
"use_amoled_dark_theme": "Use AMOLED (Pitch Black) dark theme"
} }

View File

@ -163,6 +163,8 @@ class SpotubeState extends ConsumerState<Spotube> {
ref.watch(userPreferencesProvider.select((s) => s.themeMode)); ref.watch(userPreferencesProvider.select((s) => s.themeMode));
final accentMaterialColor = final accentMaterialColor =
ref.watch(userPreferencesProvider.select((s) => s.accentColorScheme)); ref.watch(userPreferencesProvider.select((s) => s.accentColorScheme));
final isAmoledTheme =
ref.watch(userPreferencesProvider.select((s) => s.amoledDarkTheme));
final locale = ref.watch(userPreferencesProvider.select((s) => s.locale)); final locale = ref.watch(userPreferencesProvider.select((s) => s.locale));
final paletteColor = final paletteColor =
ref.watch(paletteProvider.select((s) => s?.dominantColor?.color)); ref.watch(paletteProvider.select((s) => s?.dominantColor?.color));
@ -182,12 +184,16 @@ class SpotubeState extends ConsumerState<Spotube> {
useDisableBatteryOptimizations(); useDisableBatteryOptimizations();
final lightTheme = useMemoized( final lightTheme = useMemoized(
() => theme(paletteColor ?? accentMaterialColor, Brightness.light), () => theme(paletteColor ?? accentMaterialColor, Brightness.light, false),
[paletteColor, accentMaterialColor], [paletteColor, accentMaterialColor],
); );
final darkTheme = useMemoized( final darkTheme = useMemoized(
() => theme(paletteColor ?? accentMaterialColor, Brightness.dark), () => theme(
[paletteColor, accentMaterialColor], paletteColor ?? accentMaterialColor,
Brightness.dark,
isAmoledTheme,
),
[paletteColor, accentMaterialColor, isAmoledTheme],
); );
return MaterialApp.router( return MaterialApp.router(

View File

@ -253,6 +253,12 @@ class SettingsPage extends HookConsumerWidget {
} }
}, },
), ),
SwitchListTile(
secondary: const Icon(SpotubeIcons.amoled),
title: Text(context.l10n.use_amoled_dark_theme),
value: preferences.amoledDarkTheme,
onChanged: preferences.setAmoledDarkTheme,
),
ListTile( ListTile(
leading: const Icon(SpotubeIcons.palette), leading: const Icon(SpotubeIcons.palette),
title: Text(context.l10n.accent_color), title: Text(context.l10n.accent_color),

View File

@ -68,6 +68,8 @@ class UserPreferences extends PersistedChangeNotifier {
bool systemTitleBar; bool systemTitleBar;
bool amoledDarkTheme;
final Ref ref; final Ref ref;
UserPreferences( UserPreferences(
@ -89,6 +91,7 @@ class UserPreferences extends PersistedChangeNotifier {
this.skipNonMusic = true, this.skipNonMusic = true,
this.youtubeApiType = YoutubeApiType.youtube, this.youtubeApiType = YoutubeApiType.youtube,
this.systemTitleBar = false, this.systemTitleBar = false,
this.amoledDarkTheme = false,
}) : super() { }) : super() {
if (downloadLocation.isEmpty && !kIsWeb) { if (downloadLocation.isEmpty && !kIsWeb) {
_getDefaultDownloadDirectory().then( _getDefaultDownloadDirectory().then(
@ -210,6 +213,12 @@ class UserPreferences extends PersistedChangeNotifier {
updatePersistence(); updatePersistence();
} }
void setAmoledDarkTheme(bool isAmoled) {
amoledDarkTheme = isAmoled;
notifyListeners();
updatePersistence();
}
Future<String> _getDefaultDownloadDirectory() async { Future<String> _getDefaultDownloadDirectory() async {
if (kIsAndroid) return "/storage/emulated/0/Download/Spotube"; if (kIsAndroid) return "/storage/emulated/0/Download/Spotube";
@ -274,6 +283,8 @@ class UserPreferences extends PersistedChangeNotifier {
systemTitleBar = map["systemTitleBar"] ?? systemTitleBar; systemTitleBar = map["systemTitleBar"] ?? systemTitleBar;
// updates the title bar // updates the title bar
setSystemTitleBar(systemTitleBar); setSystemTitleBar(systemTitleBar);
amoledDarkTheme = map["amoledDarkTheme"] ?? amoledDarkTheme;
} }
@override @override
@ -297,6 +308,7 @@ class UserPreferences extends PersistedChangeNotifier {
"skipNonMusic": skipNonMusic, "skipNonMusic": skipNonMusic,
"youtubeApiType": youtubeApiType.name, "youtubeApiType": youtubeApiType.name,
'systemTitleBar': systemTitleBar, 'systemTitleBar': systemTitleBar,
"amoledDarkTheme": amoledDarkTheme,
}; };
} }

View File

@ -16,8 +16,12 @@ abstract class AudioPlayerInterface {
final MkPlayerWithState _mkPlayer; final MkPlayerWithState _mkPlayer;
// final ja.AudioPlayer? _justAudio; // final ja.AudioPlayer? _justAudio;
AudioPlayerInterface() : _mkPlayer = MkPlayerWithState() AudioPlayerInterface()
// _mkPlayer = _mkSupportedPlatform ? MkPlayerWithState() : null, : _mkPlayer = MkPlayerWithState(
configuration: const mk.PlayerConfiguration(
title: "Spotube",
),
)
// _justAudio = !_mkSupportedPlatform ? ja.AudioPlayer() : null // _justAudio = !_mkSupportedPlatform ? ja.AudioPlayer() : null
{ {
_mkPlayer.stream.error.listen((event) { _mkPlayer.stream.error.listen((event) {

View File

@ -4,7 +4,6 @@ import 'package:catcher/catcher.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:media_kit/media_kit.dart'; import 'package:media_kit/media_kit.dart';
// ignore: implementation_imports // ignore: implementation_imports
import 'package:media_kit/src/models/playable.dart';
import 'package:spotube/services/audio_player/playback_state.dart'; import 'package:spotube/services/audio_player/playback_state.dart';
/// MediaKit [Player] by default doesn't have a state stream. /// MediaKit [Player] by default doesn't have a state stream.
@ -124,7 +123,9 @@ class MkPlayerWithState extends Player {
_loopModeStream.add(playlistMode); _loopModeStream.add(playlistMode);
} }
@override
Future<void> stop() async { Future<void> stop() async {
await super.stop();
await pause(); await pause();
await seek(Duration.zero); await seek(Duration.zero);

View File

@ -1,9 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
ThemeData theme(Color seed, Brightness brightness) { ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
final scheme = ColorScheme.fromSeed( final scheme = ColorScheme.fromSeed(
seedColor: seed, seedColor: seed,
shadow: Colors.black12, shadow: Colors.black12,
background: isAmoled ? Colors.black : null,
surface: isAmoled ? Colors.black : null,
brightness: brightness, brightness: brightness,
); );
return ThemeData( return ThemeData(

View File

@ -1 +1,45 @@
{} {
"bn": [
"use_amoled_dark_theme"
],
"ca": [
"use_amoled_dark_theme"
],
"de": [
"use_amoled_dark_theme"
],
"es": [
"use_amoled_dark_theme"
],
"fr": [
"use_amoled_dark_theme"
],
"hi": [
"use_amoled_dark_theme"
],
"ja": [
"use_amoled_dark_theme"
],
"pl": [
"use_amoled_dark_theme"
],
"pt": [
"use_amoled_dark_theme"
],
"ru": [
"use_amoled_dark_theme"
],
"zh": [
"use_amoled_dark_theme"
]
}