feat: settings patch framework (#113)

This commit is contained in:
oSumAtrIX 2022-08-22 01:59:38 +02:00 committed by GitHub
parent 29a812f4e5
commit 276a2bc356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 42 deletions

View File

@ -15,12 +15,10 @@ import app.revanced.integrations.utils.LogHelper;
public class 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) {
return containsLithoAd(value, buffer);
}
@RequiresApi(api = Build.VERSION_CODES.N)
private static boolean containsLithoAd(String value, ByteBuffer buffer) {
boolean enabled = false;
for (SettingsEnum setting : SettingsEnum.getAdRemovalSettings()) {

View File

@ -2,7 +2,6 @@ package app.revanced.integrations.patches;
import android.view.View;
import app.revanced.integrations.adremover.AdRemoverAPI;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
@ -10,9 +9,9 @@ public class HideCreateButtonPatch {
//Used by app.revanced.patches.youtube.layout.createbutton.patch.CreateButtonRemoverPatch
public static void hideCreateButton(View view) {
boolean show = SettingsEnum.CREATE_BUTTON_SHOWN.getBoolean();
String message = show ? "Create button: Shown" : "Create button: Hidden";
boolean enabled = SettingsEnum.CREATE_BUTTON_ENABLED.getBoolean();
String message = "Create button: " + (enabled ? "shown" : "hidden");
LogHelper.debug(HideCreateButtonPatch.class, message);
view.setVisibility(show ? View.VISIBLE : View.GONE);
view.setVisibility(enabled ? View.VISIBLE : View.GONE);
}
}

View File

@ -9,12 +9,12 @@ public class HideHomeAdsPatch {
/**
* Used by package app.revanced.extensions.Extensions
*
* @param view
*/
public static void HideHomeAds(View view) {
if (!SettingsEnum.HOME_ADS_SHOWN.getBoolean()) {
AdRemoverAPI.HideViewWithLayout1dp(view);
}
if (!SettingsEnum.HOME_ADS_HIDDEN.getBoolean()) return;
AdRemoverAPI.HideViewWithLayout1dp(view);
}
}

View File

@ -6,7 +6,7 @@ public class NewActionbarPatch {
//Used by app.revanced.patches.youtube.layout.widesearchbar.patch.WideSearchbarPatch
public static boolean getNewActionBar() {
return SettingsEnum.USE_NEW_ACTIONBAR.getBoolean();
return SettingsEnum.WIDE_SEARCHBAR.getBoolean(); // TODO: maybe this has to be inverted
}
}

View File

@ -8,7 +8,8 @@ public class VideoAdsPatch {
// Used by app.revanced.patches.youtube.ad.general.video.patch.VideoAdsPatch
// depends on Whitelist patch (still needs to be written)
public static boolean shouldShowAds() {
return SettingsEnum.VIDEO_ADS_SHOWN.getBoolean() || Whitelist.shouldShowAds();
return !SettingsEnum.VIDEO_ADS_HIDDEN.getBoolean(); // TODO && Whitelist.shouldShowAds();
}
}

View File

@ -21,8 +21,8 @@ public enum SettingsEnum {
ENABLE_WHITELIST("revanced_whitelist_ads_enabled", false, ReturnType.BOOLEAN),
//Ad settings
HOME_ADS_SHOWN("revanced_home_ads_enabled", false, ReturnType.BOOLEAN, true),
VIDEO_ADS_SHOWN("revanced_video_ads_enabled", false, ReturnType.BOOLEAN, true),
HOME_ADS_HIDDEN("revanced_home_ads_enabled", true, 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_MERCHANDISE_REMOVAL("revanced_adremover_merchandise", 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),
//ToDo: Not used atm, Patch missing
USE_TABLET_MINIPLAYER("revanced_tablet_miniplayer", false, ReturnType.BOOLEAN),
CREATE_BUTTON_SHOWN("revanced_create_button_enabled", false, ReturnType.BOOLEAN, true),
USE_NEW_ACTIONBAR("revanced_new_actionbar", false, ReturnType.BOOLEAN, true),
CREATE_BUTTON_ENABLED("revanced_create_button_enabled", false, ReturnType.BOOLEAN, true),
WIDE_SEARCHBAR("revanced_wide_searchbar", 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

View File

@ -26,7 +26,7 @@ public class ReVancedSettingActivity {
}
public static void initializeSettings(LicenseActivity base) {
base.setContentView(getIdentifier("xsettings_with_toolbar", "layout"));
base.setContentView(getIdentifier("revanced_settings_with_toolbar", "layout"));
PreferenceFragment preferenceFragment;
String preferenceIdentifier;
@ -42,10 +42,17 @@ public class ReVancedSettingActivity {
preferenceIdentifier = "revanced_settings";
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) {
if (viewGroup == null) {
return null;

View File

@ -21,7 +21,6 @@ import android.preference.SwitchPreference;
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
import com.google.android.apps.youtube.app.application.Shell_HomeActivity;
import java.util.ArrayList;
import java.util.List;
import app.revanced.integrations.settings.SettingsEnum;
@ -122,25 +121,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
this.settingsInitialized = sharedPreferences.getBoolean("revanced_initialized", false);
sharedPreferences.registerOnSharedPreferenceChangeListener(this.listener);
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;
} catch (Throwable th) {
LogHelper.printException(ReVancedSettingsFragment.class, "Error during onCreate()", th);
@ -176,11 +157,6 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
return pref;
}
private void setSpeedListPreferenceData(ListPreference listPreference) {
listPreference.setEntries(this.videoSpeedEntries);
listPreference.setEntryValues(this.videoSpeedentryValues);
}
/*
private void setCopyLinkListPreferenceData(ListPreference listPreference, String str) {
listPreference.setEntries(this.buttonLocationEntries);