mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-05 17:45:49 +01:00
feat(tiktok): adapt tiktok-download
with tiktok-settings
. (#152)
This commit is contained in:
parent
fd924ad934
commit
5a710aa033
@ -0,0 +1,13 @@
|
||||
package app.revanced.tiktok.download;
|
||||
|
||||
import app.revanced.tiktok.settings.SettingsEnum;
|
||||
|
||||
public class DownloadsPatch {
|
||||
public static String getDownloadPath() {
|
||||
return SettingsEnum.TIK_DOWN_PATH.getString();
|
||||
}
|
||||
|
||||
public static boolean shouldRemoveWatermark() {
|
||||
return SettingsEnum.TIK_DOWN_WATERMARK.getBoolean();
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ public enum SettingsEnum {
|
||||
//TikTok Settings
|
||||
TIK_REMOVE_ADS("tik-remove-ads", true, SharedPrefHelper.SharedPrefNames.TIKTOK_PREFS, ReturnType.BOOLEAN, true),
|
||||
TIK_HIDE_LIVE("tik-hide-live", false, SharedPrefHelper.SharedPrefNames.TIKTOK_PREFS, ReturnType.BOOLEAN, true),
|
||||
TIK_DOWN_PATH("tik-down-path", "DCIM/TikTok", SharedPrefHelper.SharedPrefNames.TIKTOK_PREFS, ReturnType.STRING),
|
||||
TIK_DOWN_WATERMARK("tik-down-watermark", true, SharedPrefHelper.SharedPrefNames.TIKTOK_PREFS, ReturnType.BOOLEAN),
|
||||
TIK_DEBUG("tik_debug", false, SharedPrefHelper.SharedPrefNames.TIKTOK_PREFS, ReturnType.BOOLEAN);
|
||||
|
||||
static {
|
||||
|
@ -8,6 +8,7 @@ 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.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
@ -19,6 +20,7 @@ import androidx.annotation.Nullable;
|
||||
import com.ss.android.ugc.aweme.splash.SplashActivity;
|
||||
|
||||
import app.revanced.tiktok.settings.SettingsEnum;
|
||||
import app.revanced.tiktok.settingsmenu.preference.DownloadPathPreference;
|
||||
import app.revanced.tiktok.utils.ReVancedUtils;
|
||||
import app.revanced.tiktok.utils.SharedPrefHelper;
|
||||
|
||||
@ -86,6 +88,42 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
||||
}
|
||||
}
|
||||
|
||||
//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.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.TIK_DOWN_PATH.getDefaultValue());
|
||||
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.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.TIK_DOWN_WATERMARK.getDefaultValue());
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//Integration
|
||||
PreferenceCategory integration = new PreferenceCategory(context);
|
||||
integration.setTitle("Integration");
|
||||
|
@ -2,9 +2,16 @@ package app.revanced.tiktok.settingsmenu;
|
||||
|
||||
public class SettingsStatus {
|
||||
public static boolean feedFilter = false;
|
||||
public static boolean download = false;
|
||||
|
||||
public static void enableFeedFilter() {
|
||||
feedFilter = true;
|
||||
}
|
||||
|
||||
public static void enableDownload() {
|
||||
download = true;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,108 @@
|
||||
package app.revanced.tiktok.settingsmenu.preference;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Environment;
|
||||
import android.preference.DialogPreference;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
public class DownloadPathPreference extends DialogPreference {
|
||||
private final Context context;
|
||||
private final String[] entryValues = {"DCIM", "Movies", "Pictures"};
|
||||
private String value;
|
||||
private int mediaPathIndex;
|
||||
private String childDownloadPath;
|
||||
|
||||
public DownloadPathPreference(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
String currentMedia = getValue().split("/")[0];
|
||||
childDownloadPath = getValue().substring(getValue().indexOf("/") + 1);
|
||||
|
||||
mediaPathIndex = findIndexOf(currentMedia);
|
||||
|
||||
LinearLayout dialogView = new LinearLayout(context);
|
||||
RadioGroup mediaPath = new RadioGroup(context);
|
||||
mediaPath.setLayoutParams(new RadioGroup.LayoutParams(-1, -2));
|
||||
for (String entryValue : entryValues) {
|
||||
RadioButton radioButton = new RadioButton(context);
|
||||
radioButton.setText(entryValue);
|
||||
radioButton.setId(View.generateViewId());
|
||||
mediaPath.addView(radioButton);
|
||||
}
|
||||
mediaPath.setOnCheckedChangeListener((radioGroup, id) -> {
|
||||
RadioButton radioButton = radioGroup.findViewById(id);
|
||||
mediaPathIndex = findIndexOf(radioButton.getText().toString());
|
||||
});
|
||||
mediaPath.check(mediaPath.getChildAt(mediaPathIndex).getId());
|
||||
EditText downloadPath = new EditText(context);
|
||||
downloadPath.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
downloadPath.setText(childDownloadPath);
|
||||
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
|
||||
public void afterTextChanged(Editable editable) {
|
||||
childDownloadPath = editable.toString();
|
||||
}
|
||||
});
|
||||
dialogView.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
|
||||
dialogView.setOrientation(LinearLayout.VERTICAL);
|
||||
dialogView.addView(mediaPath);
|
||||
dialogView.addView(downloadPath);
|
||||
return dialogView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
builder.setTitle("Download Path");
|
||||
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 && mediaPathIndex >= 0) {
|
||||
String newValue = entryValues[mediaPathIndex] + "/" + childDownloadPath;
|
||||
if (callChangeListener(newValue)) {
|
||||
setValue(newValue);
|
||||
setSummary(Environment.getExternalStorageDirectory().getPath() + "/" + newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int findIndexOf(String str) {
|
||||
for (int i = 0; i < entryValues.length; i++) {
|
||||
if (str.equals(entryValues[i])) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user