Skip to content

Commit

Permalink
feat: Added resource file for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
crimera authored Apr 11, 2024
2 parents 71fc9bd + 23e0b5a commit 181fd29
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/main/kotlin/app/util/ResourceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ fun String.copyXmlNode(source: DomFileEditor, target: DomFileEditor): AutoClosea
}
}

//Credits @inotia00
/**
* Copy resources from the current class loader to the resource directory.
* @param resourceDirectory The directory of the resource.
* @param targetResource The target resource.
* @param elementTag The element to copy.
*/
fun ResourceContext.copyXmlNode(
resourceDirectory: String,
targetResource: String,
elementTag: String
) {
val stringsResourceInputStream =
classLoader.getResourceAsStream("$resourceDirectory/$targetResource")!!

// Copy nodes from the resources node to the real resource node
elementTag.copyXmlNode(
this.xmlEditor[stringsResourceInputStream],
this.xmlEditor["res/$targetResource"]
).close()
}


// /**
// * Copies the specified node of the source [Document] to the target [Document].
// * @param source the source [Document].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.util.ResourceGroup
import app.revanced.util.copyResources
import org.w3c.dom.Element
import app.revanced.util.copyXmlNode

@Patch(
compatiblePackages = [CompatiblePackage("com.twitter.android")],
Expand All @@ -20,7 +23,7 @@ object SettingsResourcePatch: ResourcePatch() {

val prefMod = editor.file.createElement("Preference")
prefMod.setAttribute("android:icon", "@drawable/ic_vector_settings_stroke")
prefMod.setAttribute("android:title", "Mod Settings")
prefMod.setAttribute("android:title", "@string/piko_settings_title")
prefMod.setAttribute("android:key", "pref_mod")
prefMod.setAttribute("android:order", "110")

Expand All @@ -31,12 +34,30 @@ object SettingsResourcePatch: ResourcePatch() {
val applicationNode = it.file.getElementsByTagName("application").item(0)

val modActivity = it.file.createElement("activity").apply {
setAttribute("android:label", "Mod Settings")
setAttribute("android:label", "@strings/piko_settings_title")
setAttribute("android:name", "app.revanced.integrations.twitter.settings.SettingsActivity")
setAttribute("android:excludeFromRecents", "true")
}

applicationNode.appendChild(modActivity)
}

//credits @inotia00
context.copyXmlNode("twitter/settings", "values/strings.xml", "resources")

/**
* create directory for the untranslated language resources
*/
context["res/values-v21"].mkdirs()
arrayOf(
ResourceGroup(
"values-v21",
"strings.xml"
)
).forEach { resourceGroup ->
context.copyResources("twitter/settings", resourceGroup)
}


}
}
5 changes: 5 additions & 0 deletions src/main/resources/twitter/settings/values-v21/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Translation Exception -->
<string name="piko_settings_title">Piko Mod Settings</string>
</resources>
50 changes: 50 additions & 0 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="piko_title_premium">Premium</string>
<string name="piko_pref_reader_mode">Enable reader mode</string>
<string name="piko_pref_reader_mode_desc">Enables "reader mode" on long threads</string>
<string name="piko_pref_undo_posts">Enable undo posts</string>
<string name="piko_pref_undo_posts_desc">Enables ability to undo posts before posting</string>
<string name="piko_pref_undo_posts_btn">Undo posts settings</string>
<string name="piko_pref_icon_n_navbar_btn">App icon and navbar customisation settings</string>

<string name="piko_title_download">Download</string>
<string name="piko_pref_download_path">Public folder</string>
<string name="piko_pref_download_path_desc">The public folder to use for video downloads</string>
<string name="piko_pref_download_folder">Download subfolder</string>
<string name="piko_pref_download_folder_desc">The subfolder to download videos to ([PublicFolder]/[Subfolder])</string>

<string name="piko_title_ads">Ads</string>
<string name="piko_pref_hide_promoted_posts">Hide promoted posts</string>
<string name="piko_pref_hide_g_ads">Hide google ads</string>
<string name="piko_pref_wtf_section">Hide "Who to follow" section</string>
<string name="piko_pref_cts_section">Hide "Creators to subscribe" section</string>
<string name="piko_pref_ctj_section">Hide "Community to join" section</string>
<string name="piko_pref_ryb_section">Hide "Revist your bookmark" section</string>
<string name="piko_pref_pinned_posts_section">Hide "Pinned posts by followers" section</string>
<string name="piko_pref_hide_detailed_posts">Hide detailed posts (in replies)</string>
<string name="piko_pref_hide_trends">Hide promoted trends</string>

<string name="piko_title_misc">Misc</string>
<string name="piko_pref_chirp_font">Enable chirp font</string>
<string name="piko_pref_hide_fab">Hide floating action button</string>
<string name="piko_pref_hide_fab_menu">Hide floating action button menu</string>
<string name="piko_pref_rec_users">Hide recommended users</string>
<string name="piko_pref_comm_notes">Hide community notes</string>
<string name="piko_pref_hide_view_count">Hide view count</string>
<string name="piko_pref_custom_share_domain">Custom sharing domain</string>
<string name="piko_pref_custom_share_domain_desc">The domain to use when sharing tweets</string>

<string name="piko_title_timeline">Timeline</string>
<string name="piko_pref_hide_for_you">Hide for you tab</string>
<string name="piko_pref_hide_live_threads">Hide live threads</string>
<string name="piko_pref_hide_live_threads_desc">Hides live section in timeline</string>
<string name="piko_pref_hide_banner">Hide banner</string>
<string name="piko_pref_hide_banner_desc">Hide new posts pill</string>
<string name="piko_pref_hide_bmk_timeline">Hide bookmark icon in timeline</string>
<string name="piko_pref_show_poll_result">Show poll results</string>
<string name="piko_pref_show_poll_result_desc">View poll results without voting</string>
<string name="piko_pref_hide_immersive_player">Hide immersive player</string>
<string name="piko_pref_hide_immersive_player_desc">Removes swipe up for more videos in video player</string>

</resources>

0 comments on commit 181fd29

Please sign in to comment.