From 56fbf69fcef3dcd247bfd1f8f3698e59180496f0 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 19 Jan 2024 12:15:17 -0800 Subject: [PATCH] add option to open ext repo in ext info also remove ext info name from ext list --- .../tachiyomi/ui/extension/ExtensionHolder.kt | 16 +----------- .../details/ExtensionDetailsController.kt | 25 +++++++++++++++++++ app/src/main/res/menu/extension_details.xml | 7 ++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt index 30671f6d5293..ceaca9a9f72f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt @@ -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 @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt index 3756877f0cde..f41fbf1afa94 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsController.kt @@ -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 @@ -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) @@ -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() + 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 diff --git a/app/src/main/res/menu/extension_details.xml b/app/src/main/res/menu/extension_details.xml index c39c1a28b0e3..c339c7c3b144 100644 --- a/app/src/main/res/menu/extension_details.xml +++ b/app/src/main/res/menu/extension_details.xml @@ -1,6 +1,13 @@ + + %d extension updates available Revoke trusted unknown extensions + Open source repo Add repo