From fb77e541a07423d2341c62a42e47a1691877f009 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Fri, 10 Mar 2023 18:50:15 +0000 Subject: [PATCH] Dynamic colors - Android 12+ (#1257) Closes #1222 Need `Android 12L API 32` if want to test on emulator. Change to Dynamic colors in Settings -> Appearance -> Themes. Co-authored-by: M M Arif Co-authored-by: qwerty287 Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1257 Reviewed-by: qwerty287 --- app/build.gradle | 14 +-- app/src/main/AndroidManifest.xml | 1 + .../mian/gitnex/activities/BaseActivity.java | 3 + .../activities/IssueDetailActivity.java | 18 ++++ .../SettingsAppearanceActivity.java | 8 +- .../gitnex/adapters/IssueCommentsAdapter.java | 60 ++++++++++- .../org/mian/gitnex/core/MainApplication.java | 2 + .../java/org/mian/gitnex/helpers/AppUtil.java | 22 ++++ .../org/mian/gitnex/helpers/Markdown.java | 6 ++ app/src/main/res/layout/activity_main.xml | 2 + .../layout/activity_settings_appearance.xml | 2 +- .../main/res/layout/custom_about_dialog.xml | 100 ++++++++++-------- .../main/res/layout/fragment_repo_info.xml | 4 +- app/src/main/res/values-night/themes.xml | 2 +- app/src/main/res/values-v31/themes.xml | 100 ++++++++++++++++++ app/src/main/res/values/settings.xml | 12 +++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/themes.xml | 7 ++ 18 files changed, 305 insertions(+), 59 deletions(-) create mode 100644 app/src/main/res/values-v31/themes.xml diff --git a/app/build.gradle b/app/build.gradle index 50eee165..389df3aa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,16 +54,16 @@ configurations { } dependencies { - def lifecycle_version = '2.6.0-alpha05' + def lifecycle_version = '2.6.0-rc01' def markwon_version = '4.6.2' - def work_version = "2.7.1" + def work_version = '2.8.0' def acra = '5.9.7' implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.6.0' - implementation 'com.google.android.material:material:1.9.0-alpha01' - implementation 'androidx.compose.material3:material3:1.1.0-alpha05' - implementation 'androidx.compose.material3:material3-window-size-class:1.1.0-alpha05' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0-alpha02' + implementation 'androidx.compose.material3:material3:1.1.0-alpha07' + implementation 'androidx.compose.material3:material3-window-size-class:1.1.0-alpha07' implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "androidx.legacy:legacy-support-v4:1.0.0" @@ -111,7 +111,7 @@ dependencies { coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5" implementation 'androidx.biometric:biometric:1.1.0' implementation 'com.github.chrisvest:stormpot:2.4.2' - implementation 'androidx.browser:browser:1.4.0' + implementation 'androidx.browser:browser:1.5.0' implementation 'com.google.android.flexbox:flexbox:3.0.0' implementation('org.codeberg.gitnex:tea4j-autodeploy:3111bc1b18') { exclude module: 'org.apache.oltu.oauth2.common' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bfa94ba0..dac722f5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,7 @@ android:resizeableActivity="true" android:roundIcon="@mipmap/app_logo_round" android:supportsRtl="true" + android:exported="true" tools:targetApi="n"> = Build.VERSION_CODES.S) { + ImageViewCompat.setImageTintList( + viewBinding.issuePrState, + ColorStateList.valueOf( + ctx.getResources() + .getColor( + android.R.color.system_accent1_300, null))); + } } else { ImageViewCompat.setImageTintList( viewBinding.issuePrState, @@ -765,6 +775,14 @@ public class IssueDetailActivity extends BaseActivity ctx.getResources() .getColor(R.color.retroThemeColorPrimary, null))); } + } else if (tinyDB.getInt("themeId") == 8) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + ImageViewCompat.setImageTintList( + viewBinding.issuePrState, + ColorStateList.valueOf( + ctx.getResources() + .getColor(android.R.color.system_accent1_300, null))); + } } else { ImageViewCompat.setImageTintList( viewBinding.issuePrState, diff --git a/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java b/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java index 9588302e..aaa16ada 100644 --- a/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java @@ -2,6 +2,7 @@ package org.mian.gitnex.activities; import android.app.Dialog; import android.app.TimePickerDialog; +import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.ImageView; @@ -47,7 +48,12 @@ public class SettingsAppearanceActivity extends BaseActivity { LinearLayout darkTimeFrame = activitySettingsAppearanceBinding.darkThemeTimeSelectionFrame; customFontList = getResources().getStringArray(R.array.fonts); - themeList = getResources().getStringArray(R.array.themes); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || "S".equals(Build.VERSION.CODENAME)) { + themeList = getResources().getStringArray(R.array.themesAndroid12); + } else { + themeList = getResources().getStringArray(R.array.themes); + } initCloseListener(); closeActivity.setOnClickListener(onClickListener); diff --git a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java index 7c872b88..974bfa84 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java @@ -1,5 +1,7 @@ package org.mian.gitnex.adapters; +import static org.mian.gitnex.helpers.AppUtil.isNightModeThemeDynamic; + import android.annotation.SuppressLint; import android.content.ClipData; import android.content.ClipboardManager; @@ -550,6 +552,10 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter 0) { start.setText( context.getString( @@ -978,6 +1018,10 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter= Build.VERSION_CODES.S) { + resource = context.getResources().getColor(android.R.color.system_accent1_900, null); + } + return resource; + } } diff --git a/app/src/main/java/org/mian/gitnex/helpers/Markdown.java b/app/src/main/java/org/mian/gitnex/helpers/Markdown.java index 9a62ca0b..19a00728 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/Markdown.java +++ b/app/src/main/java/org/mian/gitnex/helpers/Markdown.java @@ -1,5 +1,7 @@ package org.mian.gitnex.helpers; +import static org.mian.gitnex.helpers.AppUtil.isNightModeThemeDynamic; + import android.content.Context; import android.content.Intent; import android.graphics.Typeface; @@ -366,6 +368,10 @@ public class Markdown { tf = AppUtil.getTypeface(context); } textView.setTypeface(tf); + if (!isNightModeThemeDynamic(context)) { + textView.setTextColor( + AppUtil.dynamicColorResource(context)); + } super.beforeSetText(textView, markdown); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c45abe2b..246e087e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -48,6 +48,8 @@ android:id="@+id/nav_view" app:headerLayout="@layout/nav_header" android:background="?attr/primaryBackgroundColor" + app:itemIconTint="?attr/primaryTextColor" + app:itemTextColor="?attr/primaryTextColor" app:menu="@menu/drawer_menu"/> diff --git a/app/src/main/res/layout/activity_settings_appearance.xml b/app/src/main/res/layout/activity_settings_appearance.xml index 1e54371e..5c2562e1 100644 --- a/app/src/main/res/layout/activity_settings_appearance.xml +++ b/app/src/main/res/layout/activity_settings_appearance.xml @@ -261,7 +261,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/label_title_frame" android:layout_marginStart="@dimen/dimen24dp" - android:layout_marginEnd="@dimen/dimen72dp" + android:layout_marginEnd="@dimen/dimen84dp" android:text="@string/settingsLabelsInListHint" android:textColor="?attr/hintColor" android:textSize="@dimen/dimen12sp" /> diff --git a/app/src/main/res/layout/custom_about_dialog.xml b/app/src/main/res/layout/custom_about_dialog.xml index a19b8918..22993d96 100644 --- a/app/src/main/res/layout/custom_about_dialog.xml +++ b/app/src/main/res/layout/custom_about_dialog.xml @@ -17,7 +17,7 @@ android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_gravity="center" - android:layout_marginTop="12dp" + android:layout_marginTop="@dimen/dimen12dp" android:orientation="vertical" tools:ignore="UselessParent"> @@ -35,7 +35,7 @@ android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:contentDescription="@string/appName" - android:src="@mipmap/app_logo"/> + android:src="@mipmap/app_logo" /> @@ -49,29 +49,43 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" - android:layout_marginTop="5dp" + android:layout_marginTop="@dimen/dimen6dp" android:text="@string/appName" android:textColor="?attr/primaryTextColor" - android:textSize="24sp" - android:textStyle="bold"/> + android:textSize="@dimen/dimen24sp" + android:textStyle="bold" /> - + android:layout_marginTop="@dimen/dimen6dp" + app:cardBackgroundColor="@color/colorWhite" + app:cardCornerRadius="@dimen/dimen36dp"> + + + + @@ -79,23 +93,23 @@ android:id="@+id/userServerVersionHeader" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="24dp" - android:paddingStart="28dp" - android:paddingEnd="28dp" + android:layout_marginTop="@dimen/dimen24dp" + android:paddingStart="@dimen/dimen28dp" + android:paddingEnd="@dimen/dimen28dp" android:text="@string/commitPage" android:textColor="?attr/primaryTextColor" - android:textSize="16sp" - android:textStyle="bold"/> + android:textSize="@dimen/dimen16sp" + android:textStyle="bold" /> + android:textSize="@dimen/dimen14sp" /> @@ -103,37 +117,37 @@ android:id="@+id/supportHeader" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="24dp" - android:paddingStart="28dp" - android:paddingEnd="28dp" + android:layout_marginTop="@dimen/dimen24dp" + android:paddingStart="@dimen/dimen28dp" + android:paddingEnd="@dimen/dimen28dp" android:text="@string/supportText" android:textColor="?attr/primaryTextColor" - android:textSize="16sp" - android:textStyle="bold"/> + android:textSize="@dimen/dimen16sp" + android:textStyle="bold" /> + android:textSize="@dimen/dimen14sp" /> + android:textSize="@dimen/dimen14sp" /> @@ -141,13 +155,13 @@ android:id="@+id/translateHeader" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="24dp" - android:paddingStart="28dp" - android:paddingEnd="28dp" + android:layout_marginTop="@dimen/dimen24dp" + android:paddingStart="@dimen/dimen28dp" + android:paddingEnd="@dimen/dimen28dp" android:text="@string/translateText" android:textColor="?attr/primaryTextColor" - android:textSize="16sp" - android:textStyle="bold"/> + android:textSize="@dimen/dimen16sp" + android:textStyle="bold" /> + android:textSize="@dimen/dimen14sp" + android:visibility="visible" /> @@ -174,8 +188,8 @@ android:layout_margin="@dimen/dimen24dp" android:text="@string/websiteText" android:textColor="@color/btnTextColor" - android:textSize="16sp" - android:textStyle="bold"/> + android:textSize="@dimen/dimen16sp" + android:textStyle="bold" /> diff --git a/app/src/main/res/layout/fragment_repo_info.xml b/app/src/main/res/layout/fragment_repo_info.xml index 19297650..1c95d49d 100644 --- a/app/src/main/res/layout/fragment_repo_info.xml +++ b/app/src/main/res/layout/fragment_repo_info.xml @@ -64,7 +64,7 @@ android:paddingBottom="@dimen/dimen10dp" android:paddingStart="@dimen/dimen0dp" android:paddingEnd="@dimen/dimen0dp" - android:textColor="@color/lightGray"/> + android:textColor="?attr/hintColor"/> + android:textColor="?attr/hintColor"/> - + + + + + + + diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index 7c52b18c..f9d0a164 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -39,6 +39,18 @@ @string/followSystemBlack + + Dark + Light + Auto (Light/Dark) + Retro + Auto (Retro/Dark) + Pitch Black + @string/followSystem + @string/followSystemBlack + @string/dynamicColorsFollowSystem + + @string/navMyRepos @string/pageTitleStarredRepos diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 17f93f0d..a6a3ca18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -766,6 +766,7 @@ %s \u25CF not logged in Follow system (Light/Dark) Follow system (Light/Pitch Black) + Dynamic colors - Follow system (Light/Dark) Fork of: %s Adopt Adopted repository %s diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 7dfc55c8..30dbb06a 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -42,6 +42,7 @@ @color/inputBackground @style/inputsMaterialComponentCorner @style/WindowAnimationTransition + @style/m3SwitchStyle 1 @@ -176,10 +177,15 @@ @color/inputBackground @style/inputsMaterialComponentCorner @style/WindowAnimationTransition + @style/m3SwitchStyle 1 + +