Skip to content

Commit

Permalink
add option to open ext repo in ext info
Browse files Browse the repository at this point in the history
also remove ext info name from ext list
  • Loading branch information
Jays2Kings committed Jan 19, 2024
1 parent 09d89e4 commit 56fbf69
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
binding.warning.text = when {
extension.isNsfw -> itemView.context.getString(R.string.nsfw_short)
else -> ""
}.plusRepo(extension).uppercase(Locale.ROOT)
}.uppercase(Locale.ROOT)
binding.installProgress.progress = item.sessionProgress ?: 0
binding.installProgress.isVisible = item.sessionProgress != null
binding.cancelButton.isVisible = item.sessionProgress != null
Expand All @@ -112,20 +112,6 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
bindButton(item)
}

private fun String.plusRepo(extension: Extension): String {
val repoText = when {
extension is Extension.Untrusted -> itemView.context.getString(R.string.untrusted)
extension is Extension.Installed && extension.isObsolete -> itemView.context.getString(R.string.obsolete)
extension is Extension.Installed -> extension.repoUrl.orEmpty()
else -> ""
}
return if (isEmpty() || repoText.isEmpty()) {
this
} else {
"$this"
} + repoText
}

@Suppress("ResourceType")
fun bindButton(item: ExtensionItem) = with(binding.extButton) {
if (item.installStep == InstallStep.Done) return@with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.ui.setting.defaultValue
import eu.kanade.tachiyomi.ui.setting.onChange
import eu.kanade.tachiyomi.ui.setting.switchPreference
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.view.openInBrowser
import eu.kanade.tachiyomi.util.view.scrollViewWith
import eu.kanade.tachiyomi.util.view.snack
import eu.kanade.tachiyomi.widget.LinearLayoutManagerAccurateOffset
Expand Down Expand Up @@ -151,10 +152,12 @@ class ExtensionDetailsController(bundle: Bundle? = null) :

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.extension_details, menu)
menu.findItem(R.id.action_open_repo)?.isVisible = presenter.extension?.repoUrl != null
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_open_repo -> openRepo()
R.id.action_clear_cookies -> clearCookies()
}
return super.onOptionsItemSelected(item)
Expand All @@ -175,6 +178,28 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
binding.coordinator.snack(context.getString(R.string.cookies_cleared))
}

private fun openRepo() {
val regex = """https://raw.githubusercontent.com/(.+?)/(.+?)/.+""".toRegex()

This comment has been minimized.

Copy link
@zhongfly

zhongfly Jan 20, 2024

Github raw url can also be https://github.com/$user/$repo/raw/$branch/...
example:https://github.com/Jays2Kings/tachiyomiJ2K/raw/master/README.md

val url = regex.find(presenter.extension?.repoUrl.orEmpty())
?.let {
val (user, repo) = it.destructured
"https://github.com/$user/$repo"
}
?: presenter.extension?.repoUrl ?: return
openInBrowser(url)
}

private fun createUrl(url: String, pkgName: String, pkgFactory: String?, path: String = ""): String {
return if (!pkgFactory.isNullOrEmpty()) {
when (path.isEmpty()) {
true -> "$url/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/$pkgFactory"
else -> "$url/multisrc/overrides/$pkgFactory/" + (pkgName.split(".").lastOrNull() ?: "") + path
}
} else {
url + "/src/" + pkgName.replace(".", "/") + path
}
}

private fun addPreferencesForSource(screen: PreferenceScreen, source: Source, isMultiSource: Boolean, isMultiLangSingleSource: Boolean) {
val context = screen.context

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/extension_details.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_open_repo"
android:icon="@drawable/ic_open_in_new_24dp"
app:iconTint="?actionBarTintColor"
android:title="@string/open_source_repo"
app:showAsAction="ifRoom" />

<item
android:id="@+id/action_clear_cookies"
android:icon="@drawable/ic_delete_24dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
<item quantity="other">%d extension updates available</item>
</plurals>
<string name="ext_revoke_trust">Revoke trusted unknown extensions</string>
<string name="open_source_repo">Open source repo</string>

<!-- Extension Repos -->
<string name="action_add_repo">Add repo</string>
Expand Down

0 comments on commit 56fbf69

Please sign in to comment.