Skip to content

Commit

Permalink
fix(TikTok - Settings): Use correct colors for dark mode (#4087)
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios authored Dec 9, 2024
1 parent 834ae2d commit 6bd22ff
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -98,25 +108,32 @@ 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
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 6bd22ff

Please sign in to comment.