mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 03:58:56 +01:00
Use Compose on BrowseSourceScreens (#7901)
This commit is contained in:
@@ -78,13 +78,22 @@ fun LibraryComfortableGridItem(
|
||||
isLocal = item.isLocal,
|
||||
language = item.sourceLanguage,
|
||||
)
|
||||
Text(
|
||||
modifier = Modifier.padding(4.dp),
|
||||
MangaGridComfortableText(
|
||||
text = manga.title,
|
||||
fontSize = 12.sp,
|
||||
maxLines = 2,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MangaGridComfortableText(
|
||||
text: String,
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier.padding(4.dp),
|
||||
text = text,
|
||||
fontSize = 12.sp,
|
||||
maxLines = 2,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.kanade.presentation.library.components
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -97,20 +98,27 @@ fun LibraryCompactGridItem(
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.BottomCenter),
|
||||
)
|
||||
Text(
|
||||
text = manga.title,
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.align(Alignment.BottomStart),
|
||||
color = Color.White,
|
||||
fontSize = 12.sp,
|
||||
maxLines = 2,
|
||||
style = MaterialTheme.typography.titleSmall.copy(
|
||||
shadow = Shadow(
|
||||
color = Color.Black,
|
||||
blurRadius = 4f,
|
||||
),
|
||||
),
|
||||
)
|
||||
MangaGridCompactText(manga.title)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BoxScope.MangaGridCompactText(
|
||||
text: String,
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.align(Alignment.BottomStart),
|
||||
color = Color.White,
|
||||
fontSize = 12.sp,
|
||||
maxLines = 2,
|
||||
style = MaterialTheme.typography.titleSmall.copy(
|
||||
shadow = Shadow(
|
||||
color = Color.Black,
|
||||
blurRadius = 4f,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.kanade.presentation.library.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -16,6 +17,41 @@ import eu.kanade.presentation.components.BadgeGroup
|
||||
import eu.kanade.presentation.components.MangaCover
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
||||
@Composable
|
||||
fun MangaGridCover(
|
||||
modifier: Modifier = Modifier,
|
||||
cover: @Composable BoxScope.() -> Unit = {},
|
||||
badgesStart: (@Composable RowScope.() -> Unit)? = null,
|
||||
badgesEnd: (@Composable RowScope.() -> Unit)? = null,
|
||||
content: @Composable BoxScope.() -> Unit = {},
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(MangaCover.Book.ratio),
|
||||
) {
|
||||
cover()
|
||||
content()
|
||||
if (badgesStart != null) {
|
||||
BadgeGroup(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.align(Alignment.TopStart),
|
||||
content = badgesStart,
|
||||
)
|
||||
}
|
||||
|
||||
if (badgesEnd != null) {
|
||||
BadgeGroup(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.align(Alignment.TopEnd),
|
||||
content = badgesEnd,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LibraryGridCover(
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -26,54 +62,41 @@ fun LibraryGridCover(
|
||||
language: String,
|
||||
content: @Composable BoxScope.() -> Unit = {},
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(MangaCover.Book.ratio),
|
||||
) {
|
||||
MangaCover.Book(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
data = mangaCover,
|
||||
)
|
||||
content()
|
||||
if (downloadCount > 0 || unreadCount > 0) {
|
||||
BadgeGroup(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.align(Alignment.TopStart),
|
||||
) {
|
||||
if (downloadCount > 0) {
|
||||
Badge(
|
||||
text = "$downloadCount",
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
if (unreadCount > 0) {
|
||||
Badge(text = "$unreadCount")
|
||||
}
|
||||
MangaGridCover(
|
||||
modifier = modifier,
|
||||
cover = {
|
||||
MangaCover.Book(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
data = mangaCover,
|
||||
)
|
||||
},
|
||||
badgesStart = {
|
||||
if (downloadCount > 0) {
|
||||
Badge(
|
||||
text = "$downloadCount",
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (isLocal || language.isNotEmpty()) {
|
||||
BadgeGroup(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.align(Alignment.TopEnd),
|
||||
) {
|
||||
if (isLocal) {
|
||||
Badge(
|
||||
text = stringResource(R.string.local_source_badge),
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
} else if (language.isNotEmpty()) {
|
||||
Badge(
|
||||
text = language,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
if (unreadCount > 0) {
|
||||
Badge(text = "$unreadCount")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
badgesEnd = {
|
||||
if (isLocal) {
|
||||
Badge(
|
||||
text = stringResource(R.string.local_source_badge),
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
} else if (language.isNotEmpty()) {
|
||||
Badge(
|
||||
text = language,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
},
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.kanade.presentation.library.components
|
||||
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
@@ -19,6 +20,7 @@ import eu.kanade.domain.manga.model.MangaCover
|
||||
import eu.kanade.presentation.components.Badge
|
||||
import eu.kanade.presentation.components.BadgeGroup
|
||||
import eu.kanade.presentation.components.FastScrollLazyColumn
|
||||
import eu.kanade.presentation.components.MangaCover.Square
|
||||
import eu.kanade.presentation.components.TextButton
|
||||
import eu.kanade.presentation.util.bottomNavPaddingValues
|
||||
import eu.kanade.presentation.util.horizontalPadding
|
||||
@@ -74,62 +76,109 @@ fun LibraryListItem(
|
||||
onLongClick: (LibraryManga) -> Unit,
|
||||
) {
|
||||
val manga = item.manga
|
||||
MangaListItem(
|
||||
modifier = Modifier.selectedBackground(isSelected),
|
||||
title = manga.title,
|
||||
cover = MangaCover(
|
||||
manga.id!!,
|
||||
manga.source,
|
||||
manga.favorite,
|
||||
manga.thumbnail_url,
|
||||
manga.cover_last_modified,
|
||||
),
|
||||
onClick = { onClick(manga) },
|
||||
onLongClick = { onLongClick(manga) },
|
||||
) {
|
||||
if (item.downloadCount > 0) {
|
||||
Badge(
|
||||
text = "${item.downloadCount}",
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
if (item.unreadCount > 0) {
|
||||
Badge(text = "${item.unreadCount}")
|
||||
}
|
||||
if (item.isLocal) {
|
||||
Badge(
|
||||
text = stringResource(R.string.local_source_badge),
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
if (item.isLocal.not() && item.sourceLanguage.isNotEmpty()) {
|
||||
Badge(
|
||||
text = item.sourceLanguage,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MangaListItem(
|
||||
modifier: Modifier = Modifier,
|
||||
title: String,
|
||||
cover: MangaCover,
|
||||
onClick: () -> Unit,
|
||||
onLongClick: () -> Unit = onClick,
|
||||
badges: @Composable RowScope.() -> Unit,
|
||||
) {
|
||||
MangaListItem(
|
||||
modifier = modifier,
|
||||
coverContent = {
|
||||
Square(
|
||||
modifier = Modifier
|
||||
.padding(vertical = verticalPadding)
|
||||
.fillMaxHeight(),
|
||||
data = cover,
|
||||
)
|
||||
},
|
||||
badges = badges,
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
content = {
|
||||
MangaListItemContent(title)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MangaListItem(
|
||||
modifier: Modifier = Modifier,
|
||||
coverContent: @Composable RowScope.() -> Unit,
|
||||
badges: @Composable RowScope.() -> Unit,
|
||||
onClick: () -> Unit,
|
||||
onLongClick: () -> Unit,
|
||||
content: @Composable RowScope.() -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.selectedBackground(isSelected)
|
||||
modifier = modifier
|
||||
.height(56.dp)
|
||||
.combinedClickable(
|
||||
onClick = { onClick(manga) },
|
||||
onLongClick = { onLongClick(manga) },
|
||||
onClick = onClick,
|
||||
onLongClick = onLongClick,
|
||||
)
|
||||
.padding(horizontal = horizontalPadding),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
eu.kanade.presentation.components.MangaCover.Square(
|
||||
modifier = Modifier
|
||||
.padding(vertical = verticalPadding)
|
||||
.fillMaxHeight(),
|
||||
data = MangaCover(
|
||||
manga.id!!,
|
||||
manga.source,
|
||||
manga.favorite,
|
||||
manga.thumbnail_url,
|
||||
manga.cover_last_modified,
|
||||
),
|
||||
)
|
||||
Text(
|
||||
text = manga.title,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = horizontalPadding)
|
||||
.weight(1f),
|
||||
maxLines = 2,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
BadgeGroup {
|
||||
if (item.downloadCount > 0) {
|
||||
Badge(
|
||||
text = "${item.downloadCount}",
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
if (item.unreadCount > 0) {
|
||||
Badge(text = "${item.unreadCount}")
|
||||
}
|
||||
if (item.isLocal) {
|
||||
Badge(
|
||||
text = stringResource(R.string.local_source_badge),
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
if (item.isLocal.not() && item.sourceLanguage.isNotEmpty()) {
|
||||
Badge(
|
||||
text = item.sourceLanguage,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
textColor = MaterialTheme.colorScheme.onTertiary,
|
||||
)
|
||||
}
|
||||
}
|
||||
coverContent()
|
||||
content()
|
||||
BadgeGroup(content = badges)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RowScope.MangaListItemContent(
|
||||
text: String,
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = horizontalPadding)
|
||||
.weight(1f),
|
||||
maxLines = 2,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user