mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Cleanup for ext repo changes
Also add shortcut for it in browse extension screen
This commit is contained in:
parent
14e669e40c
commit
09d89e4cea
7 changed files with 37 additions and 56 deletions
|
@ -26,10 +26,12 @@ internal class ExtensionApi {
|
||||||
|
|
||||||
suspend fun findExtensions(): List<Extension.Available> {
|
suspend fun findExtensions(): List<Extension.Available> {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val extensions = preferences.extensionRepos().get().flatMap { getExtensions(it) }
|
val repos = preferences.extensionRepos().get()
|
||||||
|
if (repos.isEmpty()) {
|
||||||
|
return@withIOContext emptyList()
|
||||||
|
}
|
||||||
|
val extensions = repos.flatMap { getExtensions(it) }
|
||||||
|
|
||||||
// Sanity check - a small number of extensions probably means something broke
|
|
||||||
// with the repo generator
|
|
||||||
if (extensions.isEmpty()) {
|
if (extensions.isEmpty()) {
|
||||||
throw Exception()
|
throw Exception()
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||||
ExtensionAdapter.OnButtonClickListener,
|
ExtensionAdapter.OnButtonClickListener,
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
FlexibleAdapter.OnItemLongClickListener,
|
FlexibleAdapter.OnItemLongClickListener,
|
||||||
ExtensionTrustDialog.Listener,
|
|
||||||
SourceAdapter.OnAllClickListener,
|
SourceAdapter.OnAllClickListener,
|
||||||
BaseMigrationInterface {
|
BaseMigrationInterface {
|
||||||
|
|
||||||
|
@ -323,8 +322,16 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openTrustDialog(extension: Extension.Untrusted) {
|
private fun openTrustDialog(extension: Extension.Untrusted) {
|
||||||
ExtensionTrustDialog(this, extension.signatureHash, extension.pkgName, extension.versionCode)
|
val activity = controller.activity ?: return
|
||||||
.showDialog(controller.router)
|
activity.materialAlertDialog()
|
||||||
|
.setTitle(R.string.untrusted_extension)
|
||||||
|
.setMessage(R.string.untrusted_extension_message)
|
||||||
|
.setPositiveButton(R.string.trust) { _, _ ->
|
||||||
|
trustExtension(extension.pkgName, extension.versionCode, extension.signatureHash)
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.uninstall) { _, _ ->
|
||||||
|
uninstallExtension(extension.pkgName)
|
||||||
|
}.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setExtensions(extensions: List<ExtensionItem>, updateController: Boolean = true) {
|
fun setExtensions(extensions: List<ExtensionItem>, updateController: Boolean = true) {
|
||||||
|
@ -407,10 +414,10 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
|
||||||
extAdapter?.updateItem(updateHeader)
|
extAdapter?.updateItem(updateHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun trustExtension(pkgName: String, versionCode: Long, signatureHash: String) {
|
private fun trustExtension(pkgName: String, versionCode: Long, signatureHash: String) {
|
||||||
presenter.trustExtension(pkgName, versionCode, signatureHash)
|
presenter.trustExtension(pkgName, versionCode, signatureHash)
|
||||||
}
|
}
|
||||||
override fun uninstallExtension(pkgName: String) {
|
private fun uninstallExtension(pkgName: String) {
|
||||||
presenter.uninstallExtension(pkgName)
|
presenter.uninstallExtension(pkgName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,9 +116,10 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
||||||
val repoText = when {
|
val repoText = when {
|
||||||
extension is Extension.Untrusted -> itemView.context.getString(R.string.untrusted)
|
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.isObsolete -> itemView.context.getString(R.string.obsolete)
|
||||||
|
extension is Extension.Installed -> extension.repoUrl.orEmpty()
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
return if (isEmpty()) {
|
return if (isEmpty() || repoText.isEmpty()) {
|
||||||
this
|
this
|
||||||
} else {
|
} else {
|
||||||
"$this • "
|
"$this • "
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package eu.kanade.tachiyomi.ui.extension
|
|
||||||
|
|
||||||
import android.app.Dialog
|
|
||||||
import android.os.Bundle
|
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
|
||||||
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
|
||||||
|
|
||||||
class ExtensionTrustDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
|
|
||||||
where T : ExtensionTrustDialog.Listener {
|
|
||||||
|
|
||||||
lateinit var listener: Listener
|
|
||||||
constructor(target: T, signatureHash: String, pkgName: String, versionCode: Long) : this(
|
|
||||||
Bundle().apply {
|
|
||||||
putString(SIGNATURE_KEY, signatureHash)
|
|
||||||
putString(PKGNAME_KEY, pkgName)
|
|
||||||
putLong(VERSION_CODE, versionCode)
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
listener = target
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
|
||||||
return activity!!.materialAlertDialog()
|
|
||||||
.setTitle(R.string.untrusted_extension)
|
|
||||||
.setMessage(R.string.untrusted_extension_message)
|
|
||||||
.setPositiveButton(R.string.trust) { _, _ ->
|
|
||||||
listener.trustExtension(args.getString(PKGNAME_KEY)!!, args.getLong(VERSION_CODE), args.getString(SIGNATURE_KEY)!!)
|
|
||||||
}
|
|
||||||
.setNegativeButton(R.string.uninstall) { _, _ ->
|
|
||||||
listener.uninstallExtension(args.getString(PKGNAME_KEY)!!)
|
|
||||||
}.create()
|
|
||||||
}
|
|
||||||
|
|
||||||
private companion object {
|
|
||||||
const val SIGNATURE_KEY = "signature_key"
|
|
||||||
const val PKGNAME_KEY = "pkgname_key"
|
|
||||||
const val VERSION_CODE = "version_code"
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Listener {
|
|
||||||
fun trustExtension(pkgName: String, versionCode: Long, signatureHash: String)
|
|
||||||
fun uninstallExtension(pkgName: String)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,6 +42,7 @@ import eu.kanade.tachiyomi.ui.main.RootSearchInterface
|
||||||
import eu.kanade.tachiyomi.ui.setting.SettingsBrowseController
|
import eu.kanade.tachiyomi.ui.setting.SettingsBrowseController
|
||||||
import eu.kanade.tachiyomi.ui.setting.SettingsSourcesController
|
import eu.kanade.tachiyomi.ui.setting.SettingsSourcesController
|
||||||
import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController
|
import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController
|
||||||
|
import eu.kanade.tachiyomi.ui.source.browse.repos.RepoController
|
||||||
import eu.kanade.tachiyomi.ui.source.globalsearch.GlobalSearchController
|
import eu.kanade.tachiyomi.ui.source.globalsearch.GlobalSearchController
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
import eu.kanade.tachiyomi.util.system.getBottomGestureInsets
|
import eu.kanade.tachiyomi.util.system.getBottomGestureInsets
|
||||||
|
@ -361,6 +362,9 @@ class BrowseController :
|
||||||
R.id.action_sources_settings -> {
|
R.id.action_sources_settings -> {
|
||||||
router.pushController(SettingsBrowseController().withFadeTransaction())
|
router.pushController(SettingsBrowseController().withFadeTransaction())
|
||||||
}
|
}
|
||||||
|
R.id.action_ext_repos -> {
|
||||||
|
router.pushController(RepoController().withFadeTransaction())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return@setOnMenuItemClickListener true
|
return@setOnMenuItemClickListener true
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,12 @@ class RepoController(bundle: Bundle? = null) :
|
||||||
override fun onItemDelete(position: Int) {
|
override fun onItemDelete(position: Int) {
|
||||||
activity!!.materialAlertDialog()
|
activity!!.materialAlertDialog()
|
||||||
.setTitle(R.string.confirm_repo_deletion)
|
.setTitle(R.string.confirm_repo_deletion)
|
||||||
.setMessage(R.string.delete_repo_confirmation)
|
.setMessage(
|
||||||
|
activity!!.getString(
|
||||||
|
R.string.delete_repo_confirmation,
|
||||||
|
(adapter!!.getItem(position) as RepoItem).repo,
|
||||||
|
),
|
||||||
|
)
|
||||||
.setPositiveButton(R.string.delete) { _, _ ->
|
.setPositiveButton(R.string.delete) { _, _ ->
|
||||||
deleteRepo(position)
|
deleteRepo(position)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,12 @@
|
||||||
android:id="@+id/action_filter"
|
android:id="@+id/action_filter"
|
||||||
android:title="@string/filter_languages"
|
android:title="@string/filter_languages"
|
||||||
android:icon="@drawable/ic_language_24dp"
|
android:icon="@drawable/ic_language_24dp"
|
||||||
app:showAsAction="always"/>
|
app:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_ext_repos"
|
||||||
|
android:title="@string/extension_repos"
|
||||||
|
android:icon="@drawable/ic_extension_update_24dp"
|
||||||
|
app:iconTint="?actionBarTintColor"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue