fix(TikTok - Settings): Use correct colors for dark mode (#4087)

This commit is contained in:
LisoUseInAIKyrios
2024-12-10 00:46:53 +04:00
committed by GitHub
parent 834ae2dd6f
commit 6bd22ffa7e
11 changed files with 134 additions and 56 deletions

View File

@ -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<Long[]> 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 class Utils {
}
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);
}
}

View File

@ -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];
}

View File

@ -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];
}

View File

@ -16,10 +16,10 @@ import android.widget.RadioButton;
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 @@ public class DownloadPathPreference extends DialogPreference {
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 @@ public class DownloadPathPreference extends DialogPreference {
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 class DownloadPathPreference extends DialogPreference {
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");

View File

@ -2,16 +2,26 @@ package app.revanced.extension.tiktok.settings.preference;
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);
}
}

View File

@ -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.LinearLayout;
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 class RangeValuePreference extends DialogPreference {
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 class RangeValuePreference extends DialogPreference {
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 class RangeValuePreference extends DialogPreference {
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);
}

View File

@ -18,14 +18,12 @@ import org.jetbrains.annotations.NotNull;
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);

View File

@ -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 @@ public class ReVancedTikTokAboutPreference extends ReVancedAboutPreference {
return String.format(format, args);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
Utils.setTitleAndSummaryColor(getContext(), view);
}
}

View File

@ -2,16 +2,26 @@ package app.revanced.extension.tiktok.settings.preference;
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);
}
}