mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-07 20:57:02 +01:00
feat: settings
patch framework (#113)
This commit is contained in:
parent
29a812f4e5
commit
276a2bc356
@ -15,12 +15,10 @@ import app.revanced.integrations.utils.LogHelper;
|
|||||||
public class GeneralBytecodeAdsPatch {
|
public class GeneralBytecodeAdsPatch {
|
||||||
|
|
||||||
//Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
|
//Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
||||||
public static boolean containsAd(String value, ByteBuffer buffer) {
|
public static boolean containsAd(String value, ByteBuffer buffer) {
|
||||||
return containsLithoAd(value, buffer);
|
return containsLithoAd(value, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
||||||
private static boolean containsLithoAd(String value, ByteBuffer buffer) {
|
private static boolean containsLithoAd(String value, ByteBuffer buffer) {
|
||||||
boolean enabled = false;
|
boolean enabled = false;
|
||||||
for (SettingsEnum setting : SettingsEnum.getAdRemovalSettings()) {
|
for (SettingsEnum setting : SettingsEnum.getAdRemovalSettings()) {
|
||||||
|
@ -2,7 +2,6 @@ package app.revanced.integrations.patches;
|
|||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import app.revanced.integrations.adremover.AdRemoverAPI;
|
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
|
||||||
@ -10,9 +9,9 @@ public class HideCreateButtonPatch {
|
|||||||
|
|
||||||
//Used by app.revanced.patches.youtube.layout.createbutton.patch.CreateButtonRemoverPatch
|
//Used by app.revanced.patches.youtube.layout.createbutton.patch.CreateButtonRemoverPatch
|
||||||
public static void hideCreateButton(View view) {
|
public static void hideCreateButton(View view) {
|
||||||
boolean show = SettingsEnum.CREATE_BUTTON_SHOWN.getBoolean();
|
boolean enabled = SettingsEnum.CREATE_BUTTON_ENABLED.getBoolean();
|
||||||
String message = show ? "Create button: Shown" : "Create button: Hidden";
|
String message = "Create button: " + (enabled ? "shown" : "hidden");
|
||||||
LogHelper.debug(HideCreateButtonPatch.class, message);
|
LogHelper.debug(HideCreateButtonPatch.class, message);
|
||||||
view.setVisibility(show ? View.VISIBLE : View.GONE);
|
view.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ public class HideHomeAdsPatch {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by package app.revanced.extensions.Extensions
|
* Used by package app.revanced.extensions.Extensions
|
||||||
|
*
|
||||||
* @param view
|
* @param view
|
||||||
*/
|
*/
|
||||||
public static void HideHomeAds(View view) {
|
public static void HideHomeAds(View view) {
|
||||||
if (!SettingsEnum.HOME_ADS_SHOWN.getBoolean()) {
|
if (!SettingsEnum.HOME_ADS_HIDDEN.getBoolean()) return;
|
||||||
AdRemoverAPI.HideViewWithLayout1dp(view);
|
AdRemoverAPI.HideViewWithLayout1dp(view);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ public class NewActionbarPatch {
|
|||||||
|
|
||||||
//Used by app.revanced.patches.youtube.layout.widesearchbar.patch.WideSearchbarPatch
|
//Used by app.revanced.patches.youtube.layout.widesearchbar.patch.WideSearchbarPatch
|
||||||
public static boolean getNewActionBar() {
|
public static boolean getNewActionBar() {
|
||||||
return SettingsEnum.USE_NEW_ACTIONBAR.getBoolean();
|
return SettingsEnum.WIDE_SEARCHBAR.getBoolean(); // TODO: maybe this has to be inverted
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@ public class VideoAdsPatch {
|
|||||||
// Used by app.revanced.patches.youtube.ad.general.video.patch.VideoAdsPatch
|
// Used by app.revanced.patches.youtube.ad.general.video.patch.VideoAdsPatch
|
||||||
// depends on Whitelist patch (still needs to be written)
|
// depends on Whitelist patch (still needs to be written)
|
||||||
public static boolean shouldShowAds() {
|
public static boolean shouldShowAds() {
|
||||||
return SettingsEnum.VIDEO_ADS_SHOWN.getBoolean() || Whitelist.shouldShowAds();
|
return !SettingsEnum.VIDEO_ADS_HIDDEN.getBoolean(); // TODO && Whitelist.shouldShowAds();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ public enum SettingsEnum {
|
|||||||
ENABLE_WHITELIST("revanced_whitelist_ads_enabled", false, ReturnType.BOOLEAN),
|
ENABLE_WHITELIST("revanced_whitelist_ads_enabled", false, ReturnType.BOOLEAN),
|
||||||
|
|
||||||
//Ad settings
|
//Ad settings
|
||||||
HOME_ADS_SHOWN("revanced_home_ads_enabled", false, ReturnType.BOOLEAN, true),
|
HOME_ADS_HIDDEN("revanced_home_ads_enabled", true, ReturnType.BOOLEAN, true),
|
||||||
VIDEO_ADS_SHOWN("revanced_video_ads_enabled", false, ReturnType.BOOLEAN, true),
|
VIDEO_ADS_HIDDEN("revanced_video_ads_enabled", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_AD_REMOVAL("revanced_adremover_ad_removal", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_AD_REMOVAL("revanced_adremover_ad_removal", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_MERCHANDISE_REMOVAL("revanced_adremover_merchandise", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_MERCHANDISE_REMOVAL("revanced_adremover_merchandise", true, ReturnType.BOOLEAN, true),
|
||||||
ADREMOVER_COMMUNITY_POSTS_REMOVAL("revanced_adremover_community_posts_removal", true, ReturnType.BOOLEAN, true),
|
ADREMOVER_COMMUNITY_POSTS_REMOVAL("revanced_adremover_community_posts_removal", true, ReturnType.BOOLEAN, true),
|
||||||
@ -49,8 +49,8 @@ public enum SettingsEnum {
|
|||||||
AUTOPLAY_BUTTON_SHOWN("revanced_autoplay_button_enabled", false, ReturnType.BOOLEAN, true),
|
AUTOPLAY_BUTTON_SHOWN("revanced_autoplay_button_enabled", false, ReturnType.BOOLEAN, true),
|
||||||
//ToDo: Not used atm, Patch missing
|
//ToDo: Not used atm, Patch missing
|
||||||
USE_TABLET_MINIPLAYER("revanced_tablet_miniplayer", false, ReturnType.BOOLEAN),
|
USE_TABLET_MINIPLAYER("revanced_tablet_miniplayer", false, ReturnType.BOOLEAN),
|
||||||
CREATE_BUTTON_SHOWN("revanced_create_button_enabled", false, ReturnType.BOOLEAN, true),
|
CREATE_BUTTON_ENABLED("revanced_create_button_enabled", false, ReturnType.BOOLEAN, true),
|
||||||
USE_NEW_ACTIONBAR("revanced_new_actionbar", false, ReturnType.BOOLEAN, true),
|
WIDE_SEARCHBAR("revanced_wide_searchbar", false, ReturnType.BOOLEAN, true),
|
||||||
SHORTS_BUTTON_SHOWN("revanced_shorts_button_enabled", false, ReturnType.BOOLEAN, true),
|
SHORTS_BUTTON_SHOWN("revanced_shorts_button_enabled", false, ReturnType.BOOLEAN, true),
|
||||||
FULLSCREEN_PANELS_SHOWN("revanced_fullscreen_panels_enabled", false, ReturnType.BOOLEAN), //ToDo: Add to prefs
|
FULLSCREEN_PANELS_SHOWN("revanced_fullscreen_panels_enabled", false, ReturnType.BOOLEAN), //ToDo: Add to prefs
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class ReVancedSettingActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void initializeSettings(LicenseActivity base) {
|
public static void initializeSettings(LicenseActivity base) {
|
||||||
base.setContentView(getIdentifier("xsettings_with_toolbar", "layout"));
|
base.setContentView(getIdentifier("revanced_settings_with_toolbar", "layout"));
|
||||||
|
|
||||||
PreferenceFragment preferenceFragment;
|
PreferenceFragment preferenceFragment;
|
||||||
String preferenceIdentifier;
|
String preferenceIdentifier;
|
||||||
@ -42,10 +42,17 @@ public class ReVancedSettingActivity {
|
|||||||
preferenceIdentifier = "revanced_settings";
|
preferenceIdentifier = "revanced_settings";
|
||||||
preferenceFragment = new ReVancedSettingsFragment();
|
preferenceFragment = new ReVancedSettingsFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
base.getFragmentManager().beginTransaction().replace(getIdentifier("xsettings_fragments", "id"), preferenceFragment).commit();
|
try {
|
||||||
|
getTextView((ViewGroup) base.findViewById(getIdentifier("toolbar", "id"))).setText(preferenceIdentifier);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogHelper.printException(ReVancedSettingActivity.class, "Couldn't set Toolbar title", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.getFragmentManager().beginTransaction().replace(getIdentifier("revanced_settings_fragments", "id"), preferenceFragment).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <T extends View> T getView(Class<T> typeClass, ViewGroup viewGroup) {
|
public static <T extends View> T getView(Class<T> typeClass, ViewGroup viewGroup) {
|
||||||
if (viewGroup == null) {
|
if (viewGroup == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -21,7 +21,6 @@ import android.preference.SwitchPreference;
|
|||||||
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
||||||
import com.google.android.apps.youtube.app.application.Shell_HomeActivity;
|
import com.google.android.apps.youtube.app.application.Shell_HomeActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
@ -122,25 +121,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
|||||||
this.settingsInitialized = sharedPreferences.getBoolean("revanced_initialized", false);
|
this.settingsInitialized = sharedPreferences.getBoolean("revanced_initialized", false);
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this.listener);
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this.listener);
|
||||||
this.Registered = true;
|
this.Registered = true;
|
||||||
this.screens = new ArrayList<>();
|
|
||||||
this.screens.add((PreferenceScreen) getPreferenceScreen().findPreference("video_settings"));
|
|
||||||
this.screens.add((PreferenceScreen) getPreferenceScreen().findPreference("video_ad_settings"));
|
|
||||||
this.screens.add((PreferenceScreen) getPreferenceScreen().findPreference("ad_settings"));
|
|
||||||
this.screens.add((PreferenceScreen) getPreferenceScreen().findPreference("layout_settings"));
|
|
||||||
this.screens.add((PreferenceScreen) getPreferenceScreen().findPreference("buffer_screen"));
|
|
||||||
this.screens.add((PreferenceScreen) getPreferenceScreen().findPreference("misc_screen"));
|
|
||||||
this.screens.add((PreferenceScreen) getPreferenceScreen().findPreference("swipe_screen"));
|
|
||||||
|
|
||||||
|
|
||||||
final ListPreference listPreference3 = (ListPreference) screens.get(1).findPreference("revanced_pref_video_speed");
|
|
||||||
setSpeedListPreferenceData(listPreference3);
|
|
||||||
|
|
||||||
listPreference3.setOnPreferenceClickListener(preference -> {
|
|
||||||
setSpeedListPreferenceData(listPreference3);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
sharedPreferences.edit().putBoolean("revanced_initialized", true);
|
|
||||||
this.settingsInitialized = true;
|
this.settingsInitialized = true;
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
LogHelper.printException(ReVancedSettingsFragment.class, "Error during onCreate()", th);
|
LogHelper.printException(ReVancedSettingsFragment.class, "Error during onCreate()", th);
|
||||||
@ -176,11 +157,6 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
|||||||
return pref;
|
return pref;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSpeedListPreferenceData(ListPreference listPreference) {
|
|
||||||
listPreference.setEntries(this.videoSpeedEntries);
|
|
||||||
listPreference.setEntryValues(this.videoSpeedentryValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
private void setCopyLinkListPreferenceData(ListPreference listPreference, String str) {
|
private void setCopyLinkListPreferenceData(ListPreference listPreference, String str) {
|
||||||
listPreference.setEntries(this.buttonLocationEntries);
|
listPreference.setEntries(this.buttonLocationEntries);
|
||||||
|
Loading…
Reference in New Issue
Block a user