summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2023-03-24 16:44:42 +0100
committerThomas <tschneider.ac@gmail.com>2023-03-24 16:44:42 +0100
commita1b08b8edccec5341e396160a7c4752fe72d4a0a (patch)
treeb7d245fe1c6d83ed8576f9086ab37c713df2ff21
parentfdbb3b04f3fd27eb60eaecdf49d2f7adc8f698e9 (diff)
custom dialogcustom_theming
-rw-r--r--app/src/main/java/app/fedilab/android/BaseMainActivity.java5
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentThemingSettings.java18
-rw-r--r--app/src/main/res/layouts/mastodon/values/strings.xml7
-rw-r--r--app/src/main/res/values/strings.xml8
-rw-r--r--colorPicker/build.gradle1
-rw-r--r--colorPicker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java6
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 @@
<resources>
- <string name="auto">Auto</string>
- <string name="set_custom_accent">Custom accent color</string>
- <string name="set_custom_accent_indication">Define a theme color per account</string>
- <string name="set_custom_accent_light_value">Light accent color</string>
- <string name="set_custom_accent_dark_value">Dark accent color</string>
- <string name="set_custom_accent_value_light_description">Color that will be applied to the light theme</string>
- <string name="set_custom_accent_value_dark_description">Color that will be applied to the dark theme</string>
</resources> \ 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 @@
<string name="track_selection_title">Select tracks</string>
+ <string name="auto">Auto</string>
+ <string name="set_custom_accent">Custom accent color</string>
+ <string name="set_custom_accent_indication">Define a theme color per account</string>
+ <string name="set_custom_accent_light_value">Light accent color</string>
+ <string name="set_custom_accent_dark_value">Dark accent color</string>
+ <string name="set_custom_accent_value_light_description">Color that will be applied to the light theme</string>
+ <string name="set_custom_accent_value_dark_description">Color that will be applied to the dark theme</string>
+
</resources> \ 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) {