Skip to content

Commit

Permalink
feat: settings patch framework (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 21, 2022
1 parent 29a812f commit 276a2bc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import android.view.View;

import app.revanced.integrations.adremover.AdRemoverAPI;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void setTheme(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;
String preferenceIdentifier;
Expand All @@ -42,10 +42,17 @@ public static void initializeSettings(LicenseActivity base) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;
Expand Down Expand Up @@ -122,25 +121,7 @@ public void onCreate(Bundle bundle) {
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);
Expand Down Expand Up @@ -176,11 +157,6 @@ private Preference findPreferenceOnScreen(CharSequence key) {
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);
Expand Down

0 comments on commit 276a2bc

Please sign in to comment.