mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-29 02:23:21 -05:00
Add ability to open available extension websites in WebView
Closes #8628
This commit is contained in:
parent
1ef01b53f2
commit
f776c36e70
2 changed files with 91 additions and 30 deletions
|
@ -14,6 +14,11 @@ import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Close
|
import androidx.compose.material.icons.outlined.Close
|
||||||
|
import androidx.compose.material.icons.outlined.GetApp
|
||||||
|
import androidx.compose.material.icons.outlined.Public
|
||||||
|
import androidx.compose.material.icons.outlined.Refresh
|
||||||
|
import androidx.compose.material.icons.outlined.Settings
|
||||||
|
import androidx.compose.material.icons.outlined.VerifiedUser
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
@ -62,6 +67,7 @@ fun ExtensionScreen(
|
||||||
searchQuery: String?,
|
searchQuery: String?,
|
||||||
onLongClickItem: (Extension) -> Unit,
|
onLongClickItem: (Extension) -> Unit,
|
||||||
onClickItemCancel: (Extension) -> Unit,
|
onClickItemCancel: (Extension) -> Unit,
|
||||||
|
onClickItemWebView: (Extension.Available) -> Unit,
|
||||||
onInstallExtension: (Extension.Available) -> Unit,
|
onInstallExtension: (Extension.Available) -> Unit,
|
||||||
onUninstallExtension: (Extension) -> Unit,
|
onUninstallExtension: (Extension) -> Unit,
|
||||||
onUpdateExtension: (Extension.Installed) -> Unit,
|
onUpdateExtension: (Extension.Installed) -> Unit,
|
||||||
|
@ -94,6 +100,7 @@ fun ExtensionScreen(
|
||||||
contentPadding = contentPadding,
|
contentPadding = contentPadding,
|
||||||
onLongClickItem = onLongClickItem,
|
onLongClickItem = onLongClickItem,
|
||||||
onClickItemCancel = onClickItemCancel,
|
onClickItemCancel = onClickItemCancel,
|
||||||
|
onClickItemWebView = onClickItemWebView,
|
||||||
onInstallExtension = onInstallExtension,
|
onInstallExtension = onInstallExtension,
|
||||||
onUninstallExtension = onUninstallExtension,
|
onUninstallExtension = onUninstallExtension,
|
||||||
onUpdateExtension = onUpdateExtension,
|
onUpdateExtension = onUpdateExtension,
|
||||||
|
@ -111,6 +118,7 @@ private fun ExtensionContent(
|
||||||
state: ExtensionsScreenModel.State,
|
state: ExtensionsScreenModel.State,
|
||||||
contentPadding: PaddingValues,
|
contentPadding: PaddingValues,
|
||||||
onLongClickItem: (Extension) -> Unit,
|
onLongClickItem: (Extension) -> Unit,
|
||||||
|
onClickItemWebView: (Extension.Available) -> Unit,
|
||||||
onClickItemCancel: (Extension) -> Unit,
|
onClickItemCancel: (Extension) -> Unit,
|
||||||
onInstallExtension: (Extension.Available) -> Unit,
|
onInstallExtension: (Extension.Available) -> Unit,
|
||||||
onUninstallExtension: (Extension) -> Unit,
|
onUninstallExtension: (Extension) -> Unit,
|
||||||
|
@ -177,6 +185,7 @@ private fun ExtensionContent(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongClickItem = onLongClickItem,
|
onLongClickItem = onLongClickItem,
|
||||||
|
onClickItemWebView = onClickItemWebView,
|
||||||
onClickItemCancel = onClickItemCancel,
|
onClickItemCancel = onClickItemCancel,
|
||||||
onClickItemAction = {
|
onClickItemAction = {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
@ -217,6 +226,7 @@ private fun ExtensionItem(
|
||||||
item: ExtensionUiModel.Item,
|
item: ExtensionUiModel.Item,
|
||||||
onClickItem: (Extension) -> Unit,
|
onClickItem: (Extension) -> Unit,
|
||||||
onLongClickItem: (Extension) -> Unit,
|
onLongClickItem: (Extension) -> Unit,
|
||||||
|
onClickItemWebView: (Extension.Available) -> Unit,
|
||||||
onClickItemCancel: (Extension) -> Unit,
|
onClickItemCancel: (Extension) -> Unit,
|
||||||
onClickItemAction: (Extension) -> Unit,
|
onClickItemAction: (Extension) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
@ -260,6 +270,7 @@ private fun ExtensionItem(
|
||||||
ExtensionItemActions(
|
ExtensionItemActions(
|
||||||
extension = extension,
|
extension = extension,
|
||||||
installStep = installStep,
|
installStep = installStep,
|
||||||
|
onClickItemWebView = onClickItemWebView,
|
||||||
onClickItemCancel = onClickItemCancel,
|
onClickItemCancel = onClickItemCancel,
|
||||||
onClickItemAction = onClickItemAction,
|
onClickItemAction = onClickItemAction,
|
||||||
)
|
)
|
||||||
|
@ -343,42 +354,80 @@ private fun ExtensionItemActions(
|
||||||
extension: Extension,
|
extension: Extension,
|
||||||
installStep: InstallStep,
|
installStep: InstallStep,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
onClickItemWebView: (Extension.Available) -> Unit = {},
|
||||||
onClickItemCancel: (Extension) -> Unit = {},
|
onClickItemCancel: (Extension) -> Unit = {},
|
||||||
onClickItemAction: (Extension) -> Unit = {},
|
onClickItemAction: (Extension) -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val isIdle = installStep.isCompleted()
|
val isIdle = installStep.isCompleted()
|
||||||
Row(modifier = modifier) {
|
|
||||||
if (isIdle) {
|
Row(
|
||||||
TextButton(
|
modifier = modifier,
|
||||||
onClick = { onClickItemAction(extension) },
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
) {
|
) {
|
||||||
Text(
|
when {
|
||||||
text = when (installStep) {
|
!isIdle -> {
|
||||||
InstallStep.Installed -> stringResource(MR.strings.ext_installed)
|
IconButton(onClick = { onClickItemCancel(extension) }) {
|
||||||
InstallStep.Error -> stringResource(MR.strings.action_retry)
|
Icon(
|
||||||
InstallStep.Idle -> {
|
imageVector = Icons.Outlined.Close,
|
||||||
when (extension) {
|
contentDescription = stringResource(MR.strings.action_cancel),
|
||||||
is Extension.Installed -> {
|
)
|
||||||
if (extension.hasUpdate) {
|
}
|
||||||
stringResource(MR.strings.ext_update)
|
}
|
||||||
} else {
|
installStep == InstallStep.Error -> {
|
||||||
stringResource(MR.strings.action_settings)
|
IconButton(onClick = { onClickItemAction(extension) }) {
|
||||||
}
|
Icon(
|
||||||
}
|
imageVector = Icons.Outlined.Refresh,
|
||||||
is Extension.Untrusted -> stringResource(MR.strings.ext_trust)
|
contentDescription = stringResource(MR.strings.action_retry),
|
||||||
is Extension.Available -> stringResource(MR.strings.ext_install)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
installStep == InstallStep.Idle -> {
|
||||||
|
when (extension) {
|
||||||
|
is Extension.Installed -> {
|
||||||
|
if (extension.hasUpdate) {
|
||||||
|
IconButton(onClick = { onClickItemAction(extension) }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.GetApp,
|
||||||
|
contentDescription = stringResource(MR.strings.ext_update),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> error("Must not show install process text")
|
|
||||||
},
|
IconButton(onClick = { onClickItemAction(extension) }) {
|
||||||
)
|
Icon(
|
||||||
}
|
imageVector = Icons.Outlined.Settings,
|
||||||
} else {
|
contentDescription = stringResource(MR.strings.action_settings),
|
||||||
IconButton(onClick = { onClickItemCancel(extension) }) {
|
)
|
||||||
Icon(
|
}
|
||||||
imageVector = Icons.Outlined.Close,
|
}
|
||||||
contentDescription = stringResource(MR.strings.action_cancel),
|
is Extension.Untrusted -> {
|
||||||
)
|
IconButton(onClick = { onClickItemAction(extension) }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.VerifiedUser,
|
||||||
|
contentDescription = stringResource(MR.strings.ext_trust),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is Extension.Available -> {
|
||||||
|
if (extension.sources.isNotEmpty()) {
|
||||||
|
IconButton(
|
||||||
|
onClick = { onClickItemWebView(extension) },
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Public,
|
||||||
|
contentDescription = stringResource(MR.strings.action_open_in_web_view),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IconButton(onClick = { onClickItemAction(extension) }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.GetApp,
|
||||||
|
contentDescription = stringResource(MR.strings.ext_install),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import eu.kanade.presentation.components.AppBar
|
||||||
import eu.kanade.presentation.components.TabContent
|
import eu.kanade.presentation.components.TabContent
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import eu.kanade.tachiyomi.ui.browse.extension.details.ExtensionDetailsScreen
|
import eu.kanade.tachiyomi.ui.browse.extension.details.ExtensionDetailsScreen
|
||||||
|
import eu.kanade.tachiyomi.ui.webview.WebViewScreen
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.presentation.core.i18n.stringResource
|
import tachiyomi.presentation.core.i18n.stringResource
|
||||||
|
@ -47,6 +48,17 @@ fun extensionsTab(
|
||||||
},
|
},
|
||||||
onClickItemCancel = extensionsScreenModel::cancelInstallUpdateExtension,
|
onClickItemCancel = extensionsScreenModel::cancelInstallUpdateExtension,
|
||||||
onClickUpdateAll = extensionsScreenModel::updateAllExtensions,
|
onClickUpdateAll = extensionsScreenModel::updateAllExtensions,
|
||||||
|
onClickItemWebView = { extension ->
|
||||||
|
extension.sources.getOrNull(0)?.let {
|
||||||
|
navigator.push(
|
||||||
|
WebViewScreen(
|
||||||
|
url = it.baseUrl,
|
||||||
|
initialTitle = it.name,
|
||||||
|
sourceId = it.id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
onInstallExtension = extensionsScreenModel::installExtension,
|
onInstallExtension = extensionsScreenModel::installExtension,
|
||||||
onOpenExtension = { navigator.push(ExtensionDetailsScreen(it.pkgName)) },
|
onOpenExtension = { navigator.push(ExtensionDetailsScreen(it.pkgName)) },
|
||||||
onTrustExtension = { extensionsScreenModel.trustSignature(it.signatureHash) },
|
onTrustExtension = { extensionsScreenModel.trustSignature(it.signatureHash) },
|
||||||
|
|
Loading…
Reference in a new issue