Skip to content

Commit

Permalink
feat: add Amoled theme #724
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Sep 16, 2023
1 parent 532248b commit 5c5dbf6
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/collections/spotube_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ abstract class SpotubeIcons {
static const user = FeatherIcons.user;
static const edit = FeatherIcons.edit;
static const web = FeatherIcons.globe;
static const amoled = FeatherIcons.sunset;
}
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,6 @@
"connection_restored": "Your internet connection was restored",
"use_system_title_bar": "Use system title bar",
"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"
}
12 changes: 9 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class SpotubeState extends ConsumerState<Spotube> {
ref.watch(userPreferencesProvider.select((s) => s.themeMode));
final accentMaterialColor =
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 paletteColor =
ref.watch(paletteProvider.select((s) => s?.dominantColor?.color));
Expand All @@ -182,12 +184,16 @@ class SpotubeState extends ConsumerState<Spotube> {
useDisableBatteryOptimizations();

final lightTheme = useMemoized(
() => theme(paletteColor ?? accentMaterialColor, Brightness.light),
() => theme(paletteColor ?? accentMaterialColor, Brightness.light, false),
[paletteColor, accentMaterialColor],
);
final darkTheme = useMemoized(
() => theme(paletteColor ?? accentMaterialColor, Brightness.dark),
[paletteColor, accentMaterialColor],
() => theme(
paletteColor ?? accentMaterialColor,
Brightness.dark,
isAmoledTheme,
),
[paletteColor, accentMaterialColor, isAmoledTheme],
);

return MaterialApp.router(
Expand Down
6 changes: 6 additions & 0 deletions lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
leading: const Icon(SpotubeIcons.palette),
title: Text(context.l10n.accent_color),
Expand Down
12 changes: 12 additions & 0 deletions lib/provider/user_preferences_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class UserPreferences extends PersistedChangeNotifier {

bool systemTitleBar;

bool amoledDarkTheme;

final Ref ref;

UserPreferences(
Expand All @@ -89,6 +91,7 @@ class UserPreferences extends PersistedChangeNotifier {
this.skipNonMusic = true,
this.youtubeApiType = YoutubeApiType.youtube,
this.systemTitleBar = false,
this.amoledDarkTheme = false,
}) : super() {
if (downloadLocation.isEmpty && !kIsWeb) {
_getDefaultDownloadDirectory().then(
Expand Down Expand Up @@ -210,6 +213,12 @@ class UserPreferences extends PersistedChangeNotifier {
updatePersistence();
}

void setAmoledDarkTheme(bool isAmoled) {
amoledDarkTheme = isAmoled;
notifyListeners();
updatePersistence();
}

Future<String> _getDefaultDownloadDirectory() async {
if (kIsAndroid) return "/storage/emulated/0/Download/Spotube";

Expand Down Expand Up @@ -274,6 +283,8 @@ class UserPreferences extends PersistedChangeNotifier {
systemTitleBar = map["systemTitleBar"] ?? systemTitleBar;
// updates the title bar
setSystemTitleBar(systemTitleBar);

amoledDarkTheme = map["amoledDarkTheme"] ?? amoledDarkTheme;
}

@override
Expand All @@ -297,6 +308,7 @@ class UserPreferences extends PersistedChangeNotifier {
"skipNonMusic": skipNonMusic,
"youtubeApiType": youtubeApiType.name,
'systemTitleBar': systemTitleBar,
"amoledDarkTheme": amoledDarkTheme,
};
}

Expand Down
8 changes: 6 additions & 2 deletions lib/services/audio_player/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ abstract class AudioPlayerInterface {
final MkPlayerWithState _mkPlayer;
// final ja.AudioPlayer? _justAudio;

AudioPlayerInterface() : _mkPlayer = MkPlayerWithState()
// _mkPlayer = _mkSupportedPlatform ? MkPlayerWithState() : null,
AudioPlayerInterface()
: _mkPlayer = MkPlayerWithState(
configuration: const mk.PlayerConfiguration(
title: "Spotube",
),
)
// _justAudio = !_mkSupportedPlatform ? ja.AudioPlayer() : null
{
_mkPlayer.stream.error.listen((event) {
Expand Down
3 changes: 2 additions & 1 deletion lib/services/audio_player/mk_state_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:catcher/catcher.dart';
import 'package:collection/collection.dart';
import 'package:media_kit/media_kit.dart';
// ignore: implementation_imports
import 'package:media_kit/src/models/playable.dart';
import 'package:spotube/services/audio_player/playback_state.dart';

/// MediaKit [Player] by default doesn't have a state stream.
Expand Down Expand Up @@ -124,7 +123,9 @@ class MkPlayerWithState extends Player {
_loopModeStream.add(playlistMode);
}

@override
Future<void> stop() async {
await super.stop();
await pause();
await seek(Duration.zero);

Expand Down
4 changes: 3 additions & 1 deletion lib/themes/theme.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';

ThemeData theme(Color seed, Brightness brightness) {
ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
final scheme = ColorScheme.fromSeed(
seedColor: seed,
shadow: Colors.black12,
background: isAmoled ? Colors.black : null,
surface: isAmoled ? Colors.black : null,
brightness: brightness,
);
return ThemeData(
Expand Down
46 changes: 45 additions & 1 deletion untranslated_messages.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit 5c5dbf6

Please sign in to comment.