-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(mobile): refactor theme management #14415
Open
dvbthien
wants to merge
26
commits into
immich-app:main
Choose a base branch
from
dvbthien:mobile/refactor-theme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+254
−234
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
83d818a
WIP
e86a53e
split file and refactor theme
b7a828e
remove white row
8aa63cc
clean
13a32c2
Merge branch 'main' of https://github.com/dvbthien/immich into mobile…
4076cf1
rename variable
36c1a33
Merge branch 'main' into mobile/refactor-theme
dvbthien 853391f
add const
6e1e7a9
WIP
eff5576
split file and refactor theme
e1390c3
remove white row
cae3622
clean
27616f8
rename variable
68739c6
add const
9e29c61
Merge branch 'mobile/refactor-theme' of https://github.com/dvbthien/i…
2951297
fix conflict
ea887cb
update code for review
d12d1b4
Revert "add const"
1dda6a0
just refactor theme
32933d2
Merge branch 'main' into mobile/refactor-theme
dvbthien ec9e580
fix conflict
3a5f49b
fix conflict
d9239c6
fix import
273bf2b
Merge branch 'main' into mobile/refactor-theme
dvbthien f6480ca
Merge branch 'main' into mobile/refactor-theme
dvbthien 634b336
Merge branch 'main' into mobile/refactor-theme
dvbthien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
enum ImmichColorPreset { | ||
indigo, | ||
deepPurple, | ||
pink, | ||
red, | ||
orange, | ||
yellow, | ||
lime, | ||
green, | ||
cyan, | ||
slateGray | ||
} | ||
|
||
const ImmichColorPreset defaultColorPreset = ImmichColorPreset.indigo; | ||
const String defaultColorPresetName = "indigo"; | ||
|
||
const Color immichBrandColorLight = Color(0xFF4150AF); | ||
const Color immichBrandColorDark = Color(0xFFACCBFA); | ||
const Color whiteOpacity75 = Color.fromARGB((0.75 * 255) ~/ 1, 255, 255, 255); | ||
const Color red400 = Color(0xFFEF5350); | ||
const Color grey200 = Color(0xFFEEEEEE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
import 'package:immich_mobile/constants/colors.dart'; | ||
import 'package:immich_mobile/theme/color_scheme.dart'; | ||
import 'package:immich_mobile/theme/theme_data.dart'; | ||
import 'package:immich_mobile/theme/dynamic_theme.dart'; | ||
import 'package:immich_mobile/providers/app_settings.provider.dart'; | ||
import 'package:immich_mobile/services/app_settings.service.dart'; | ||
|
||
final immichThemeModeProvider = StateProvider<ThemeMode>((ref) { | ||
final themeMode = ref | ||
.watch(appSettingsServiceProvider) | ||
.getSetting(AppSettingsEnum.themeMode); | ||
|
||
debugPrint("Current themeMode $themeMode"); | ||
|
||
if (themeMode == ThemeMode.light.name) { | ||
return ThemeMode.light; | ||
} else if (themeMode == ThemeMode.dark.name) { | ||
return ThemeMode.dark; | ||
} else { | ||
return ThemeMode.system; | ||
} | ||
}); | ||
|
||
final immichThemePresetProvider = StateProvider<ImmichColorPreset>((ref) { | ||
final appSettingsProvider = ref.watch(appSettingsServiceProvider); | ||
final primaryColorPreset = | ||
appSettingsProvider.getSetting(AppSettingsEnum.primaryColor); | ||
|
||
debugPrint("Current theme preset $primaryColorPreset"); | ||
|
||
try { | ||
return ImmichColorPreset.values | ||
.firstWhere((e) => e.name == primaryColorPreset); | ||
} catch (e) { | ||
debugPrint( | ||
"Theme preset $primaryColorPreset not found. Applying default preset.", | ||
); | ||
appSettingsProvider.setSetting( | ||
AppSettingsEnum.primaryColor, | ||
defaultColorPresetName, | ||
); | ||
return defaultColorPreset; | ||
} | ||
}); | ||
|
||
final dynamicThemeSettingProvider = StateProvider<bool>((ref) { | ||
return ref | ||
.watch(appSettingsServiceProvider) | ||
.getSetting(AppSettingsEnum.dynamicTheme); | ||
}); | ||
|
||
final colorfulInterfaceSettingProvider = StateProvider<bool>((ref) { | ||
return ref | ||
.watch(appSettingsServiceProvider) | ||
.getSetting(AppSettingsEnum.colorfulInterface); | ||
}); | ||
|
||
// Provider for current selected theme | ||
final immichThemeProvider = StateProvider<ImmichTheme>((ref) { | ||
final primaryColorPreset = ref.read(immichThemePresetProvider); | ||
final useSystemColor = ref.watch(dynamicThemeSettingProvider); | ||
final useColorfulInterface = ref.watch(colorfulInterfaceSettingProvider); | ||
final ImmichTheme? dynamicTheme = DynamicTheme.theme; | ||
final currentTheme = (useSystemColor && dynamicTheme != null) | ||
? dynamicTheme | ||
: primaryColorPreset.themeOfPreset; | ||
|
||
return useColorfulInterface | ||
? currentTheme | ||
: decolorizeSurfaces(theme: currentTheme); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:dynamic_color/dynamic_color.dart'; | ||
|
||
import 'package:immich_mobile/theme/theme_data.dart'; | ||
|
||
abstract final class DynamicTheme { | ||
DynamicTheme._(); | ||
|
||
static ImmichTheme? _theme; | ||
// Method to fetch dynamic system colors | ||
static Future<void> fetchSystemPalette() async { | ||
try { | ||
final corePalette = await DynamicColorPlugin.getCorePalette(); | ||
if (corePalette != null) { | ||
final primaryColor = corePalette.toColorScheme().primary; | ||
debugPrint('dynamic_color: Core palette detected.'); | ||
|
||
// Some palettes do not generate surface container colors accurately, | ||
// so we regenerate all colors using the primary color | ||
_theme = ImmichTheme( | ||
light: ColorScheme.fromSeed( | ||
seedColor: primaryColor, | ||
brightness: Brightness.light, | ||
), | ||
dark: ColorScheme.fromSeed( | ||
seedColor: primaryColor, | ||
brightness: Brightness.dark, | ||
), | ||
); | ||
} | ||
} catch (error) { | ||
debugPrint('dynamic_color: Failed to obtain core palette: $error'); | ||
} | ||
} | ||
|
||
static ImmichTheme? get theme => _theme; | ||
static bool get isAvailable => _theme != null; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're working on unifying colours and theme across the app, I'd like the global variables for colours to be removed from the codebase as well. Maybe if not in this PR, Kindly consider this in your upcoming PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shenlong-tanwen,
Thanks for your suggestion. Can you explain it to me in more detail? If you have any ideas for unifying colors and themes across the app, let me know. I'll implement them in upcoming PRs. I just started coding in Flutter, so your ideas will help me a lot.