fix(YouTube - ReturnYouTubeDislike): Improve layout padding (#3291)

This commit is contained in:
LisoUseInAIKyrios 2023-11-18 21:10:43 +02:00 committed by GitHub
parent 4704943c5c
commit 630b067b18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 1 deletions

View file

@ -55,7 +55,8 @@ object ReturnYouTubeDislikePatch : BytecodePatch(
DislikeFingerprint,
RemoveLikeFingerprint,
RollingNumberSetterFingerprint,
RollingNumberTextViewFingerprint
RollingNumberTextViewFingerprint,
RollingNumberMeasureTextParentFingerprint
)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
@ -181,6 +182,31 @@ object ReturnYouTubeDislikePatch : BytecodePatch(
}
} ?: throw RollingNumberSetterFingerprint.exception
// Rolling Number text views use the measured width of the raw string for layout.
// Modify the measure text calculation to include the left drawable separator if needed.
RollingNumberMeasureTextFingerprint.also {
if (!it.resolve(context, RollingNumberMeasureTextParentFingerprint.result!!.classDef))
throw it.exception
}.result?.also {
it.mutableMethod.apply {
val returnInstructionIndex = it.scanResult.patternScanResult!!.endIndex
val measuredTextWidthRegister =
getInstruction<OneRegisterInstruction>(returnInstructionIndex).registerA
replaceInstruction( // Replace instruction to preserve control flow label.
returnInstructionIndex,
"invoke-static {p1, v$measuredTextWidthRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->onRollingNumberMeasured(Ljava/lang/String;F)F"
)
addInstructions(
returnInstructionIndex + 1,
"""
move-result v$measuredTextWidthRegister
return v$measuredTextWidthRegister
"""
)
}
} ?: throw RollingNumberMeasureTextFingerprint.exception
// The rolling number Span is missing styling since it's initially set as a String.
// Modify the UI text view and use the styled like/dislike Span.
RollingNumberTextViewFingerprint.result?.let {

View file

@ -0,0 +1,23 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
/**
* Resolves to class found in [RollingNumberMeasureTextParentFingerprint].
*/
object RollingNumberMeasureTextFingerprint : MethodFingerprint(
returnType = "F",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Ljava/lang/String;"),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.ADD_FLOAT_2ADDR,
Opcode.ADD_INT_LIT8,
Opcode.GOTO,
Opcode.RETURN
)
)

View file

@ -0,0 +1,12 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
object RollingNumberMeasureTextParentFingerprint : MethodFingerprint(
returnType = "Ljava/lang/String;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
strings = listOf("RollingNumberFontProperties{paint=")
)