repo icon for Komikku & Keiyoushi (#291)

This commit is contained in:
Tran M. Cuong 2024-08-25 00:23:09 +07:00 committed by Cuong-Tran
parent 50b837c976
commit 8a7c005d61
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
6 changed files with 99 additions and 62 deletions

View file

@ -1,14 +1,16 @@
package eu.kanade.presentation.more.settings.screen.browse.components
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Label
import androidx.compose.material.icons.automirrored.outlined.OpenInNew
import androidx.compose.material.icons.outlined.ContentCopy
import androidx.compose.material.icons.outlined.Delete
@ -23,9 +25,14 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.copyToClipboard
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.persistentSetOf
@ -89,83 +96,102 @@ private fun ExtensionRepoListItem(
ElevatedCard(
modifier = modifier,
) {
// KMK -->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(
start = MaterialTheme.padding.medium,
top = MaterialTheme.padding.medium,
end = MaterialTheme.padding.medium,
),
verticalAlignment = Alignment.CenterVertically,
.padding(start = MaterialTheme.padding.medium),
) {
Icon(
imageVector = Icons.AutoMirrored.Outlined.Label,
val resId = repoResId(repo.baseUrl)
Image(
bitmap = ImageBitmap.imageResource(id = resId),
contentDescription = null,
// KMK -->
tint = LocalContentColor.current.let { if (isDisabled) it.copy(alpha = 0.6f) else it },
// KMK <--
alpha = if (isDisabled) 0.4f else 1f,
modifier = Modifier
.size(48.dp)
.clip(MaterialTheme.shapes.extraSmall)
.align(Alignment.CenterVertically),
)
Text(
text = repo.name,
modifier = Modifier.padding(start = MaterialTheme.padding.medium),
style = MaterialTheme.typography.titleMedium,
// KMK -->
color = LocalContentColor.current.let { if (isDisabled) it.copy(alpha = 0.6f) else it },
textDecoration = TextDecoration.LineThrough.takeIf { isDisabled },
Column {
// KMK <--
)
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(
start = MaterialTheme.padding.medium,
top = MaterialTheme.padding.medium,
end = MaterialTheme.padding.medium,
),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = repo.name,
// KMK: modifier = Modifier.padding(start = MaterialTheme.padding.medium),
style = MaterialTheme.typography.titleMedium,
// KMK -->
color = LocalContentColor.current.let { if (isDisabled) it.copy(alpha = 0.6f) else it },
textDecoration = TextDecoration.LineThrough.takeIf { isDisabled },
// KMK <--
)
}
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
) {
IconButton(onClick = onOpenWebsite) {
Icon(
imageVector = Icons.AutoMirrored.Outlined.OpenInNew,
contentDescription = stringResource(MR.strings.action_open_in_browser),
)
}
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
) {
IconButton(onClick = onOpenWebsite) {
Icon(
imageVector = Icons.AutoMirrored.Outlined.OpenInNew,
contentDescription = stringResource(MR.strings.action_open_in_browser),
)
}
IconButton(
onClick = {
val url = "${repo.baseUrl}/index.min.json"
context.copyToClipboard(url, url)
},
) {
Icon(
imageVector = Icons.Outlined.ContentCopy,
contentDescription = stringResource(MR.strings.action_copy_to_clipboard),
)
}
IconButton(
onClick = {
val url = "${repo.baseUrl}/index.min.json"
context.copyToClipboard(url, url)
},
) {
Icon(
imageVector = Icons.Outlined.ContentCopy,
contentDescription = stringResource(MR.strings.action_copy_to_clipboard),
)
}
// KMK -->
IconButton(onClick = if (isDisabled) onEnable else onDisable) {
Icon(
imageVector = if (isDisabled) Icons.Outlined.VisibilityOff else Icons.Outlined.Visibility,
contentDescription = stringResource(MR.strings.action_disable),
)
}
// KMK <--
// KMK -->
IconButton(onClick = if (isDisabled) onEnable else onDisable) {
Icon(
imageVector = if (isDisabled) Icons.Outlined.VisibilityOff else Icons.Outlined.Visibility,
contentDescription = stringResource(MR.strings.action_disable),
)
}
// KMK <--
IconButton(onClick = onDelete) {
Icon(
imageVector = Icons.Outlined.Delete,
contentDescription = stringResource(MR.strings.action_delete),
)
IconButton(onClick = onDelete) {
Icon(
imageVector = Icons.Outlined.Delete,
contentDescription = stringResource(MR.strings.action_delete),
)
}
}
}
}
}
}
// KMK -->
fun repoResId(baseUrl: String) = when (baseUrl) {
"https://raw.githubusercontent.com/komikku-app/extensions/repo" -> R.mipmap.komikku
"https://raw.githubusercontent.com/keiyoushi/extensions/repo" -> R.mipmap.keiyoushi
else -> R.mipmap.extension
}
@Preview
@Composable
fun ExtensionReposContentPreview() {
val repos = persistentSetOf(
ExtensionRepo("url1", "Repo 1", "", "", "key1"),
ExtensionRepo("url2", "Repo 2", "", "", "key2"),
ExtensionRepo("https://raw.githubusercontent.com/komikku-app/extensions/repo", "Komikku", "", "", "key1"),
ExtensionRepo("https://raw.githubusercontent.com/keiyoushi/extensions/repo", "Keiyoushi", "", "", "key2"),
ExtensionRepo("https://repo", "Other", "", "", "key2"),
)
ExtensionReposContent(
repos = repos,
@ -175,7 +201,7 @@ fun ExtensionReposContentPreview() {
onClickDelete = {},
onClickEnable = {},
onClickDisable = {},
disabledRepos = setOf("url2"),
disabledRepos = setOf("https://repo"),
)
}
// KMK <--

View file

@ -76,6 +76,7 @@ fun ExtensionReposScreen(
EmptyScreen(
MR.strings.information_empty_repos,
modifier = Modifier.padding(paddingValues),
// KMK -->
help = {
TextButton(
onClick = { context.openInBrowser(OFFICIAL_REPO_WEBSITE) },
@ -86,6 +87,7 @@ fun ExtensionReposScreen(
Text(text = stringResource(MR.strings.label_help))
}
},
// KMK <--
)
return@Scaffold
}
@ -112,10 +114,11 @@ fun ExtensionReposScreen(
private fun ExtensionReposScreenPreview() {
val state = RepoScreenState.Success(
repos = persistentSetOf(
ExtensionRepo("url1", "Repo 1", "", "", "key1"),
ExtensionRepo("url2", "Repo 2", "", "", "key2"),
ExtensionRepo("https://raw.githubusercontent.com/komikku-app/extensions/repo", "Komikku", "", "", "key1"),
ExtensionRepo("https://raw.githubusercontent.com/keiyoushi/extensions/repo", "Keiyoushi", "", "", "key2"),
ExtensionRepo("https://repo", "Other", "", "", "key2"),
),
disabledRepos = setOf("url2"),
disabledRepos = setOf("https://repo"),
)
ExtensionReposScreen(
state = state,

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -40,13 +40,17 @@ fun EmptyScreen(
stringRes: StringResource,
modifier: Modifier = Modifier,
actions: ImmutableList<EmptyScreenAction>? = null,
// KMK -->
help: @Composable (() -> Unit)? = null,
// KMK <--
) {
EmptyScreen(
message = stringResource(stringRes),
modifier = modifier,
actions = actions,
// KMK -->
help = help,
// KMK <--
)
}
@ -55,7 +59,9 @@ fun EmptyScreen(
message: String,
modifier: Modifier = Modifier,
actions: ImmutableList<EmptyScreenAction>? = null,
// KMK -->
help: @Composable (() -> Unit)? = null,
// KMK <--
) {
val face = remember { getRandomErrorFace() }
Column(
@ -83,7 +89,9 @@ fun EmptyScreen(
textAlign = TextAlign.Center,
)
// KMK -->
help?.let { help() }
// KMK <--
if (!actions.isNullOrEmpty()) {
Row(