feat(Tiktok - Feed filter): Add more filters (#445)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
Vu Hoan Huy 2023-08-02 19:09:07 +07:00 committed by GitHub
parent d2a8c33109
commit c16c038396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 775 additions and 331 deletions

View File

@ -4,10 +4,10 @@ import app.revanced.tiktok.settings.SettingsEnum;
public class DownloadsPatch { public class DownloadsPatch {
public static String getDownloadPath() { public static String getDownloadPath() {
return SettingsEnum.TIK_DOWN_PATH.getString(); return SettingsEnum.DOWNLOAD_PATH.getString();
} }
public static boolean shouldRemoveWatermark() { public static boolean shouldRemoveWatermark() {
return SettingsEnum.TIK_DOWN_WATERMARK.getBoolean(); return SettingsEnum.DOWNLOAD_WATERMARK.getBoolean();
} }
} }

View File

@ -0,0 +1,16 @@
package app.revanced.tiktok.feedfilter;
import app.revanced.tiktok.settings.SettingsEnum;
import com.ss.android.ugc.aweme.feed.model.Aweme;
public class AdsFilter implements IFilter {
@Override
public boolean getEnabled() {
return SettingsEnum.REMOVE_ADS.getBoolean();
}
@Override
public boolean getFiltered(Aweme item) {
return item.isAd() || item.isWithPromotionalMusic();
}
}

View File

@ -6,33 +6,28 @@ import com.ss.android.ugc.aweme.feed.model.FeedItemList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import app.revanced.tiktok.settings.SettingsEnum; public final class FeedItemsFilter {
private static final List<IFilter> FILTERS = List.of(
public class FeedItemsFilter { new AdsFilter(),
new LiveFilter(),
new StoryFilter(),
new ImageVideoFilter(),
new ViewCountFilter(),
new LikeCountFilter()
);
public static void filter(FeedItemList feedItemList) { public static void filter(FeedItemList feedItemList) {
if (SettingsEnum.TIK_REMOVE_ADS.getBoolean()) removeAds(feedItemList); Iterator<Aweme> feedItemListIterator = feedItemList.items.iterator();
if (SettingsEnum.TIK_HIDE_LIVE.getBoolean()) removeLive(feedItemList); while (feedItemListIterator.hasNext()) {
} Aweme item = feedItemListIterator.next();
if (item == null) continue;
private static void removeAds(FeedItemList feedItemList) { for (IFilter filter : FILTERS) {
List<Aweme> items = feedItemList.items; boolean enabled = filter.getEnabled();
Iterator<Aweme> it = items.iterator(); if (enabled && filter.getFiltered(item)) {
while (it.hasNext()) { feedItemListIterator.remove();
Aweme item = it.next(); break;
if (item != null && (item.isAd() || item.isWithPromotionalMusic())) { }
it.remove();
}
}
}
private static void removeLive(FeedItemList feedItemList) {
List<Aweme> items = feedItemList.items;
Iterator<Aweme> it = items.iterator();
while (it.hasNext()) {
Aweme item = it.next();
if (item != null && (item.isLive() || item.isLiveReplay())) {
it.remove();
} }
} }
} }

View File

@ -0,0 +1,9 @@
package app.revanced.tiktok.feedfilter;
import com.ss.android.ugc.aweme.feed.model.Aweme;
public interface IFilter {
boolean getEnabled();
boolean getFiltered(Aweme item);
}

View File

@ -0,0 +1,16 @@
package app.revanced.tiktok.feedfilter;
import app.revanced.tiktok.settings.SettingsEnum;
import com.ss.android.ugc.aweme.feed.model.Aweme;
public class ImageVideoFilter implements IFilter {
@Override
public boolean getEnabled() {
return SettingsEnum.HIDE_IMAGE.getBoolean();
}
@Override
public boolean getFiltered(Aweme item) {
return item.isImage() || item.isPhotoMode();
}
}

View File

@ -0,0 +1,32 @@
package app.revanced.tiktok.feedfilter;
import app.revanced.tiktok.settings.SettingsEnum;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeStatistics;
import static app.revanced.tiktok.utils.ReVancedUtils.parseMinMax;
public final class LikeCountFilter implements IFilter {
final long minLike;
final long maxLike;
LikeCountFilter() {
long[] minMax = parseMinMax(SettingsEnum.MIN_MAX_LIKES);
minLike = minMax[0];
maxLike = minMax[1];
}
@Override
public boolean getEnabled() {
return true;
}
@Override
public boolean getFiltered(Aweme item) {
AwemeStatistics statistics = item.getStatistics();
if (statistics == null) return false;
long likeCount = statistics.getDiggCount();
return likeCount < minLike || likeCount > maxLike;
}
}

View File

@ -0,0 +1,16 @@
package app.revanced.tiktok.feedfilter;
import app.revanced.tiktok.settings.SettingsEnum;
import com.ss.android.ugc.aweme.feed.model.Aweme;
public class LiveFilter implements IFilter {
@Override
public boolean getEnabled() {
return SettingsEnum.HIDE_LIVE.getBoolean();
}
@Override
public boolean getFiltered(Aweme item) {
return item.isLive() || item.isLiveReplay();
}
}

View File

@ -0,0 +1,16 @@
package app.revanced.tiktok.feedfilter;
import app.revanced.tiktok.settings.SettingsEnum;
import com.ss.android.ugc.aweme.feed.model.Aweme;
public class StoryFilter implements IFilter {
@Override
public boolean getEnabled() {
return SettingsEnum.HIDE_STORY.getBoolean();
}
@Override
public boolean getFiltered(Aweme item) {
return item.getIsTikTokStory();
}
}

View File

@ -0,0 +1,32 @@
package app.revanced.tiktok.feedfilter;
import app.revanced.tiktok.settings.SettingsEnum;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeStatistics;
import static app.revanced.tiktok.utils.ReVancedUtils.parseMinMax;
public class ViewCountFilter implements IFilter {
final long minView;
final long maxView;
ViewCountFilter() {
long[] minMax = parseMinMax(SettingsEnum.MIN_MAX_VIEWS);
minView = minMax[0];
maxView = minMax[1];
}
@Override
public boolean getEnabled() {
return true;
}
@Override
public boolean getFiltered(Aweme item) {
AwemeStatistics statistics = item.getStatistics();
if (statistics == null) return false;
long playCount = statistics.getPlayCount();
return playCount < minView || playCount > maxView;
}
}

View File

@ -1,32 +1,42 @@
package app.revanced.tiktok.settings; package app.revanced.tiktok.settings;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static app.revanced.tiktok.settings.SettingsEnum.ReturnType.BOOLEAN;
import static app.revanced.tiktok.settings.SettingsEnum.ReturnType.STRING;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import app.revanced.tiktok.utils.LogHelper; import app.revanced.tiktok.utils.LogHelper;
import app.revanced.tiktok.utils.ReVancedUtils; import app.revanced.tiktok.utils.ReVancedUtils;
import java.util.HashMap;
import java.util.Map;
import static app.revanced.tiktok.settings.SettingsEnum.ReturnType.BOOLEAN;
import static app.revanced.tiktok.settings.SettingsEnum.ReturnType.STRING;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
public enum SettingsEnum { public enum SettingsEnum {
//TikTok Settings DEBUG("debug", BOOLEAN, FALSE), // Must be first value, otherwise logging during loading will not work.
TIK_DEBUG("tik_debug", BOOLEAN, FALSE), // must be first value, otherwise logging during loading will not work REMOVE_ADS("remove_ads", BOOLEAN, TRUE, true),
TIK_REMOVE_ADS("tik_remove_ads", BOOLEAN, TRUE, true), HIDE_LIVE("hide_live", BOOLEAN, FALSE, true),
TIK_HIDE_LIVE("tik_hide_live", BOOLEAN, FALSE, true), HIDE_STORY("hide_story", BOOLEAN, FALSE, true),
TIK_DOWN_PATH("tik_down_path", STRING, "DCIM/TikTok"), HIDE_IMAGE("hide_image", BOOLEAN, FALSE, true),
TIK_DOWN_WATERMARK("tik_down_watermark", BOOLEAN, TRUE), MIN_MAX_VIEWS("min_max_views", STRING, "0-" + Long.MAX_VALUE, true),
TIK_SIMSPOOF("tik_simspoof", BOOLEAN, TRUE, true), MIN_MAX_LIKES("min_max_likes", STRING, "0-" + Long.MAX_VALUE, true),
TIK_SIMSPOOF_ISO("tik_simspoof_iso", STRING, "us"), DOWNLOAD_PATH("down_path", STRING, "DCIM/TikTok"),
TIK_SIMSPOOF_MCCMNC("tik_simspoof_mccmnc", STRING, "310160"), DOWNLOAD_WATERMARK("down_watermark", BOOLEAN, TRUE),
TIK_SIMSPOOF_OP_NAME("tik_simspoof_op_name", STRING, "T-Mobile"); SIM_SPOOF("simspoof", BOOLEAN, TRUE, true),
SIM_SPOOF_ISO("simspoof_iso", STRING, "us"),
SIMSPOOF_MCCMNC("simspoof_mccmnc", STRING, "310160"),
SIMSPOOF_OP_NAME("simspoof_op_name", STRING, "T-Mobile");
private static final Map<String, SettingsEnum> pathToSetting = new HashMap<>(2 * values().length);
static { static {
loadAllSettings(); loadAllSettings();
for (SettingsEnum setting : values()) {
pathToSetting.put(setting.path, setting);
}
} }
@NonNull @NonNull
@ -47,11 +57,12 @@ public enum SettingsEnum {
SettingsEnum(String path, ReturnType returnType, Object defaultValue) { SettingsEnum(String path, ReturnType returnType, Object defaultValue) {
this(path, returnType, defaultValue, SharedPrefCategory.TIKTOK_PREFS, false); this(path, returnType, defaultValue, SharedPrefCategory.TIKTOK_PREFS, false);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, boolean rebootApp) { SettingsEnum(String path, ReturnType returnType, Object defaultValue, boolean rebootApp) {
this(path, returnType, defaultValue, SharedPrefCategory.TIKTOK_PREFS, rebootApp); this(path, returnType, defaultValue, SharedPrefCategory.TIKTOK_PREFS, rebootApp);
} }
SettingsEnum(@NonNull String path, @NonNull ReturnType returnType, @NonNull Object defaultValue,
@NonNull SharedPrefCategory prefName, boolean rebootApp) { SettingsEnum(@NonNull String path, @NonNull ReturnType returnType, @NonNull Object defaultValue, @NonNull SharedPrefCategory prefName, boolean rebootApp) {
this.path = path; this.path = path;
this.returnType = returnType; this.returnType = returnType;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
@ -59,6 +70,11 @@ public enum SettingsEnum {
this.rebootApp = rebootApp; this.rebootApp = rebootApp;
} }
@Nullable
public static SettingsEnum getSettingsFromPath(@NonNull String str) {
return pathToSetting.get(str);
}
private static void loadAllSettings() { private static void loadAllSettings() {
try { try {
Context context = ReVancedUtils.getAppContext(); Context context = ReVancedUtils.getAppContext();
@ -144,11 +160,15 @@ public enum SettingsEnum {
return (String) value; return (String) value;
} }
/**
* @return the value of this setting as as generic object type.
*/
@NonNull
public Object getObjectValue() {
return value;
}
public enum ReturnType { public enum ReturnType {
BOOLEAN, BOOLEAN, INTEGER, LONG, FLOAT, STRING,
INTEGER,
LONG,
FLOAT,
STRING,
} }
} }

View File

@ -0,0 +1,119 @@
package app.revanced.tiktok.settingsmenu;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Process;
import android.preference.*;
import androidx.annotation.Nullable;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.tiktok.settings.SettingsEnum;
import app.revanced.tiktok.settings.SharedPrefCategory;
import app.revanced.tiktok.settingsmenu.preference.DownloadPathPreference;
import app.revanced.tiktok.settingsmenu.preference.RangeValuePreference;
import app.revanced.tiktok.settingsmenu.preference.categories.DownloadsPreferenceCategory;
import app.revanced.tiktok.settingsmenu.preference.categories.FeedFilterPreferenceCategory;
import app.revanced.tiktok.settingsmenu.preference.categories.IntegrationsPreferenceCategory;
import app.revanced.tiktok.settingsmenu.preference.categories.SimSpoofPreferenceCategory;
import app.revanced.tiktok.utils.ReVancedUtils;
import com.ss.android.ugc.aweme.splash.SplashActivity;
@SuppressWarnings("deprecation")
public class ReVancedPreferenceFragment extends PreferenceFragment {
private boolean registered = false;
private boolean settingsInitialized = false;
SharedPreferences.OnSharedPreferenceChangeListener listener = (sharedPreferences, str) -> {
try {
SettingsEnum setting = SettingsEnum.getSettingsFromPath(str);
if (setting == null) {
return;
}
Preference pref = findPreference(str);
if (pref == null) {
return;
}
if (pref instanceof SwitchPreference) {
SwitchPreference switchPref = (SwitchPreference) pref;
SettingsEnum.setValue(setting, switchPref.isChecked());
} else if (pref instanceof EditTextPreference) {
EditTextPreference editPreference = (EditTextPreference) pref;
SettingsEnum.setValue(setting, editPreference.getText());
} else if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref;
SettingsEnum.setValue(setting, listPref.getValue());
updateListPreferenceSummary((ListPreference) pref, setting);
} else if (pref instanceof RangeValuePreference) {
RangeValuePreference rangeValuePref = (RangeValuePreference) pref;
SettingsEnum.setValue(setting, rangeValuePref.getValue());
} else if (pref instanceof DownloadPathPreference) {
DownloadPathPreference downloadPathPref = (DownloadPathPreference) pref;
SettingsEnum.setValue(setting, downloadPathPref.getValue());
} else {
LogHelper.printException(() -> "Setting cannot be handled: " + pref.getClass() + " " + pref);
return;
}
if (ReVancedUtils.getAppContext() != null && this.settingsInitialized && setting.rebootApp) {
rebootDialog(getActivity());
}
} catch (Exception ex) {
LogHelper.printException(() -> "OnSharedPreferenceChangeListener failure", ex);
}
};
private void updateListPreferenceSummary(ListPreference listPreference, SettingsEnum setting) {
String objectStringValue = setting.getObjectValue().toString();
final int entryIndex = listPreference.findIndexOfValue(objectStringValue);
if (entryIndex >= 0) {
listPreference.setSummary(listPreference.getEntries()[entryIndex]);
listPreference.setValue(objectStringValue);
} else {
listPreference.setSummary(objectStringValue);
}
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.registered = true;
getPreferenceManager().setSharedPreferencesName(SharedPrefCategory.TIKTOK_PREFS.prefName);
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this.listener);
final Activity context = this.getActivity();
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(context);
setPreferenceScreen(preferenceScreen);
new FeedFilterPreferenceCategory(context, preferenceScreen);
new DownloadsPreferenceCategory(context, preferenceScreen);
new SimSpoofPreferenceCategory(context, preferenceScreen);
new IntegrationsPreferenceCategory(context, preferenceScreen);
this.settingsInitialized = true;
}
@Override
public void onDestroy() {
if (this.registered) {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this.listener);
this.registered = false;
}
super.onDestroy();
}
private void reboot(Activity activity) {
int intent = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
((AlarmManager) activity.getSystemService(Context.ALARM_SERVICE)).setExact(AlarmManager.ELAPSED_REALTIME, 1500L, PendingIntent.getActivity(activity, 0, new Intent(activity, SplashActivity.class), intent));
Process.killProcess(Process.myPid());
}
private void rebootDialog(final Activity activity) {
new AlertDialog.Builder(activity).setMessage("Refresh and restart").setPositiveButton("Restart", (dialog, i) -> reboot(activity)).setNegativeButton("Cancel", null).show();
}
}

View File

@ -1,242 +0,0 @@
package app.revanced.tiktok.settingsmenu;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.os.Process;
import android.preference.EditTextPreference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import androidx.annotation.Nullable;
import com.ss.android.ugc.aweme.splash.SplashActivity;
import app.revanced.tiktok.settings.SettingsEnum;
import app.revanced.tiktok.settings.SharedPrefCategory;
import app.revanced.tiktok.settingsmenu.preference.DownloadPathPreference;
import app.revanced.tiktok.utils.ReVancedUtils;
public class ReVancedSettingsFragment extends PreferenceFragment {
private boolean Registered = false;
private boolean settingsInitialized = false;
SharedPreferences.OnSharedPreferenceChangeListener listener = (sharedPreferences, str) -> {
for (SettingsEnum setting : SettingsEnum.values()) {
if (!setting.path.equals(str)) continue;
if (ReVancedUtils.getAppContext() != null && this.settingsInitialized && setting.rebootApp) {
rebootDialog(getActivity());
}
}
};
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(SharedPrefCategory.TIKTOK_PREFS.prefName);
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this.listener);
this.Registered = true;
final Activity context = this.getActivity();
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(context);
setPreferenceScreen(preferenceScreen);
//Feed filter
if (SettingsStatus.feedFilter) {
PreferenceCategory feedFilter = new PreferenceCategory(context);
feedFilter.setTitle("Feed filter");
preferenceScreen.addPreference(feedFilter);
//Remove ads toggle
{
SwitchPreference preference = new SwitchPreference(context);
feedFilter.addPreference(preference);
preference.setKey(SettingsEnum.TIK_REMOVE_ADS.path);
preference.setDefaultValue(SettingsEnum.TIK_REMOVE_ADS.defaultValue);
preference.setChecked(SettingsEnum.TIK_REMOVE_ADS.getBoolean());
preference.setTitle("Remove feed ads");
preference.setSummary("Remove ads from feed.");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
// FIXME: the value is already saved in the preferences.
// instead of saving again, simple call SettingsEnum#setValue()
final boolean value = (Boolean) newValue;
SettingsEnum.TIK_REMOVE_ADS.saveValue(value);
return true;
});
}
//Hide LiveStreams toggle
{
SwitchPreference preference = new SwitchPreference(context);
feedFilter.addPreference(preference);
preference.setKey(SettingsEnum.TIK_HIDE_LIVE.path);
preference.setDefaultValue(SettingsEnum.TIK_HIDE_LIVE.defaultValue);
preference.setChecked(SettingsEnum.TIK_HIDE_LIVE.getBoolean());
preference.setTitle("Hide livestreams");
preference.setSummary("Hide livestreams from feed.");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final boolean value = (Boolean) newValue;
SettingsEnum.TIK_HIDE_LIVE.saveValue(value);
return true;
});
}
}
//Download
if (SettingsStatus.download) {
PreferenceCategory download = new PreferenceCategory(context);
download.setTitle("Download");
preferenceScreen.addPreference(download);
//Download path
{
DownloadPathPreference preference = new DownloadPathPreference(context);
download.addPreference(preference);
preference.setKey(SettingsEnum.TIK_DOWN_PATH.path);
preference.setDefaultValue(SettingsEnum.TIK_DOWN_PATH.defaultValue);
preference.setValue(SettingsEnum.TIK_DOWN_PATH.getString());
preference.setTitle("Download path");
preference.setSummary(Environment.getExternalStorageDirectory().getPath() + "/" + preference.getValue());
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final String value = (String) newValue;
SettingsEnum.TIK_DOWN_PATH.saveValue(value);
return true;
});
}
//Download watermark
{
SwitchPreference preference = new SwitchPreference(context);
download.addPreference(preference);
preference.setKey(SettingsEnum.TIK_DOWN_WATERMARK.path);
preference.setDefaultValue(SettingsEnum.TIK_DOWN_WATERMARK.defaultValue);
preference.setChecked(SettingsEnum.TIK_DOWN_WATERMARK.getBoolean());
preference.setTitle("Remove watermark");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final boolean value = (Boolean) newValue;
SettingsEnum.TIK_DOWN_WATERMARK.saveValue(value);
return true;
});
}
}
// SpoofSimPatch
if(SettingsStatus.simSpoof) {
PreferenceCategory simSpoof = new PreferenceCategory(context);
simSpoof.setTitle("Bypass regional restriction");
preferenceScreen.addPreference(simSpoof);
//Global Switch
{
SwitchPreference preference = new SwitchPreference(context);
simSpoof.addPreference(preference);
preference.setKey(SettingsEnum.TIK_SIMSPOOF.path);
preference.setDefaultValue(SettingsEnum.TIK_SIMSPOOF.defaultValue);
preference.setChecked(SettingsEnum.TIK_SIMSPOOF.getBoolean());
preference.setTitle("Fake sim card info");
preference.setSummary("Bypass regional restriction by fake sim card information.");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final boolean value = (Boolean) newValue;
SettingsEnum.TIK_SIMSPOOF.saveValue(value);
return true;
});
}
//Country ISO
{
EditTextPreference preference = new EditTextPreference(context);
simSpoof.addPreference(preference);
preference.setKey(SettingsEnum.TIK_SIMSPOOF_ISO.path);
preference.setDefaultValue(SettingsEnum.TIK_SIMSPOOF_ISO.defaultValue);
preference.setText(SettingsEnum.TIK_SIMSPOOF_ISO.getString());
preference.setTitle("Country ISO");
preference.setSummary("us, uk, jp, ...");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final String value = (String) newValue;
SettingsEnum.TIK_SIMSPOOF_ISO.saveValue(value);
return true;
});
}
//Operator mcc+mnc
{
EditTextPreference preference = new EditTextPreference(context);
simSpoof.addPreference(preference);
preference.setKey(SettingsEnum.TIK_SIMSPOOF_MCCMNC.path);
preference.setDefaultValue(SettingsEnum.TIK_SIMSPOOF_MCCMNC.defaultValue);
preference.setText(SettingsEnum.TIK_SIMSPOOF_MCCMNC.getString());
preference.setTitle("Operator mcc+mnc");
preference.setSummary("mcc+mnc");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final String value = (String) newValue;
SettingsEnum.TIK_SIMSPOOF_MCCMNC.saveValue(value);
return true;
});
}
//Operator name
{
EditTextPreference preference = new EditTextPreference(context);
simSpoof.addPreference(preference);
preference.setKey(SettingsEnum.TIK_SIMSPOOF_OP_NAME.path);
preference.setDefaultValue(SettingsEnum.TIK_SIMSPOOF_OP_NAME.defaultValue);
preference.setText(SettingsEnum.TIK_SIMSPOOF_OP_NAME.getString());
preference.setTitle("Operator name");
preference.setSummary("Name of the operator");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final String value = (String) newValue;
SettingsEnum.TIK_SIMSPOOF_OP_NAME.saveValue(value);
return true;
});
}
}
//Integration
PreferenceCategory integration = new PreferenceCategory(context);
integration.setTitle("Integration");
preferenceScreen.addPreference(integration);
//Enable DebugLog toggle
{
SwitchPreference preference = new SwitchPreference(context);
integration.addPreference(preference);
preference.setKey(SettingsEnum.TIK_DEBUG.path);
preference.setDefaultValue(SettingsEnum.TIK_DEBUG.defaultValue);
preference.setChecked(SettingsEnum.TIK_DEBUG.getBoolean());
preference.setTitle("Enable debug log");
preference.setSummary("Show integration debug log.");
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final boolean value = (Boolean) newValue;
SettingsEnum.TIK_DEBUG.saveValue(value);
return true;
});
}
this.settingsInitialized = true;
}
@Override // android.preference.PreferenceFragment, android.app.Fragment
public void onDestroy() {
if (this.Registered) {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this.listener);
this.Registered = false;
}
super.onDestroy();
}
private void reboot(Activity activity) {
int intent;
intent = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
((AlarmManager) activity.getSystemService(Context.ALARM_SERVICE)).setExact(AlarmManager.ELAPSED_REALTIME, 1500L, PendingIntent.getActivity(activity, 0, new Intent(activity, SplashActivity.class), intent));
Process.killProcess(Process.myPid());
}
private void rebootDialog(final Activity activity) {
new AlertDialog.Builder(activity).
setMessage("Refresh and restart").
setPositiveButton("RESTART", (dialog, i) -> reboot(activity))
.setNegativeButton("CANCEL", null)
.show();
}
}

View File

@ -55,7 +55,7 @@ public class SettingsMenu {
linearLayout.addView(fragment); linearLayout.addView(fragment);
base.setContentView(linearLayout); base.setContentView(linearLayout);
PreferenceFragment preferenceFragment = new ReVancedSettingsFragment(); PreferenceFragment preferenceFragment = new ReVancedPreferenceFragment();
base.getFragmentManager().beginTransaction().replace(fragmentId, preferenceFragment).commit(); base.getFragmentManager().beginTransaction().replace(fragmentId, preferenceFragment).commit();
return true; return true;

View File

@ -1,20 +1,20 @@
package app.revanced.tiktok.settingsmenu; package app.revanced.tiktok.settingsmenu;
public class SettingsStatus { public class SettingsStatus {
public static boolean feedFilter = false; public static boolean feedFilterEnabled = false;
public static boolean download = false; public static boolean downloadEnabled = false;
public static boolean simSpoof = false; public static boolean simSpoofEnabled = false;
public static void enableFeedFilter() { public static void enableFeedFilter() {
feedFilter = true; feedFilterEnabled = true;
} }
public static void enableDownload() { public static void enableDownload() {
download = true; downloadEnabled = true;
} }
public static void enableSimSpoof() { public static void enableSimSpoof() {
simSpoof = true; simSpoofEnabled = true;
} }
public static void load() { public static void load() {

View File

@ -7,6 +7,7 @@ import android.os.Environment;
import android.preference.DialogPreference; import android.preference.DialogPreference;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
@ -14,23 +15,48 @@ import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import app.revanced.tiktok.settings.SettingsEnum;
@SuppressWarnings("deprecation")
public class DownloadPathPreference extends DialogPreference { public class DownloadPathPreference extends DialogPreference {
private final Context context; private final Context context;
private final String[] entryValues = {"DCIM", "Movies", "Pictures"}; private final String[] entryValues = {"DCIM", "Movies", "Pictures"};
private String value; private String mValue;
private boolean mValueSet;
private int mediaPathIndex; private int mediaPathIndex;
private String childDownloadPath; private String childDownloadPath;
public DownloadPathPreference(Context context) { public DownloadPathPreference(Context context, String title, SettingsEnum setting) {
super(context); super(context);
this.context = context; this.context = context;
this.setTitle(title);
this.setSummary(Environment.getExternalStorageDirectory().getPath() + "/" + setting.getString());
this.setKey(setting.path);
this.setValue(setting.getString());
}
public String getValue() {
return this.mValue;
}
public void setValue(String value) {
final boolean changed = !TextUtils.equals(mValue, value);
if (changed || !mValueSet) {
mValue = value;
mValueSet = true;
persistString(value);
if (changed) {
notifyDependencyChange(shouldDisableDependents());
notifyChanged();
}
}
} }
@Override @Override
protected View onCreateDialogView() { protected View onCreateDialogView() {
String currentMedia = getValue().split("/")[0]; String currentMedia = getValue().split("/")[0];
childDownloadPath = getValue().substring(getValue().indexOf("/") + 1); childDownloadPath = getValue().substring(getValue().indexOf("/") + 1);
mediaPathIndex = findIndexOf(currentMedia); mediaPathIndex = findIndexOf(currentMedia);
LinearLayout dialogView = new LinearLayout(context); LinearLayout dialogView = new LinearLayout(context);
@ -84,10 +110,8 @@ public class DownloadPathPreference extends DialogPreference {
protected void onDialogClosed(boolean positiveResult) { protected void onDialogClosed(boolean positiveResult) {
if (positiveResult && mediaPathIndex >= 0) { if (positiveResult && mediaPathIndex >= 0) {
String newValue = entryValues[mediaPathIndex] + "/" + childDownloadPath; String newValue = entryValues[mediaPathIndex] + "/" + childDownloadPath;
if (callChangeListener(newValue)) { setSummary(Environment.getExternalStorageDirectory().getPath() + "/" + newValue);
setValue(newValue); setValue(newValue);
setSummary(Environment.getExternalStorageDirectory().getPath() + "/" + newValue);
}
} }
} }
@ -97,12 +121,4 @@ public class DownloadPathPreference extends DialogPreference {
} }
return -1; return -1;
} }
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
} }

View File

@ -0,0 +1,17 @@
package app.revanced.tiktok.settingsmenu.preference;
import android.content.Context;
import android.preference.EditTextPreference;
import app.revanced.tiktok.settings.SettingsEnum;
public class InputTextPreference extends EditTextPreference {
public InputTextPreference(Context context, String title, String summary, SettingsEnum setting) {
super(context);
this.setTitle(title);
this.setSummary(summary);
this.setKey(setting.path);
this.setText(setting.getString());
}
}

View File

@ -0,0 +1,130 @@
package app.revanced.tiktok.settingsmenu.preference;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.DialogPreference;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import app.revanced.tiktok.settings.SettingsEnum;
@SuppressWarnings("deprecation")
public class RangeValuePreference extends DialogPreference {
private final Context context;
private String minValue;
private String maxValue;
private String mValue;
private boolean mValueSet;
public RangeValuePreference(Context context, String title, String summary, SettingsEnum setting) {
super(context);
this.context = context;
setTitle(title);
setSummary(summary);
setKey(setting.path);
setValue(setting.getString());
}
public void setValue(String value) {
final boolean changed = !TextUtils.equals(mValue, value);
if (changed || !mValueSet) {
mValue = value;
mValueSet = true;
persistString(value);
if (changed) {
notifyDependencyChange(shouldDisableDependents());
notifyChanged();
}
}
}
public String getValue() {
return mValue;
}
@Override
protected View onCreateDialogView() {
minValue = getValue().split("-")[0];
maxValue = getValue().split("-")[1];
LinearLayout dialogView = new LinearLayout(context);
dialogView.setOrientation(LinearLayout.VERTICAL);
LinearLayout minView = new LinearLayout(context);
minView.setOrientation(LinearLayout.HORIZONTAL);
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);
LinearLayout maxView = new LinearLayout(context);
maxView.setOrientation(LinearLayout.HORIZONTAL);
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
public void afterTextChanged(Editable editable) {
minValue = editable.toString();
}
});
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 onPrepareDialogBuilder(AlertDialog.Builder builder) {
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> this.onClick(dialog, DialogInterface.BUTTON_POSITIVE));
builder.setNegativeButton(android.R.string.cancel, null);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
String newValue = minValue + "-" + maxValue;
setValue(newValue);
}
}
}

View File

@ -0,0 +1,17 @@
package app.revanced.tiktok.settingsmenu.preference;
import android.content.Context;
import android.preference.SwitchPreference;
import app.revanced.tiktok.settings.SettingsEnum;
@SuppressWarnings("deprecation")
public class TogglePreference extends SwitchPreference {
public TogglePreference(Context context, String title, String summary, SettingsEnum setting) {
super(context);
this.setTitle(title);
this.setSummary(summary);
this.setKey(setting.path);
this.setChecked(setting.getBoolean());
}
}

View File

@ -0,0 +1,22 @@
package app.revanced.tiktok.settingsmenu.preference.categories;
import android.content.Context;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
@SuppressWarnings("deprecation")
public abstract class ConditionalPreferenceCategory extends PreferenceCategory {
public ConditionalPreferenceCategory(Context context, PreferenceScreen screen) {
super(context);
if (getSettingsStatus()) {
screen.addPreference(this);
addPreferences(context);
}
}
public abstract boolean getSettingsStatus();
public abstract void addPreferences(Context context);
}

View File

@ -0,0 +1,35 @@
package app.revanced.tiktok.settingsmenu.preference.categories;
import android.content.Context;
import android.preference.PreferenceScreen;
import app.revanced.tiktok.settings.SettingsEnum;
import app.revanced.tiktok.settingsmenu.SettingsStatus;
import app.revanced.tiktok.settingsmenu.preference.DownloadPathPreference;
import app.revanced.tiktok.settingsmenu.preference.TogglePreference;
@SuppressWarnings("deprecation")
public class DownloadsPreferenceCategory extends ConditionalPreferenceCategory {
public DownloadsPreferenceCategory(Context context, PreferenceScreen screen) {
super(context, screen);
setTitle("Downloads");
}
@Override
public boolean getSettingsStatus() {
return SettingsStatus.downloadEnabled;
}
@Override
public void addPreferences(Context context) {
addPreference(new DownloadPathPreference(
context,
"Download path",
SettingsEnum.DOWNLOAD_PATH
));
addPreference(new TogglePreference(
context,
"Remove watermark", "",
SettingsEnum.DOWNLOAD_WATERMARK
));
}
}

View File

@ -0,0 +1,55 @@
package app.revanced.tiktok.settingsmenu.preference.categories;
import android.content.Context;
import android.preference.PreferenceScreen;
import app.revanced.tiktok.settings.SettingsEnum;
import app.revanced.tiktok.settingsmenu.SettingsStatus;
import app.revanced.tiktok.settingsmenu.preference.RangeValuePreference;
import app.revanced.tiktok.settingsmenu.preference.TogglePreference;
@SuppressWarnings("deprecation")
public class FeedFilterPreferenceCategory extends ConditionalPreferenceCategory {
public FeedFilterPreferenceCategory(Context context, PreferenceScreen screen) {
super(context, screen);
setTitle("Feed filter");
}
@Override
public boolean getSettingsStatus() {
return SettingsStatus.feedFilterEnabled;
}
@Override
public void addPreferences(Context context) {
addPreference(new TogglePreference(
context,
"Remove feed ads", "Remove ads from feed.",
SettingsEnum.REMOVE_ADS
));
addPreference(new TogglePreference(
context,
"Hide livestreams", "Hide livestreams from feed.",
SettingsEnum.HIDE_LIVE
));
addPreference(new TogglePreference(
context,
"Hide story", "Hide story from feed.",
SettingsEnum.HIDE_STORY
));
addPreference(new TogglePreference(
context,
"Hide image video", "Hide image video from feed.",
SettingsEnum.HIDE_IMAGE
));
addPreference(new RangeValuePreference(
context,
"Min/Max views", "The minimum or maximum views of a video to show.",
SettingsEnum.MIN_MAX_VIEWS
));
addPreference(new RangeValuePreference(
context,
"Min/Max likes", "The minimum or maximum likes of a video to show.",
SettingsEnum.MIN_MAX_LIKES
));
}
}

View File

@ -0,0 +1,28 @@
package app.revanced.tiktok.settingsmenu.preference.categories;
import android.content.Context;
import android.preference.PreferenceScreen;
import app.revanced.tiktok.settings.SettingsEnum;
import app.revanced.tiktok.settingsmenu.preference.TogglePreference;
@SuppressWarnings("deprecation")
public class IntegrationsPreferenceCategory extends ConditionalPreferenceCategory {
public IntegrationsPreferenceCategory(Context context, PreferenceScreen screen) {
super(context, screen);
setTitle("Integrations");
}
@Override
public boolean getSettingsStatus() {
return true;
}
@Override
public void addPreferences(Context context) {
addPreference(new TogglePreference(context,
"Enable debug log",
"Show integration debug log.",
SettingsEnum.DEBUG
));
}
}

View File

@ -0,0 +1,47 @@
package app.revanced.tiktok.settingsmenu.preference.categories;
import android.content.Context;
import android.preference.PreferenceScreen;
import app.revanced.tiktok.settings.SettingsEnum;
import app.revanced.tiktok.settingsmenu.SettingsStatus;
import app.revanced.tiktok.settingsmenu.preference.InputTextPreference;
import app.revanced.tiktok.settingsmenu.preference.TogglePreference;
@SuppressWarnings("deprecation")
public class SimSpoofPreferenceCategory extends ConditionalPreferenceCategory {
public SimSpoofPreferenceCategory(Context context, PreferenceScreen screen) {
super(context, screen);
setTitle("Bypass regional restriction");
}
@Override
public boolean getSettingsStatus() {
return SettingsStatus.simSpoofEnabled;
}
@Override
public void addPreferences(Context context) {
addPreference(new TogglePreference(
context,
"Fake sim card info",
"Bypass regional restriction by fake sim card information.",
SettingsEnum.SIM_SPOOF
));
addPreference(new InputTextPreference(
context,
"Country ISO", "us, uk, jp, ...",
SettingsEnum.SIM_SPOOF_ISO
));
addPreference(new InputTextPreference(
context,
"Operator mcc+mnc", "mcc+mnc",
SettingsEnum.SIMSPOOF_MCCMNC
));
addPreference(new InputTextPreference(
context,
"Operator name", "Name of the operator.",
SettingsEnum.SIMSPOOF_OP_NAME
));
}
}

View File

@ -4,11 +4,11 @@ import app.revanced.tiktok.settings.SettingsEnum;
public class SpoofSimPatch { public class SpoofSimPatch {
public static boolean isEnable() { public static boolean isEnable() {
return SettingsEnum.TIK_SIMSPOOF.getBoolean(); return SettingsEnum.SIM_SPOOF.getBoolean();
} }
public static String getCountryIso(String value) { public static String getCountryIso(String value) {
if (isEnable()) { if (isEnable()) {
return SettingsEnum.TIK_SIMSPOOF_ISO.getString(); return SettingsEnum.SIM_SPOOF_ISO.getString();
} else { } else {
return value; return value;
} }
@ -16,14 +16,14 @@ public class SpoofSimPatch {
} }
public static String getOperator(String value) { public static String getOperator(String value) {
if (isEnable()) { if (isEnable()) {
return SettingsEnum.TIK_SIMSPOOF_MCCMNC.getString(); return SettingsEnum.SIMSPOOF_MCCMNC.getString();
} else { } else {
return value; return value;
} }
} }
public static String getOperatorName(String value) { public static String getOperatorName(String value) {
if (isEnable()) { if (isEnable()) {
return SettingsEnum.TIK_SIMSPOOF_OP_NAME.getString(); return SettingsEnum.SIMSPOOF_OP_NAME.getString();
} else { } else {
return value; return value;
} }

View File

@ -10,7 +10,7 @@ import app.revanced.tiktok.settings.SettingsEnum;
public class LogHelper { public class LogHelper {
public static void debug(Class clazz, String message) { public static void debug(Class clazz, String message) {
if (SettingsEnum.TIK_DEBUG.getBoolean()) { if (SettingsEnum.DEBUG.getBoolean()) {
Log.d("revanced: " + (clazz != null ? clazz.getSimpleName() : ""), message); Log.d("revanced: " + (clazz != null ? clazz.getSimpleName() : ""), message);
} }
} }

View File

@ -1,13 +1,14 @@
package app.revanced.tiktok.utils; package app.revanced.tiktok.utils;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import app.revanced.tiktok.settings.SettingsEnum;
public class ReVancedUtils { public class ReVancedUtils {
//Used by TiktokIntegrations patch @SuppressLint("StaticFieldLeak")
public static Context context; public static Context context;
//Used by TiktokIntegrations patch
public static Context getAppContext() { public static Context getAppContext() {
if (context != null) { if (context != null) {
return context; return context;
@ -15,4 +16,23 @@ public class ReVancedUtils {
LogHelper.printException(ReVancedUtils.class, "Context is null!"); LogHelper.printException(ReVancedUtils.class, "Context is null!");
return null; return null;
} }
public static long[] parseMinMax(SettingsEnum setting) {
if (setting.returnType == SettingsEnum.ReturnType.STRING) {
final String[] minMax = setting.getString().split("-");
if (minMax.length == 2)
try {
final long min = Long.parseLong(minMax[0]);
final long max = Long.parseLong(minMax[1]);
if (min <= max && min >= 0) return new long[]{min, max};
} catch (NumberFormatException ignored) {
}
}
setting.saveValue("0-" + Long.MAX_VALUE);
return new long[]{0L, Long.MAX_VALUE};
}
} }

View File

@ -3,16 +3,34 @@ package com.ss.android.ugc.aweme.feed.model;
//Dummy class //Dummy class
public class Aweme { public class Aweme {
public boolean isAd() { public boolean isAd() {
return true; throw new UnsupportedOperationException("Stub");
}
public boolean isLive() {
return true;
}
public boolean isLiveReplay() {
return true;
}
public boolean isWithPromotionalMusic() {
return true;
} }
public boolean isLive() {
throw new UnsupportedOperationException("Stub");
}
public boolean isLiveReplay() {
throw new UnsupportedOperationException("Stub");
}
public boolean isWithPromotionalMusic() {
throw new UnsupportedOperationException("Stub");
}
public boolean getIsTikTokStory() {
throw new UnsupportedOperationException("Stub");
}
public boolean isImage() {
throw new UnsupportedOperationException("Stub");
}
public boolean isPhotoMode() {
throw new UnsupportedOperationException("Stub");
}
public AwemeStatistics getStatistics() {
throw new UnsupportedOperationException("Stub");
}
} }

View File

@ -0,0 +1,10 @@
package com.ss.android.ugc.aweme.feed.model;
public class AwemeStatistics {
public long getPlayCount() {
throw new UnsupportedOperationException("Stub");
}
public long getDiggCount() {
throw new UnsupportedOperationException("Stub");
}
}