Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
feat(YouTube): Add Change share sheet patch
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and Francesco146 committed Aug 16, 2024
1 parent 645e1e4 commit 0fdeba2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app.revanced.integrations.youtube.patches.components;

import androidx.annotation.Nullable;

import app.revanced.integrations.shared.patches.components.Filter;
import app.revanced.integrations.shared.patches.components.StringFilterGroup;
import app.revanced.integrations.youtube.patches.misc.ShareSheetPatch;
import app.revanced.integrations.youtube.settings.Settings;

/**
* Abuse LithoFilter for {@link ShareSheetPatch}.
*/
public final class ShareSheetMenuFilter extends Filter {
// Must be volatile or synchronized, as litho filtering runs off main thread and this field is then access from the main thread.
public static volatile boolean isShareSheetMenuVisible;

public ShareSheetMenuFilter() {
addIdentifierCallbacks(
new StringFilterGroup(
Settings.CHANGE_SHARE_SHEET,
"share_sheet_container.eml"
)
);
}

@Override
public boolean isFiltered(String path, @Nullable String identifier, String allValue, byte[] protobufBufferArray,
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
isShareSheetMenuVisible = true;

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package app.revanced.integrations.youtube.patches.misc;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import app.revanced.integrations.shared.utils.Logger;
import app.revanced.integrations.shared.utils.Utils;
import app.revanced.integrations.youtube.patches.components.ShareSheetMenuFilter;
import app.revanced.integrations.youtube.settings.Settings;

@SuppressWarnings("unused")
public class ShareSheetPatch {
private static final boolean changeShareSheetEnabled = Settings.CHANGE_SHARE_SHEET.get();

/**
* Injection point.
*/
public static void onShareSheetMenuCreate(final RecyclerView recyclerView) {
if (!changeShareSheetEnabled)
return;

recyclerView.getViewTreeObserver().addOnDrawListener(() -> {
try {
if (ShareSheetMenuFilter.isShareSheetMenuVisible &&
recyclerView.getChildAt(0) instanceof ViewGroup parentView4th &&
parentView4th.getChildAt(0) instanceof ViewGroup parentView3rd &&
parentView3rd.getChildAt(0) instanceof ViewGroup parentView2nd &&
parentView2nd.getChildAt(parentView2nd.getChildCount() - 1) instanceof ViewGroup parentView &&
parentView.getChildAt(0) instanceof ViewGroup shareWithOtherAppsView
) {
ShareSheetMenuFilter.isShareSheetMenuVisible = false;

recyclerView.setVisibility(View.GONE);
Utils.clickView(shareWithOtherAppsView);
}
} catch (Exception ex) {
Logger.printException(() -> "onShareSheetMenuCreate failure", ex);
}
});
}

/**
* Injection point.
*/
public static String overridePackageName(String original) {
return changeShareSheetEnabled ? "" : original;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ public class Settings extends BaseSettings {

public static final EnumSetting<WatchHistoryType> WATCH_HISTORY_TYPE = new EnumSetting<>("revanced_watch_history_type", WatchHistoryType.REPLACE);

public static final BooleanSetting CHANGE_SHARE_SHEET = new BooleanSetting("revanced_change_share_sheet", FALSE, true);
public static final BooleanSetting ENABLE_OPUS_CODEC = new BooleanSetting("revanced_enable_opus_codec", FALSE, true);

@Deprecated
Expand Down

0 comments on commit 0fdeba2

Please sign in to comment.