Skip to content

Commit

Permalink
feat(YouTube - Alternative Thumbnails): Add option to use DeArrow (#3378
Browse files Browse the repository at this point in the history
)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 11, 2023
1 parent 314f843 commit 41217f6
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 71 deletions.
5 changes: 3 additions & 2 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,9 @@ public final class app/revanced/patches/shared/settings/preference/impl/ListPref
}

public final class app/revanced/patches/shared/settings/preference/impl/NonInteractivePreference : app/revanced/patches/shared/settings/preference/BasePreference {
public fun <init> (Lapp/revanced/patches/shared/settings/preference/impl/StringResource;Lapp/revanced/patches/shared/settings/preference/impl/StringResource;)V
public fun <init> (Lapp/revanced/patches/shared/settings/preference/impl/StringResource;Lapp/revanced/patches/shared/settings/preference/impl/StringResource;Ljava/lang/String;Z)V
public synthetic fun <init> (Lapp/revanced/patches/shared/settings/preference/impl/StringResource;Lapp/revanced/patches/shared/settings/preference/impl/StringResource;Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getSelectable ()Z
public fun serialize (Lorg/w3c/dom/Document;Lkotlin/jvm/functions/Function1;)Lorg/w3c/dom/Element;
}

Expand Down Expand Up @@ -1363,7 +1365,6 @@ public final class app/revanced/patches/youtube/layout/theme/ThemeBytecodePatch

public final class app/revanced/patches/youtube/layout/thumbnails/AlternativeThumbnailsPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/youtube/layout/thumbnails/AlternativeThumbnailsPatch;
public final fun addImageUrlErrorCallbackHook (Ljava/lang/String;)V
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.w3c.dom.Element
*
* @param key The key of the preference.
* @param title The title of the preference.
* @param tag The tag of the preference.
* @param tag The full class name for the preference.
* @param summary The summary of the preference.
*/
abstract class BasePreference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ import org.w3c.dom.Element
*
* @param title The title of the preference.
* @param summary The summary of the text preference.
* @param selectable If this preference responds to tapping.
* Setting to 'true' restores the horizontal dividers on the top and bottom,
* but tapping will still do nothing since this Preference has no key.
*/
class NonInteractivePreference(
title: StringResource,
summary: StringResource,
) : BasePreference(null, title, summary, "Preference") {
summary: StringResource?,
tag: String = "Preference",
// If androidx.preference is later used, this can be changed to the show top/bottom dividers feature.
val selectable: Boolean = false
) : BasePreference(null, title, summary, tag) {
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit): Element {
return super.serialize(ownerDocument, resourceCallback).apply {
addSummary(summary?.also { resourceCallback.invoke(it)
setAttribute("android:selectable", false.toString())
setAttribute("android:selectable", selectable.toString())
})
}
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.revanced.patches.youtube.layout.thumbnails

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.util.mergeStrings

@Patch(
dependencies = [SettingsPatch::class]
)
internal object AlternativeThumbnailsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
context.mergeStrings("alternativethumbnails/host/values/strings.xml")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.revanced.patches.youtube.layout.thumbnails.fingerprints.cronet

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.layout.thumbnails.fingerprints.cronet.RequestFingerprint.IMPLEMENTATION_CLASS_NAME
import com.android.tools.smali.dexlib2.AccessFlags

internal object RequestFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { _, classDef ->
classDef.type == IMPLEMENTATION_CLASS_NAME
}
) {
const val IMPLEMENTATION_CLASS_NAME = "Lorg/chromium/net/impl/CronetUrlRequest;"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package app.revanced.patches.youtube.layout.thumbnails.fingerprints
package app.revanced.patches.youtube.layout.thumbnails.fingerprints.cronet.request.callback

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal object CronetURLRequestCallbackOnFailureFingerprint : MethodFingerprint(
internal object OnFailureFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Lorg/chromium/net/UrlRequest;", "Lorg/chromium/net/UrlResponseInfo;", "Lorg/chromium/net/CronetException;"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package app.revanced.patches.youtube.layout.thumbnails.fingerprints
package app.revanced.patches.youtube.layout.thumbnails.fingerprints.cronet.request.callback

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

// Acts as a parent fingerprint.
internal object CronetURLRequestCallbackOnResponseStartedFingerprint : MethodFingerprint(
internal object OnResponseStartedFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Lorg/chromium/net/UrlRequest;", "Lorg/chromium/net/UrlResponseInfo;"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package app.revanced.patches.youtube.layout.thumbnails.fingerprints
package app.revanced.patches.youtube.layout.thumbnails.fingerprints.cronet.request.callback

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal object CronetURLRequestCallbackOnSucceededFingerprint : MethodFingerprint(
internal object OnSucceededFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Lorg/chromium/net/UrlRequest;", "Lorg/chromium/net/UrlResponseInfo;"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<resources>
<string name="revanced_alt_thumbnail_about_status_disabled">Showing original YouTube thumbnails</string>
<string name="revanced_alt_thumbnail_about_status_stills">Showing still video captures</string>
<string name="revanced_alt_thumbnail_about_status_dearrow">Showing DeArrow thumbnails. If a video has no DeArrow thumbnails then the original YouTube thumbnails are shown</string>
<string name="revanced_alt_thumbnail_about_status_dearrow_stills">Showing DeArrow thumbnails. If a video has no DeArrow thumbnails then still video captures are shown</string>

<string name="revanced_alt_thumbnail_dearrow_error">DeArrow temporarily not available (status code: %s)</string>
<string name="revanced_alt_thumbnail_dearrow_error_generic">DeArrow temporarily not available</string>
</resources>

0 comments on commit 41217f6

Please sign in to comment.