From a1b08b8edccec5341e396160a7c4752fe72d4a0a Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 24 Mar 2023 16:44:42 +0100 Subject: [PATCH] custom dialog --- .../app/fedilab/android/BaseMainActivity.java | 5 ++--- .../settings/FragmentThemingSettings.java | 18 ++++++++++++++---- .../res/layouts/mastodon/values/strings.xml | 7 ------- app/src/main/res/values/strings.xml | 8 ++++++++ colorPicker/build.gradle | 1 + .../android/colorpicker/ColorPickerDialog.java | 6 ++++-- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 2521198a6..57fb34bdf 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -1067,13 +1067,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } catch (DBException e) { e.printStackTrace(); } + //Apply the custom theme if (currentAccount != null && currentInstance == null) { currentInstance = currentAccount.instance; currentUserID = currentAccount.user_id; Handler mainHandler = new Handler(Looper.getMainLooper()); - Runnable myRunnable = () -> { - recreate(); - }; + Runnable myRunnable = this::recreate; mainHandler.post(myRunnable); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentThemingSettings.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentThemingSettings.java index 68effe5f2..262c08734 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentThemingSettings.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentThemingSettings.java @@ -21,7 +21,6 @@ import static app.fedilab.android.BaseMainActivity.currentUserID; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; -import android.util.Log; import androidx.appcompat.app.AlertDialog; import androidx.navigation.NavOptions; @@ -101,8 +100,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements editor.putInt(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_CUSTOM_ACCENT_VALUE.getColor()); } } - Log.v(Helper.TAG, "currentUserID: " + currentUserID); - Log.v(Helper.TAG, "currentInstance: " + currentInstance); editor.apply(); } @@ -115,7 +112,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements if (getPreferenceScreen() == null) { Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); } - + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); SwitchPreferenceCompat SET_DYNAMIC_COLOR = findPreference(getString(R.string.SET_DYNAMICCOLOR)); SwitchPreferenceCompat SET_CUSTOM_ACCENT = findPreference(getString(R.string.SET_CUSTOM_ACCENT)); ColorPreferenceCompat SET_CUSTOM_ACCENT_DARK_VALUE = findPreference(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE)); @@ -133,6 +130,19 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements if (SET_CUSTOM_ACCENT_LIGHT_VALUE != null) { getPreferenceScreen().removePreference(SET_CUSTOM_ACCENT_LIGHT_VALUE); } + } else { + if (SET_CUSTOM_ACCENT != null) { + boolean customAccentEnabled = sharedpreferences.getBoolean(getString(R.string.SET_CUSTOM_ACCENT) + currentUserID + currentInstance, false); + SET_CUSTOM_ACCENT.setChecked(customAccentEnabled); + } + if (SET_CUSTOM_ACCENT_DARK_VALUE != null) { + int darkValue = sharedpreferences.getInt(getString(R.string.SET_CUSTOM_ACCENT_DARK_VALUE) + currentUserID + currentInstance, -1); + SET_CUSTOM_ACCENT_DARK_VALUE.setColor(darkValue); + } + if (SET_CUSTOM_ACCENT_LIGHT_VALUE != null) { + int darkValue = sharedpreferences.getInt(getString(R.string.SET_CUSTOM_ACCENT_LIGHT_VALUE) + currentUserID + currentInstance, -1); + SET_CUSTOM_ACCENT_LIGHT_VALUE.setColor(darkValue); + } } Preference SET_CUSTOMIZE_LIGHT_COLORS_ACTION = findPreference(getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS_ACTION)); diff --git a/app/src/main/res/layouts/mastodon/values/strings.xml b/app/src/main/res/layouts/mastodon/values/strings.xml index d319693c3..78554f9eb 100644 --- a/app/src/main/res/layouts/mastodon/values/strings.xml +++ b/app/src/main/res/layouts/mastodon/values/strings.xml @@ -2,11 +2,4 @@ - Auto - Custom accent color - Define a theme color per account - Light accent color - Dark accent color - Color that will be applied to the light theme - Color that will be applied to the dark theme \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2dc50eb8d..977280dac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1970,4 +1970,12 @@ Select tracks + Auto + Custom accent color + Define a theme color per account + Light accent color + Dark accent color + Color that will be applied to the light theme + Color that will be applied to the dark theme + \ No newline at end of file diff --git a/colorPicker/build.gradle b/colorPicker/build.gradle index 0f3f1c23a..10f4d0d89 100644 --- a/colorPicker/build.gradle +++ b/colorPicker/build.gradle @@ -31,6 +31,7 @@ dependencies { //noinspection GradleCompatible implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'androidx.preference:preference:1.2.0' + implementation 'com.google.android.material:material:1.8.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' diff --git a/colorPicker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java b/colorPicker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java index 7cbac4007..62d7c208d 100644 --- a/colorPicker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java +++ b/colorPicker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java @@ -53,6 +53,8 @@ import androidx.core.graphics.ColorUtils; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentActivity; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import java.util.Arrays; import java.util.Locale; @@ -183,8 +185,8 @@ public class ColorPickerDialog extends DialogFragment implements ColorPickerView if (selectedButtonStringRes == 0) { selectedButtonStringRes = R.string.cpv_select; } - - AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()).setView(rootView) + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()).setView(rootView) + // AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()).setView(rootView) .setPositiveButton(selectedButtonStringRes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {