Skip to content
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

#16 Add dark mode #26

Merged
merged 15 commits into from
Sep 3, 2024
Merged

#16 Add dark mode #26

merged 15 commits into from
Sep 3, 2024

Conversation

deifyed
Copy link
Contributor

@deifyed deifyed commented Dec 5, 2023

privacy

This PR closes #16 by implementing theme switching functionality and a dark theme based on native Android dark mode colors. Images should still be updated to fit the dark background.

Let me know if I missed something and I'll sort it out. I'm not an Android developer, so I apologize for any silly mistakes.

@@ -40,6 +42,7 @@ public class AboutActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(GetThemeRes(getApplicationContext()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik, we need to set the theme per activity

else
setColor(context.getResources().getColor(R.color.button_empty_2));

setColor(GetColorRes(context, R.attr.buttonEmpty));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference in colors are now handled by the ThemeResolver file

setContentView(R.layout.activity_settings);

//setupActionBar();

overridePendingTransition(0, 0);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to have an instant change in themes when selecting it in the menu

import org.secuso.privacyfriendly2048.R

@StyleRes
fun GetThemeRes(ctx: Context): Int {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns the correct style depending on preferences/settings

}

@ColorRes
fun GetColorRes(ctx: Context, res: Int): Int {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns the correct color depending on the color scheme chosen through preferences/settings

}

@ColorInt
fun GetColorInt(ctx: Context, res: Int): Int {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setTextColor requires an actual color instead of a reference like the GetColorRes function. Somehow it works if I just cast the reference to an int

# Conflicts:
#	app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
@udenr udenr self-requested a review September 2, 2024 14:58
- Check preferences in `PF2048.kt` once instead of in every activity
- Use AppCompatDelegate to set the theme
- Fix the warning/error `View class org.secuso.privacyfriendly2048.activities.Element is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant).` by switching from the applicationContext to the activity
@udenr
Copy link
Contributor

udenr commented Sep 2, 2024

Thank you for the work you've put into this pull request. I wanted to look into it quite some time ago, but had other things to do and forgot about it.
I looked at your changes now, merged the current main branch and made some additional small changes.
I'll have another look at it this week if something broke due to these changes, and then we'll work on releasing an update with these changes.
And thanks for your comments - that made understanding it a lot easier.

@deifyed
Copy link
Contributor Author

deifyed commented Sep 3, 2024

My pleasure! It should definitely be well tested. Let me know if you need/want me to do some testing

@udenr udenr merged commit 5f90011 into SecUSo:master Sep 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dark theme
2 participants