feat(app): Add ability to open available extension websites in WebView

Closes #8628
This commit is contained in:
arkon 2023-12-11 22:24:33 -05:00 committed by Claudemirovsky
parent 637f11652b
commit 6135798471
No known key found for this signature in database
GPG key ID: 82AE76162407356E
4 changed files with 183 additions and 60 deletions

View file

@ -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.Button import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -61,6 +66,7 @@ fun AnimeExtensionScreen(
searchQuery: String?, searchQuery: String?,
onLongClickItem: (AnimeExtension) -> Unit, onLongClickItem: (AnimeExtension) -> Unit,
onClickItemCancel: (AnimeExtension) -> Unit, onClickItemCancel: (AnimeExtension) -> Unit,
onClickItemWebView: (AnimeExtension.Available) -> Unit,
onInstallExtension: (AnimeExtension.Available) -> Unit, onInstallExtension: (AnimeExtension.Available) -> Unit,
onUninstallExtension: (AnimeExtension) -> Unit, onUninstallExtension: (AnimeExtension) -> Unit,
onUpdateExtension: (AnimeExtension.Installed) -> Unit, onUpdateExtension: (AnimeExtension.Installed) -> Unit,
@ -93,6 +99,7 @@ fun AnimeExtensionScreen(
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,
@ -110,6 +117,7 @@ private fun AnimeExtensionContent(
state: AnimeExtensionsScreenModel.State, state: AnimeExtensionsScreenModel.State,
contentPadding: PaddingValues, contentPadding: PaddingValues,
onLongClickItem: (AnimeExtension) -> Unit, onLongClickItem: (AnimeExtension) -> Unit,
onClickItemWebView: (AnimeExtension.Available) -> Unit,
onClickItemCancel: (AnimeExtension) -> Unit, onClickItemCancel: (AnimeExtension) -> Unit,
onInstallExtension: (AnimeExtension.Available) -> Unit, onInstallExtension: (AnimeExtension.Available) -> Unit,
onUninstallExtension: (AnimeExtension) -> Unit, onUninstallExtension: (AnimeExtension) -> Unit,
@ -177,6 +185,7 @@ private fun AnimeExtensionContent(
}, },
onLongClickItem = onLongClickItem, onLongClickItem = onLongClickItem,
onClickItemCancel = onClickItemCancel, onClickItemCancel = onClickItemCancel,
onClickItemWebView = onClickItemWebView,
onClickItemAction = { onClickItemAction = {
when (it) { when (it) {
is AnimeExtension.Available -> onInstallExtension(it) is AnimeExtension.Available -> onInstallExtension(it)
@ -219,6 +228,7 @@ private fun AnimeExtensionItem(
item: AnimeExtensionUiModel.Item, item: AnimeExtensionUiModel.Item,
onClickItem: (AnimeExtension) -> Unit, onClickItem: (AnimeExtension) -> Unit,
onLongClickItem: (AnimeExtension) -> Unit, onLongClickItem: (AnimeExtension) -> Unit,
onClickItemWebView: (AnimeExtension.Available) -> Unit,
onClickItemCancel: (AnimeExtension) -> Unit, onClickItemCancel: (AnimeExtension) -> Unit,
onClickItemAction: (AnimeExtension) -> Unit, onClickItemAction: (AnimeExtension) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@ -262,6 +272,7 @@ private fun AnimeExtensionItem(
AnimeExtensionItemActions( AnimeExtensionItemActions(
extension = extension, extension = extension,
installStep = installStep, installStep = installStep,
onClickItemWebView = onClickItemWebView,
onClickItemCancel = onClickItemCancel, onClickItemCancel = onClickItemCancel,
onClickItemAction = onClickItemAction, onClickItemAction = onClickItemAction,
) )
@ -348,43 +359,82 @@ private fun AnimeExtensionItemActions(
extension: AnimeExtension, extension: AnimeExtension,
installStep: InstallStep, installStep: InstallStep,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClickItemWebView: (AnimeExtension.Available) -> Unit = {},
onClickItemCancel: (AnimeExtension) -> Unit = {}, onClickItemCancel: (AnimeExtension) -> Unit = {},
onClickItemAction: (AnimeExtension) -> Unit = {}, onClickItemAction: (AnimeExtension) -> 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 AnimeExtension.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 AnimeExtension.Untrusted -> stringResource(MR.strings.ext_trust) contentDescription = stringResource(MR.strings.action_retry),
is AnimeExtension.Available -> stringResource(MR.strings.ext_install) )
}
}
installStep == InstallStep.Idle -> {
when (extension) {
is AnimeExtension.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 AnimeExtension.Untrusted -> {
) IconButton(onClick = { onClickItemAction(extension) }) {
Icon(
imageVector = Icons.Outlined.VerifiedUser,
contentDescription = stringResource(MR.strings.ext_trust),
)
}
}
is AnimeExtension.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),
)
}
}
}
} }
} }
} }
} }

View file

@ -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 MangaExtensionScreen(
searchQuery: String?, searchQuery: String?,
onLongClickItem: (MangaExtension) -> Unit, onLongClickItem: (MangaExtension) -> Unit,
onClickItemCancel: (MangaExtension) -> Unit, onClickItemCancel: (MangaExtension) -> Unit,
onClickItemWebView: (MangaExtension.Available) -> Unit,
onInstallExtension: (MangaExtension.Available) -> Unit, onInstallExtension: (MangaExtension.Available) -> Unit,
onUninstallExtension: (MangaExtension) -> Unit, onUninstallExtension: (MangaExtension) -> Unit,
onUpdateExtension: (MangaExtension.Installed) -> Unit, onUpdateExtension: (MangaExtension.Installed) -> Unit,
@ -94,6 +100,7 @@ fun MangaExtensionScreen(
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: MangaExtensionsScreenModel.State, state: MangaExtensionsScreenModel.State,
contentPadding: PaddingValues, contentPadding: PaddingValues,
onLongClickItem: (MangaExtension) -> Unit, onLongClickItem: (MangaExtension) -> Unit,
onClickItemWebView: (MangaExtension.Available) -> Unit,
onClickItemCancel: (MangaExtension) -> Unit, onClickItemCancel: (MangaExtension) -> Unit,
onInstallExtension: (MangaExtension.Available) -> Unit, onInstallExtension: (MangaExtension.Available) -> Unit,
onUninstallExtension: (MangaExtension) -> Unit, onUninstallExtension: (MangaExtension) -> Unit,
@ -177,6 +185,7 @@ private fun ExtensionContent(
} }
}, },
onLongClickItem = onLongClickItem, onLongClickItem = onLongClickItem,
onClickItemWebView = onClickItemWebView,
onClickItemCancel = onClickItemCancel, onClickItemCancel = onClickItemCancel,
onClickItemAction = { onClickItemAction = {
when (it) { when (it) {
@ -220,6 +229,7 @@ private fun ExtensionItem(
item: MangaExtensionUiModel.Item, item: MangaExtensionUiModel.Item,
onClickItem: (MangaExtension) -> Unit, onClickItem: (MangaExtension) -> Unit,
onLongClickItem: (MangaExtension) -> Unit, onLongClickItem: (MangaExtension) -> Unit,
onClickItemWebView: (MangaExtension.Available) -> Unit,
onClickItemCancel: (MangaExtension) -> Unit, onClickItemCancel: (MangaExtension) -> Unit,
onClickItemAction: (MangaExtension) -> Unit, onClickItemAction: (MangaExtension) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@ -263,6 +273,7 @@ private fun ExtensionItem(
ExtensionItemActions( ExtensionItemActions(
extension = extension, extension = extension,
installStep = installStep, installStep = installStep,
onClickItemWebView = onClickItemWebView,
onClickItemCancel = onClickItemCancel, onClickItemCancel = onClickItemCancel,
onClickItemAction = onClickItemAction, onClickItemAction = onClickItemAction,
) )
@ -349,42 +360,80 @@ private fun ExtensionItemActions(
extension: MangaExtension, extension: MangaExtension,
installStep: InstallStep, installStep: InstallStep,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClickItemWebView: (MangaExtension.Available) -> Unit = {},
onClickItemCancel: (MangaExtension) -> Unit = {}, onClickItemCancel: (MangaExtension) -> Unit = {},
onClickItemAction: (MangaExtension) -> Unit = {}, onClickItemAction: (MangaExtension) -> 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 MangaExtension.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 MangaExtension.Untrusted -> stringResource(MR.strings.ext_trust) contentDescription = stringResource(MR.strings.action_retry),
is MangaExtension.Available -> stringResource(MR.strings.ext_install) )
}
}
installStep == InstallStep.Idle -> {
when (extension) {
is MangaExtension.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 MangaExtension.Untrusted -> {
) IconButton(onClick = { onClickItemAction(extension) }) {
Icon(
imageVector = Icons.Outlined.VerifiedUser,
contentDescription = stringResource(MR.strings.ext_trust),
)
}
}
is MangaExtension.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),
)
}
}
}
} }
} }
} }

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.browse.anime.extension package eu.kanade.tachiyomi.ui.browse.anime.extension
import eu.kanade.tachiyomi.ui.webview.WebViewScreen
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Translate import androidx.compose.material.icons.outlined.Translate
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -53,6 +54,17 @@ fun animeExtensionsTab(
}, },
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(AnimeExtensionDetailsScreen(it.pkgName)) }, onOpenExtension = { navigator.push(AnimeExtensionDetailsScreen(it.pkgName)) },
onTrustExtension = { extensionsScreenModel.trustSignature(it.signatureHash) }, onTrustExtension = { extensionsScreenModel.trustSignature(it.signatureHash) },

View file

@ -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.manga.model.MangaExtension import eu.kanade.tachiyomi.extension.manga.model.MangaExtension
import eu.kanade.tachiyomi.ui.browse.manga.extension.details.MangaExtensionDetailsScreen import eu.kanade.tachiyomi.ui.browse.manga.extension.details.MangaExtensionDetailsScreen
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
@ -49,6 +50,17 @@ fun mangaExtensionsTab(
}, },
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(MangaExtensionDetailsScreen(it.pkgName)) }, onOpenExtension = { navigator.push(MangaExtensionDetailsScreen(it.pkgName)) },
onTrustExtension = { extensionsScreenModel.trustSignature(it.signatureHash) }, onTrustExtension = { extensionsScreenModel.trustSignature(it.signatureHash) },