From 6bd22ffa7e8af4d8f5d2d3b1711bd92c44b4e4aa Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 10 Dec 2024 00:46:53 +0400 Subject: [PATCH] fix(TikTok - Settings): Use correct colors for dark mode (#4087) --- .../app/revanced/extension/shared/Utils.java | 7 ++++ .../preference/ReVancedAboutPreference.java | 4 +- .../app/revanced/extension/tiktok/Utils.java | 36 +++++++++++++++++- .../tiktok/feedfilter/LikeCountFilter.java | 7 ++-- .../tiktok/feedfilter/ViewCountFilter.java | 4 +- .../preference/DownloadPathPreference.java | 21 +++++++---- .../preference/InputTextPreference.java | 18 +++++++-- .../preference/RangeValuePreference.java | 37 ++++++++++++++----- .../ReVancedPreferenceFragment.java | 10 ++--- .../ReVancedTikTokAboutPreference.java | 28 +++++++------- .../settings/preference/TogglePreference.java | 18 +++++++-- 11 files changed, 134 insertions(+), 56 deletions(-) diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/Utils.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/Utils.java index aed89670ce..13ad92d8ef 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/Utils.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/Utils.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.net.ConnectivityManager; import android.os.Build; @@ -499,6 +500,12 @@ private static void showToast(@NonNull String messageToToast, int toastDuration) ); } + public static boolean isDarkModeEnabled(Context context) { + Configuration config = context.getResources().getConfiguration(); + final int currentNightMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK; + return currentNightMode == Configuration.UI_MODE_NIGHT_YES; + } + /** * Automatically logs any exceptions the runnable throws. * diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ReVancedAboutPreference.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ReVancedAboutPreference.java index cd62235fc7..ba2facccbd 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ReVancedAboutPreference.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/preference/ReVancedAboutPreference.java @@ -54,9 +54,7 @@ private static String getColorHexString(int color) { } protected boolean isDarkModeEnabled() { - Configuration config = getContext().getResources().getConfiguration(); - final int currentNightMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK; - return currentNightMode == Configuration.UI_MODE_NIGHT_YES; + return Utils.isDarkModeEnabled(getContext()); } /** diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/Utils.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/Utils.java index 2779659210..63f4b0127b 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/Utils.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/Utils.java @@ -1,9 +1,20 @@ package app.revanced.extension.tiktok; +import static app.revanced.extension.shared.Utils.isDarkModeEnabled; + +import android.content.Context; +import android.graphics.Color; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.ColorInt; + import app.revanced.extension.shared.settings.StringSetting; public class Utils { + private static final long[] DEFAULT_MIN_MAX_VALUES = {0L, Long.MAX_VALUE}; + // Edit: This could be handled using a custom Setting class // that saves its value to preferences and JSON using the formatted String created here. public static long[] parseMinMax(StringSetting setting) { @@ -20,6 +31,29 @@ public static long[] parseMinMax(StringSetting setting) { } setting.save("0-" + Long.MAX_VALUE); - return new long[]{0L, Long.MAX_VALUE}; + return DEFAULT_MIN_MAX_VALUES; + } + + // Colors picked by hand. These should be replaced with the styled resources TikTok uses. + private static final @ColorInt int TEXT_DARK_MODE_TITLE = Color.WHITE; + private static final @ColorInt int TEXT_DARK_MODE_SUMMARY + = Color.argb(255, 170, 170, 170); + + private static final @ColorInt int TEXT_LIGHT_MODE_TITLE = Color.BLACK; + private static final @ColorInt int TEXT_LIGHT_MODE_SUMMARY + = Color.argb(255, 80, 80, 80); + + public static void setTitleAndSummaryColor(Context context, View view) { + final boolean darkModeEnabled = isDarkModeEnabled(context); + + TextView title = view.findViewById(android.R.id.title); + title.setTextColor(darkModeEnabled + ? TEXT_DARK_MODE_TITLE + : TEXT_LIGHT_MODE_TITLE); + + TextView summary = view.findViewById(android.R.id.summary); + summary.setTextColor(darkModeEnabled + ? TEXT_DARK_MODE_SUMMARY + : TEXT_LIGHT_MODE_SUMMARY); } } \ No newline at end of file diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/LikeCountFilter.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/LikeCountFilter.java index 57eb665ea1..f5336da5b4 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/LikeCountFilter.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/LikeCountFilter.java @@ -1,17 +1,18 @@ package app.revanced.extension.tiktok.feedfilter; -import app.revanced.extension.tiktok.settings.Settings; import com.ss.android.ugc.aweme.feed.model.Aweme; import com.ss.android.ugc.aweme.feed.model.AwemeStatistics; -import static app.revanced.extension.tiktok.Utils.parseMinMax; +import app.revanced.extension.tiktok.Utils; +import app.revanced.extension.tiktok.settings.Settings; public final class LikeCountFilter implements IFilter { + final long minLike; final long maxLike; LikeCountFilter() { - long[] minMax = parseMinMax(Settings.MIN_MAX_LIKES); + long[] minMax = Utils.parseMinMax(Settings.MIN_MAX_LIKES); minLike = minMax[0]; maxLike = minMax[1]; } diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/ViewCountFilter.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/ViewCountFilter.java index ca9156f84e..32627ca60d 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/ViewCountFilter.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/feedfilter/ViewCountFilter.java @@ -1,17 +1,17 @@ package app.revanced.extension.tiktok.feedfilter; +import app.revanced.extension.tiktok.Utils; import app.revanced.extension.tiktok.settings.Settings; import com.ss.android.ugc.aweme.feed.model.Aweme; import com.ss.android.ugc.aweme.feed.model.AwemeStatistics; -import static app.revanced.extension.tiktok.Utils.parseMinMax; public class ViewCountFilter implements IFilter { final long minView; final long maxView; ViewCountFilter() { - long[] minMax = parseMinMax(Settings.MIN_MAX_VIEWS); + long[] minMax = Utils.parseMinMax(Settings.MIN_MAX_VIEWS); minView = minMax[0]; maxView = minMax[1]; } diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/DownloadPathPreference.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/DownloadPathPreference.java index ae4759c793..fb4e271214 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/DownloadPathPreference.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/DownloadPathPreference.java @@ -16,10 +16,10 @@ import android.widget.RadioGroup; import app.revanced.extension.shared.settings.StringSetting; +import app.revanced.extension.tiktok.Utils; @SuppressWarnings("deprecation") public class DownloadPathPreference extends DialogPreference { - private final Context context; private final String[] entryValues = {"DCIM", "Movies", "Pictures"}; private String mValue; @@ -29,11 +29,10 @@ public class DownloadPathPreference extends DialogPreference { public DownloadPathPreference(Context context, String title, StringSetting setting) { super(context); - this.context = context; - this.setTitle(title); - this.setSummary(Environment.getExternalStorageDirectory().getPath() + "/" + setting.get()); - this.setKey(setting.key); - this.setValue(setting.get()); + setTitle(title); + setSummary(Environment.getExternalStorageDirectory().getPath() + "/" + setting.get()); + setKey(setting.key); + setValue(setting.get()); } public String getValue() { @@ -59,6 +58,7 @@ protected View onCreateDialogView() { childDownloadPath = getValue().substring(getValue().indexOf("/") + 1); mediaPathIndex = findIndexOf(currentMedia); + Context context = getContext(); LinearLayout dialogView = new LinearLayout(context); RadioGroup mediaPath = new RadioGroup(context); mediaPath.setLayoutParams(new RadioGroup.LayoutParams(-1, -2)); @@ -79,12 +79,10 @@ protected View onCreateDialogView() { downloadPath.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - } @Override @@ -99,6 +97,13 @@ public void afterTextChanged(Editable editable) { return dialogView; } + @Override + protected void onBindView(View view) { + super.onBindView(view); + + Utils.setTitleAndSummaryColor(getContext(), view); + } + @Override protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { builder.setTitle("Download Path"); diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/InputTextPreference.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/InputTextPreference.java index b80380e512..d2df31462b 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/InputTextPreference.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/InputTextPreference.java @@ -2,16 +2,26 @@ import android.content.Context; import android.preference.EditTextPreference; +import android.view.View; import app.revanced.extension.shared.settings.StringSetting; +import app.revanced.extension.tiktok.Utils; +@SuppressWarnings("deprecation") public class InputTextPreference extends EditTextPreference { public InputTextPreference(Context context, String title, String summary, StringSetting setting) { super(context); - this.setTitle(title); - this.setSummary(summary); - this.setKey(setting.key); - this.setText(setting.get()); + setTitle(title); + setSummary(summary); + setKey(setting.key); + setText(setting.get()); + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + Utils.setTitleAndSummaryColor(getContext(), view); } } diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/RangeValuePreference.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/RangeValuePreference.java index 8eaf98ac52..012d334f07 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/RangeValuePreference.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/RangeValuePreference.java @@ -1,5 +1,6 @@ package app.revanced.extension.tiktok.settings.preference; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -14,11 +15,10 @@ import android.widget.TextView; import app.revanced.extension.shared.settings.StringSetting; +import app.revanced.extension.tiktok.Utils; @SuppressWarnings("deprecation") public class RangeValuePreference extends DialogPreference { - private final Context context; - private String minValue; private String maxValue; @@ -29,7 +29,6 @@ public class RangeValuePreference extends DialogPreference { public RangeValuePreference(Context context, String title, String summary, StringSetting setting) { super(context); - this.context = context; setTitle(title); setSummary(summary); setKey(setting.key); @@ -53,41 +52,52 @@ public String getValue() { return mValue; } + @SuppressLint("SetTextI18n") @Override protected View onCreateDialogView() { minValue = getValue().split("-")[0]; maxValue = getValue().split("-")[1]; + + Context context = getContext(); + LinearLayout dialogView = new LinearLayout(context); dialogView.setOrientation(LinearLayout.VERTICAL); + + // Min view LinearLayout minView = new LinearLayout(context); minView.setOrientation(LinearLayout.HORIZONTAL); + dialogView.addView(minView); + TextView min = new TextView(context); min.setText("Min: "); minView.addView(min); + EditText minEditText = new EditText(context); minEditText.setInputType(InputType.TYPE_CLASS_NUMBER); minEditText.setText(minValue); minView.addView(minEditText); - dialogView.addView(minView); + + // Max view LinearLayout maxView = new LinearLayout(context); maxView.setOrientation(LinearLayout.HORIZONTAL); + dialogView.addView(maxView); + TextView max = new TextView(context); max.setText("Max: "); maxView.addView(max); + EditText maxEditText = new EditText(context); maxEditText.setInputType(InputType.TYPE_CLASS_NUMBER); maxEditText.setText(maxValue); maxView.addView(maxEditText); - dialogView.addView(maxView); + minEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - } @Override @@ -98,12 +108,10 @@ public void afterTextChanged(Editable editable) { maxEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - } @Override @@ -111,12 +119,21 @@ public void afterTextChanged(Editable editable) { maxValue = editable.toString(); } }); + return dialogView; } + @Override + protected void onBindView(View view) { + super.onBindView(view); + + Utils.setTitleAndSummaryColor(getContext(), view); + } + @Override protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { - builder.setPositiveButton(android.R.string.ok, (dialog, which) -> this.onClick(dialog, DialogInterface.BUTTON_POSITIVE)); + builder.setPositiveButton(android.R.string.ok, (dialog, which) + -> this.onClick(dialog, DialogInterface.BUTTON_POSITIVE)); builder.setNegativeButton(android.R.string.cancel, null); } diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedPreferenceFragment.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedPreferenceFragment.java index 43ab69297e..7027e924a4 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedPreferenceFragment.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedPreferenceFragment.java @@ -18,14 +18,12 @@ public class ReVancedPreferenceFragment extends AbstractPreferenceFragment { @Override - protected void syncSettingWithPreference(@NonNull @NotNull Preference pref, - @NonNull @NotNull Setting setting, + protected void syncSettingWithPreference(@NonNull Preference pref, + @NonNull Setting setting, boolean applySettingToPreference) { - if (pref instanceof RangeValuePreference) { - RangeValuePreference rangeValuePref = (RangeValuePreference) pref; + if (pref instanceof RangeValuePreference rangeValuePref) { Setting.privateSetValueFromString(setting, rangeValuePref.getValue()); - } else if (pref instanceof DownloadPathPreference) { - DownloadPathPreference downloadPathPref = (DownloadPathPreference) pref; + } else if (pref instanceof DownloadPathPreference downloadPathPref) { Setting.privateSetValueFromString(setting, downloadPathPref.getValue()); } else { super.syncSettingWithPreference(pref, setting, applySettingToPreference); diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedTikTokAboutPreference.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedTikTokAboutPreference.java index 2ca953e1c8..408bab6c02 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedTikTokAboutPreference.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/ReVancedTikTokAboutPreference.java @@ -1,13 +1,15 @@ package app.revanced.extension.tiktok.settings.preference; import android.content.Context; -import android.util.AttributeSet; +import android.view.View; import java.util.Map; import app.revanced.extension.shared.Logger; import app.revanced.extension.shared.settings.preference.ReVancedAboutPreference; +import app.revanced.extension.tiktok.Utils; +@SuppressWarnings("deprecation") public class ReVancedTikTokAboutPreference extends ReVancedAboutPreference { /** @@ -23,22 +25,11 @@ public class ReVancedTikTokAboutPreference extends ReVancedAboutPreference { "revanced_settings_about_links_header", "Official links" ); - { - //noinspection deprecation - setTitle("About"); - } - - public ReVancedTikTokAboutPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - public ReVancedTikTokAboutPreference(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - public ReVancedTikTokAboutPreference(Context context, AttributeSet attrs) { - super(context, attrs); - } public ReVancedTikTokAboutPreference(Context context) { super(context); + + setTitle("About"); + setSummary("About ReVanced"); } @Override @@ -52,4 +43,11 @@ protected String getString(String key, Object ... args) { return String.format(format, args); } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + Utils.setTitleAndSummaryColor(getContext(), view); + } } diff --git a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/TogglePreference.java b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/TogglePreference.java index 788b0d67d0..f0e8085f04 100644 --- a/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/TogglePreference.java +++ b/extensions/tiktok/src/main/java/app/revanced/extension/tiktok/settings/preference/TogglePreference.java @@ -2,16 +2,26 @@ import android.content.Context; import android.preference.SwitchPreference; +import android.view.View; import app.revanced.extension.shared.settings.BooleanSetting; +import app.revanced.extension.tiktok.Utils; @SuppressWarnings("deprecation") public class TogglePreference extends SwitchPreference { + public TogglePreference(Context context, String title, String summary, BooleanSetting setting) { super(context); - this.setTitle(title); - this.setSummary(summary); - this.setKey(setting.key); - this.setChecked(setting.get()); + setTitle(title); + setSummary(summary); + setKey(setting.key); + setChecked(setting.get()); + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + Utils.setTitleAndSummaryColor(getContext(), view); } }