Skip to content

Commit

Permalink
Use dynamically updated about summary
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Dec 6, 2023
1 parent b544e7e commit e34295c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import org.w3c.dom.Element
*/
class NonInteractivePreference(
title: StringResource,
summary: StringResource,
) : BasePreference(null, title, summary, "Preference") {
summary: StringResource?,
tag: String = "Preference",
) : 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import app.revanced.util.exception
@Patch(
name = "Alternative thumbnails",
description = "Adds options to replace video thumbnails with still image captures of the video.",
dependencies = [IntegrationsPatch::class, SettingsPatch::class],
dependencies = [IntegrationsPatch::class, SettingsPatch::class, AlternativeThumbnailsResourcePatch::class],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
Expand Down Expand Up @@ -88,64 +88,48 @@ object AlternativeThumbnailsPatch : BytecodePatch(
"revanced_alt_thumbnails_preference_screen",
StringResource("revanced_alt_thumbnails_preference_screen_title", "Alternative thumbnails"),
listOf(
ListPreference(
"revanced_alt_thumbnail_mode",
StringResource("revanced_alt_thumbnail_mode_title", "Thumbnail mode"),
ArrayResource(
"revanced_alt_thumbnail_mode_entries",
listOf(
StringResource("revanced_alt_thumbnail_mode_entry_1", "Original thumbnails"),
StringResource("revanced_alt_thumbnail_mode_entry_2", "YouTube video stills"),
StringResource(
"revanced_alt_thumbnail_mode_entry_3",
"DeArrow, fallback to original thumbnails"
),
StringResource(
"revanced_alt_thumbnail_mode_entry_4",
"DeArrow, fallback to YouTube video stills"
)
)
),
ArrayResource(
"revanced_alt_thumbnail_mode_entry_values",
listOf(
StringResource("revanced_alt_thumbnail_mode_entry_value_1", "1"),
StringResource("revanced_alt_thumbnail_mode_entry_value_2", "2"),
StringResource("revanced_alt_thumbnail_mode_entry_value_3", "3"),
StringResource("revanced_alt_thumbnail_mode_entry_value_4", "4"),
)
)
SwitchPreference(
"revanced_alt_thumbnail_stills",
StringResource("revanced_alt_thumbnail_stills_title", "Enable still video captures"),
StringResource("revanced_alt_thumbnail_stills_summary_on", "Using YouTube video still captures"),
StringResource("revanced_alt_thumbnail_stills_summary_off", "Not using YouTube video still captures")
),
ListPreference(
"revanced_alt_thumbnail_still_time",
StringResource("revanced_alt_thumbnail_still_time_title", "Video time to take the still from"),
"revanced_alt_thumbnail_stills_time",
StringResource("revanced_alt_thumbnail_stills_time_title", "Video time to take the still from"),
ArrayResource(
"revanced_alt_thumbnail_type_entries",
listOf(
StringResource("revanced_alt_thumbnail_still_time_entry_1", "Beginning of video"),
StringResource("revanced_alt_thumbnail_still_time_entry_2", "Middle of video"),
StringResource("revanced_alt_thumbnail_still_time_entry_3", "End of video"),
StringResource("revanced_alt_thumbnail_stills_time_entry_1", "Beginning of video"),
StringResource("revanced_alt_thumbnail_stills_time_entry_2", "Middle of video"),
StringResource("revanced_alt_thumbnail_stills_time_entry_3", "End of video"),
)
),
ArrayResource(
"revanced_alt_thumbnail_type_entry_values",
"revanced_alt_thumbnail_stills_time_entry_values",
listOf(
StringResource("revanced_alt_thumbnail_still_time_entry_value_1", "1"),
StringResource("revanced_alt_thumbnail_still_time_entry_value_2", "2"),
StringResource("revanced_alt_thumbnail_still_time_entry_value_3", "3"),
StringResource("revanced_alt_thumbnail_stills_time_entry_value_1", "1"),
StringResource("revanced_alt_thumbnail_stills_time_entry_value_2", "2"),
StringResource("revanced_alt_thumbnail_stills_time_entry_value_3", "3"),
)
)
),
SwitchPreference(
"revanced_alt_thumbnail_still_fast_quality",
StringResource("revanced_alt_thumbnail_still_fast_quality_title", "Use fast alternative thumbnails"),
"revanced_alt_thumbnail_stills_fast",
StringResource("revanced_alt_thumbnail_stills_fast_title", "Use fast still captures"),
StringResource(
"revanced_alt_thumbnail_still_fast_quality_summary_on",
"Using medium quality stills. " +
"revanced_alt_thumbnail_stills_fast_summary_on",
"Using medium quality still captures. " +
"Thumbnails will load faster, but live streams, unreleased, " +
"or very old videos may show blank thumbnails"
),
StringResource("revanced_alt_thumbnail_still_fast_quality_summary_off", "Using high quality stills")
StringResource("revanced_alt_thumbnail_stills_fast_summary_off", "Using high quality still captures")
),
SwitchPreference(
"revanced_alt_thumbnail_dearrow",
StringResource("revanced_alt_thumbnail_dearrow_title", "Enable DeArrow"),
StringResource("revanced_alt_thumbnail_dearrow_summary_on", "Using DeArrow"),
StringResource("revanced_alt_thumbnail_dearrow_summary_off", "Not using DeArrow")
),
TextPreference(
"revanced_alt_thumbnail_dearrow_api_url",
Expand All @@ -156,25 +140,13 @@ object AlternativeThumbnailsPatch : BytecodePatch(
StringResource(
"revanced_alt_thumbnail_dearrow_api_url_summary",
"The URL of the DeArrow thumbnail cache endpoint. " +
"This should not be changed unless you know what you are doing."
"Do not change this unless you know what you\\\'re doing"
),
),
NonInteractivePreference(
StringResource("revanced_alt_thumbnail_stills_about_title", "About video stills"),
StringResource(
"revanced_alt_thumbnail_stills_about_summary",
"Video stills are still images from the beginning/middle/end of each video. " +
"No external API is used, as these images are built into YouTube"
)
),
NonInteractivePreference(
StringResource("revanced_alt_thumbnail_dearrow_about_title", "About DeArrow"),
StringResource(
"revanced_alt_thumbnail_dearrow_about_summary",
"DeArrow provides crowd-sourced thumbnails for YouTube videos. " +
"These thumbnails are often more relevant than the ones provided by YouTube. " +
"Using DeArrow will send requests to DeArrows servers. No other data is sent."
)
title = StringResource("revanced_alt_thumbnail_about_title", "Thumbnails to display"),
summary = null, // Summary is dynamically updated using on the current settings.
tag = "app.revanced.integrations.settingsmenu.AlternativeThumbnailsAboutPreference"
)
),
StringResource("revanced_alt_thumbnails_preference_screen_summary", "Video thumbnail settings")
Expand Down
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,9 @@
<resources>
<string name="revanced_alt_thumbnail_about_summary_disabled">Showing original YouTube thumbnails</string>
<string name="revanced_alt_thumbnail_about_summary_stills">Showing still video captures from the beginning/middle/end of each video. These images are built into YouTube, and no external API is used</string>

<string name="revanced_alt_thumbnail_about_summary_dearrow" formatted="false">Showing DeArrow provides crowd-sourced thumbnails. These thumbnails are often more relevant than the ones provided by YouTube. Thumbnail requests will be sent to the DeArrow API server, and no other data is sent.\n\nIf DeArrow has no thumbnails, %s\n\n%s</string>
<string name="revanced_alt_thumbnail_about_summary_dearrow_fallback_none">then the original YouTube thumbnails will be shown</string>
<string name="revanced_alt_thumbnail_about_summary_dearrow_fallback_stills">then YouTube provided still image captures will be shown.</string>
<string name="revanced_alt_thumbnail_about_summary_link_text">Tap here to learn more about DeArrow</string>
</resources>

0 comments on commit e34295c

Please sign in to comment.