generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
250 additions
and
297 deletions.
There are no files selected for viewing
Empty file.
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
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
23 changes: 23 additions & 0 deletions
23
...ations/java/app/revanced/integrations/patches/components/VideoQualityMenuFilterPatch.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,23 @@ | ||
package app.revanced.integrations.patches.components; | ||
|
||
import app.revanced.integrations.settings.SettingsEnum; | ||
|
||
// Abuse LithoFilter for OldVideoQualityMenuPatch. | ||
public final class VideoQualityMenuFilterPatch 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 isVideoQualityMenuVisible; | ||
|
||
public VideoQualityMenuFilterPatch() { | ||
pathFilterGroups.addAll(new StringFilterGroup( | ||
SettingsEnum.SHOW_OLD_VIDEO_QUALITY_MENU, | ||
"quick_quality_sheet_content.eml-js" | ||
)); | ||
} | ||
|
||
@Override | ||
boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) { | ||
isVideoQualityMenuVisible = super.isFiltered(path, identifier, protobufBufferArray); | ||
|
||
return false; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...grations/java/app/revanced/integrations/patches/components/VideoSpeedMenuFilterPatch.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,21 @@ | ||
package app.revanced.integrations.patches.components; | ||
|
||
// Abuse LithoFilter for CustomVideoSpeedPatch. | ||
public final class VideoSpeedMenuFilterPatch 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 isVideoSpeedMenuVisible; | ||
|
||
public VideoSpeedMenuFilterPatch() { | ||
pathFilterGroups.addAll(new StringFilterGroup( | ||
null, | ||
"playback_speed_sheet_content.eml-js" | ||
)); | ||
} | ||
|
||
@Override | ||
boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) { | ||
isVideoSpeedMenuVisible = super.isFiltered(path, identifier, protobufBufferArray); | ||
|
||
return false; | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
...ations/java/app/revanced/integrations/patches/playback/quality/OldQualityLayoutPatch.java
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
...ons/java/app/revanced/integrations/patches/playback/quality/OldVideoQualityMenuPatch.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,94 @@ | ||
package app.revanced.integrations.patches.playback.quality; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.ViewTreeObserver; | ||
import android.widget.LinearLayout; | ||
import android.widget.ListView; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import app.revanced.integrations.patches.components.VideoQualityMenuFilterPatch; | ||
import app.revanced.integrations.settings.SettingsEnum; | ||
import app.revanced.integrations.utils.LogHelper; | ||
import com.facebook.litho.ComponentHost; | ||
import kotlin.Deprecated; | ||
|
||
// This patch contains the logic to show the old video quality menu. | ||
// Two methods are required, because the quality menu is a RecyclerView in the new YouTube version | ||
// and a ListView in the old one. | ||
public final class OldVideoQualityMenuPatch { | ||
|
||
public static void onFlyoutMenuCreate(final LinearLayout linearLayout) { | ||
if (!SettingsEnum.SHOW_OLD_VIDEO_QUALITY_MENU.getBoolean()) return; | ||
|
||
// The quality menu is a RecyclerView with 3 children. The third child is the "Advanced" quality menu. | ||
addRecyclerListener(linearLayout, 3, 2, recyclerView -> { | ||
// Check if the current view is the quality menu. | ||
if (VideoQualityMenuFilterPatch.isVideoQualityMenuVisible) {// Hide the video quality menu. | ||
linearLayout.setVisibility(View.GONE); | ||
|
||
// Click the "Advanced" quality menu to show the "old" quality menu. | ||
((ComponentHost) recyclerView.getChildAt(0)).getChildAt(3).performClick(); | ||
LogHelper.printDebug(() -> "Advanced quality menu in new type of quality menu clicked"); | ||
} | ||
}); | ||
} | ||
|
||
public static void addRecyclerListener(@NonNull LinearLayout linearLayout, | ||
int expectedLayoutChildCount, int recyclerViewIndex, | ||
@NonNull RecyclerViewGlobalLayoutListener listener) { | ||
if (linearLayout.getChildCount() != expectedLayoutChildCount) return; | ||
|
||
var layoutChild = linearLayout.getChildAt(recyclerViewIndex); | ||
if (!(layoutChild instanceof RecyclerView)) return; | ||
final var recyclerView = (RecyclerView) layoutChild; | ||
|
||
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener( | ||
new ViewTreeObserver.OnGlobalLayoutListener() { | ||
@Override | ||
public void onGlobalLayout() { | ||
try { | ||
listener.recyclerOnGlobalLayout(recyclerView); | ||
} catch (Exception ex) { | ||
LogHelper.printException(() -> "addRecyclerListener failure", ex); | ||
} finally { | ||
// Remove the listener because it will be added again. | ||
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
public interface RecyclerViewGlobalLayoutListener { | ||
void recyclerOnGlobalLayout(@NonNull RecyclerView recyclerView); | ||
} | ||
|
||
@Deprecated(message = "This patch is deprecated because the quality menu is not a ListView anymore") | ||
public static void showOldVideoQualityMenu(final ListView listView) { | ||
if (!SettingsEnum.SHOW_OLD_VIDEO_QUALITY_MENU.getBoolean()) return; | ||
|
||
listView.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() { | ||
@Override | ||
public void onChildViewAdded(View parent, View child) { | ||
LogHelper.printDebug(() -> "Added listener to old type of quality menu"); | ||
|
||
parent.setVisibility(View.GONE); | ||
|
||
final var indexOfAdvancedQualityMenuItem = 4; | ||
if (listView.indexOfChild(child) != indexOfAdvancedQualityMenuItem) return; | ||
|
||
LogHelper.printDebug(() -> "Found advanced menu item in old type of quality menu"); | ||
|
||
final var qualityItemMenuPosition = 4; | ||
listView.performItemClick(null, qualityItemMenuPosition, 0); | ||
} | ||
|
||
@Override | ||
public void onChildViewRemoved(View parent, View child) { | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.