This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add
Change share sheet
patch
- Loading branch information
1 parent
645e1e4
commit 0fdeba2
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.../main/java/app/revanced/integrations/youtube/patches/components/ShareSheetMenuFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/app/revanced/integrations/youtube/patches/misc/ShareSheetPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters