-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added Support for System Wide Dark Theme #3460
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aeed7cc
Added Support for System Wide Dark Theme
madhurgupta10 f1162e2
changed methods to private
madhurgupta10 b5114d2
Moved Strings to strings.xml
madhurgupta10 1fd47e8
Used Dagger to reduce code repetition
madhurgupta10 479a51c
Changes made as per review suggestions
madhurgupta10 568448a
Minor Changes
madhurgupta10 e0371ee
Fixes as per suggestions
madhurgupta10 492a336
Minor Fixes as per suggestion
madhurgupta10 8a99f77
made the variables static
madhurgupta10 e7e820e
removed irrelevant code
madhurgupta10 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
49 changes: 49 additions & 0 deletions
49
app/src/main/java/fr/free/nrw/commons/utils/SystemThemeUtils.java
This file contains hidden or 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,49 @@ | ||
| package fr.free.nrw.commons.utils; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.res.Configuration; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.inject.Named; | ||
|
|
||
| import fr.free.nrw.commons.kvstore.JsonKvStore; | ||
| import fr.free.nrw.commons.settings.Prefs; | ||
|
|
||
| public class SystemThemeUtils { | ||
|
|
||
| private Context context; | ||
| private JsonKvStore applicationKvStore; | ||
|
|
||
| public static final String THEME_MODE_DEFAULT = "0"; | ||
| public static final String THEME_MODE_DARK = "1"; | ||
| public static final String THEME_MODE_LIGHT = "2"; | ||
|
|
||
| @Inject | ||
| public SystemThemeUtils(Context context, @Named("default_preferences") JsonKvStore applicationKvStore) { | ||
| this.context = context; | ||
| this.applicationKvStore = applicationKvStore; | ||
| } | ||
|
|
||
| // Return true is system wide dark theme is enabled else false | ||
| public boolean getSystemDefaultThemeBool(String theme) { | ||
| if (theme.equals(THEME_MODE_DARK)) { | ||
| return true; | ||
| } else if (theme.equals(THEME_MODE_DEFAULT)) { | ||
| return getSystemDefaultThemeBool(getSystemDefaultTheme()); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // Returns the default system wide theme | ||
| public String getSystemDefaultTheme() { | ||
| return (context.getResources().getConfiguration().uiMode & | ||
| Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES ? THEME_MODE_DARK : THEME_MODE_LIGHT; | ||
| } | ||
|
|
||
| // Returns true if the device is in night mode or false otherwise | ||
| public boolean isDeviceInNightMode() { | ||
| return getSystemDefaultThemeBool( | ||
| applicationKvStore.getString(Prefs.KEY_THEME_VALUE, getSystemDefaultTheme())); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.