revanced-patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockResourcePatch.kt

107 lines
4.0 KiB
Kotlin
Raw Normal View History

package app.revanced.patches.youtube.layout.sponsorblock
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.all.misc.resources.AddResourcesPatch
import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch
import app.revanced.patches.shared.misc.settings.preference.IntentPreference
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.patches.youtube.misc.settings.SettingsResourcePatch
2023-12-02 22:35:13 +01:00
import app.revanced.util.ResourceGroup
import app.revanced.util.copyResources
import app.revanced.util.copyXmlNode
import app.revanced.util.inputStreamFromBundledResource
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
@Patch(
dependencies = [
SettingsPatch::class,
ResourceMappingPatch::class,
AddResourcesPatch::class,
],
)
2023-12-02 22:35:13 +01:00
internal object SponsorBlockResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)
SettingsResourcePatch += IntentPreference(
key = "revanced_settings_screen_10",
titleKey = "revanced_sb_settings_title",
summaryKey = null,
intent = SettingsPatch.newIntent("revanced_sb_settings_intent")
)
arrayOf(
2023-12-02 22:35:13 +01:00
ResourceGroup(
"layout",
"revanced_sb_inline_sponsor_overlay.xml",
"revanced_sb_new_segment.xml",
"revanced_sb_skip_sponsor_button.xml",
),
2023-12-02 22:35:13 +01:00
ResourceGroup(
// required resource for back button, because when the base APK is used, this resource will not exist
"drawable",
"revanced_sb_adjust.xml",
"revanced_sb_compare.xml",
"revanced_sb_edit.xml",
"revanced_sb_logo.xml",
"revanced_sb_publish.xml",
"revanced_sb_voting.xml",
),
2023-12-02 22:35:13 +01:00
ResourceGroup(
// required resource for back button, because when the base APK is used, this resource will not exist
"drawable-xxxhdpi",
"quantum_ic_skip_next_white_24.png",
),
).forEach { resourceGroup ->
context.copyResources("sponsorblock", resourceGroup)
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
}
// copy nodes from host resources to their real xml files
val hostingResourceStream =
inputStreamFromBundledResource(
"sponsorblock",
"host/layout/youtube_controls_layout.xml",
)!!
var modifiedControlsLayout = false
val editor = context.xmlEditor["res/layout/youtube_controls_layout.xml"]
"RelativeLayout".copyXmlNode(
context.xmlEditor[hostingResourceStream],
editor,
).also {
val document = editor.file
val children = document.getElementsByTagName("RelativeLayout").item(0).childNodes
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
// Replace the startOf with the voting button view so that the button does not overlap
for (i in 1 until children.length) {
val view = children.item(i)
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
// Replace the attribute for a specific node only
if (!(
view.hasAttributes() &&
view.attributes.getNamedItem(
"android:id",
).nodeValue.endsWith("live_chat_overlay_button")
)
) {
continue
}
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
// voting button id from the voting button view from the youtube_controls_layout.xml host file
val votingButtonId = "@+id/revanced_sb_voting_button"
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
view.attributes.getNamedItem("android:layout_toStartOf").nodeValue = votingButtonId
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
modifiedControlsLayout = true
break
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
}
}.close()
if (!modifiedControlsLayout) throw PatchException("Could not modify controls layout")
feat: `sponsorblock` patch (#101) * chore(release): 2.5.1-dev.1 [skip ci] ## [2.5.1-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.0...v2.5.1-dev.1) (2022-06-30) ### Bug Fixes * freezing panels when watching video in fullscreen ([#89](https://github.com/revanced/revanced-patches/issues/89)) ([f5d4f6c](https://github.com/revanced/revanced-patches/commit/f5d4f6c3419916c6a9cf67babc6be8a64c854d3b)) * invalid version in compatibility annotation ([#90](https://github.com/revanced/revanced-patches/issues/90)) ([df43547](https://github.com/revanced/revanced-patches/commit/df435475cdd0494a1e4ea9e2980c2998c9bc7048)) * feat: migrate to breaking changes of patcher * chore(release): 2.6.0-dev.1 [skip ci] # [2.6.0-dev.1](https://github.com/revanced/revanced-patches/compare/v2.5.1-dev.1...v2.6.0-dev.1) (2022-07-02) ### Features * migrate to breaking changes of patcher ([a116852](https://github.com/revanced/revanced-patches/commit/a11685263fb2274c67684258e73c5247502cb010)) * refactor: add package for fingerprints * feat: partial `sponsorblock` patch * feat: add `Name` annotation to `sponsorblock-resource-patch` * fix: `sponsorblock-resource-patch` * refactor: remove unused resources * refactor: remove `locale-config-fix` dependency * fix: broken fingerprints * feat: general fixes on `sponsorblock` patch * feat: more fixes on `sponsorblock` patch * feat: update `sponsorblock` patch to 17.26.35 * style: use better wording and fix spelling mistakes * fix: finish `sponsorblock` patch Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2022-07-18 01:17:03 +02:00
}
}