generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Enable tablet layout
patch
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...app/revanced/patches/youtube/layout/tablet/annotations/EnableTabletLayoutCompatibility.kt
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,8 @@ | ||
package app.revanced.patches.youtube.layout.tablet.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility([Package("com.google.android.youtube")]) | ||
@Target(AnnotationTarget.CLASS) | ||
internal annotation class EnableTabletLayoutCompatibility |
25 changes: 25 additions & 0 deletions
25
...otlin/app/revanced/patches/youtube/layout/tablet/fingerprints/GetFormFactorFingerprint.kt
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,25 @@ | ||
package app.revanced.patches.youtube.layout.tablet.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
object GetFormFactorFingerprint : MethodFingerprint( | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, | ||
returnType = "L", | ||
parameters = listOf("Landroid/content/Context;", "Ljava/util/List;"), | ||
opcodes = listOf( | ||
Opcode.SGET_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IF_EQZ, | ||
Opcode.SGET_OBJECT, | ||
Opcode.RETURN_OBJECT, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.RETURN_OBJECT | ||
) | ||
) |
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/app/revanced/patches/youtube/layout/tablet/patch/EnableTabletLayoutPatch.kt
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,56 @@ | ||
package app.revanced.patches.youtube.layout.tablet.patch | ||
|
||
import app.revanced.extensions.exception | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.util.smali.ExternalLabel | ||
import app.revanced.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.layout.tablet.annotations.EnableTabletLayoutCompatibility | ||
import app.revanced.patches.youtube.layout.tablet.fingerprints.GetFormFactorFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) | ||
@Name("Enable tablet layout") | ||
@Description("Spoofs the device form factor to a tablet which enables the tablet layout.") | ||
@EnableTabletLayoutCompatibility | ||
class EnableTabletLayoutPatch : BytecodePatch(listOf(GetFormFactorFingerprint)) { | ||
override fun execute(context: BytecodeContext) { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_tablet_layout", | ||
StringResource("revanced_tablet_layout_enabled_title", "Enable tablet layout"), | ||
StringResource("revanced_tablet_layout_summary_on", "Tablet layout is enabled"), | ||
StringResource("revanced_tablet_layout_summary_off", "Tablet layout is disabled"), | ||
StringResource("revanced_tablet_layout_user_dialog_message", "Community posts do not show up on tablet layouts") | ||
) | ||
) | ||
|
||
GetFormFactorFingerprint.result?.let { | ||
it.mutableMethod.apply { | ||
val returnLargeFormFactorIndex = it.scanResult.patternScanResult!!.endIndex - 4 | ||
|
||
addInstructionsWithLabels( | ||
0, | ||
""" | ||
invoke-static {}, Lapp/revanced/integrations/patches/EnableTabletLayoutPatch;->enableTabletLayout()Z | ||
move-result v0 | ||
if-nez v0, :is_large_form_factor | ||
""", | ||
ExternalLabel( | ||
"is_large_form_factor", | ||
getInstruction(returnLargeFormFactorIndex) | ||
) | ||
) | ||
} | ||
} ?: GetFormFactorFingerprint.exception | ||
} | ||
} |