[优化] 优化代码
This commit is contained in:
@@ -35,7 +35,8 @@ import io.legado.app.R
|
|||||||
import io.legado.app.data.entities.BookGroup
|
import io.legado.app.data.entities.BookGroup
|
||||||
import io.legado.app.ui.config.bookshelfConfig.BookshelfConfig
|
import io.legado.app.ui.config.bookshelfConfig.BookshelfConfig
|
||||||
import io.legado.app.ui.widget.components.cover.BookCover
|
import io.legado.app.ui.widget.components.cover.BookCover
|
||||||
import io.legado.app.ui.widget.components.cover.BookCoverWithProgress
|
import io.legado.app.ui.widget.components.cover.BookshelfCover
|
||||||
|
import io.legado.app.ui.widget.components.cover.Cover
|
||||||
import io.legado.app.utils.toTimeAgo
|
import io.legado.app.utils.toTimeAgo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,6 +208,12 @@ fun BookGroupCover(
|
|||||||
.clip(RoundedCornerShape(4.dp))
|
.clip(RoundedCornerShape(4.dp))
|
||||||
.background(MaterialTheme.colorScheme.surfaceContainer)
|
.background(MaterialTheme.colorScheme.surfaceContainer)
|
||||||
) {
|
) {
|
||||||
|
if (!coverPath.isNullOrBlank()) {
|
||||||
|
Cover(
|
||||||
|
path = coverPath,
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
Column(modifier = Modifier.fillMaxSize()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
Row(modifier = Modifier.weight(1f)) {
|
Row(modifier = Modifier.weight(1f)) {
|
||||||
Box(
|
Box(
|
||||||
@@ -275,6 +282,7 @@ fun BookGroupCover(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BookGroupItemGrid(
|
fun BookGroupItemGrid(
|
||||||
@@ -357,7 +365,7 @@ fun BookItem(
|
|||||||
gridStyle = gridStyle,
|
gridStyle = gridStyle,
|
||||||
isCompact = isCompact,
|
isCompact = isCompact,
|
||||||
cover = { modifier ->
|
cover = { modifier ->
|
||||||
BookCoverWithProgress(
|
BookshelfCover(
|
||||||
name = book.name,
|
name = book.name,
|
||||||
author = book.author,
|
author = book.author,
|
||||||
path = book.getDisplayCover(),
|
path = book.getDisplayCover(),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.legado.app.ui.main.bookshelf
|
|||||||
|
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import io.legado.app.constant.BookType
|
import io.legado.app.constant.BookType
|
||||||
import io.legado.app.data.entities.Book
|
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
@@ -36,24 +35,3 @@ data class BookShelfItem(
|
|||||||
|
|
||||||
fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0)
|
fun getUnreadChapterNum() = max(totalChapterNum - durChapterIndex - 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Book.toBookShelfItem(): BookShelfItem {
|
|
||||||
return BookShelfItem(
|
|
||||||
bookUrl = bookUrl,
|
|
||||||
name = name,
|
|
||||||
author = author,
|
|
||||||
coverUrl = coverUrl,
|
|
||||||
customCoverUrl = customCoverUrl,
|
|
||||||
durChapterTitle = durChapterTitle,
|
|
||||||
durChapterTime = durChapterTime,
|
|
||||||
durChapterPos = durChapterPos,
|
|
||||||
latestChapterTitle = latestChapterTitle,
|
|
||||||
latestChapterTime = latestChapterTime,
|
|
||||||
totalChapterNum = totalChapterNum,
|
|
||||||
durChapterIndex = durChapterIndex,
|
|
||||||
type = type,
|
|
||||||
group = group,
|
|
||||||
order = order,
|
|
||||||
canUpdate = canUpdate
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ import android.text.TextUtils
|
|||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Update
|
import androidx.compose.material.icons.filled.Book
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
@@ -34,12 +35,12 @@ import androidx.compose.ui.graphics.nativeCanvas
|
|||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.graphics.withSave
|
import androidx.core.graphics.withSave
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import io.legado.app.ui.config.coverConfig.CoverConfig
|
import io.legado.app.ui.config.coverConfig.CoverConfig
|
||||||
import io.legado.app.ui.widget.components.card.TextCard
|
|
||||||
import org.koin.compose.koinInject
|
import org.koin.compose.koinInject
|
||||||
import io.legado.app.model.BookCover as BookCoverModel
|
import io.legado.app.model.BookCover as BookCoverModel
|
||||||
|
|
||||||
@@ -49,8 +50,6 @@ fun BookCover(
|
|||||||
author: String?,
|
author: String?,
|
||||||
path: String?,
|
path: String?,
|
||||||
modifier: Modifier = Modifier.width(64.dp),
|
modifier: Modifier = Modifier.width(64.dp),
|
||||||
badgeText: String? = null,
|
|
||||||
showBadgeDot: Boolean = false,
|
|
||||||
sourceOrigin: String? = null,
|
sourceOrigin: String? = null,
|
||||||
onLoadFinish: (() -> Unit)? = null,
|
onLoadFinish: (() -> Unit)? = null,
|
||||||
ignoreUseDefaultCover: Boolean = false
|
ignoreUseDefaultCover: Boolean = false
|
||||||
@@ -79,7 +78,7 @@ fun BookCover(
|
|||||||
isOnlineCoverLoaded = false
|
isOnlineCoverLoaded = false
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
BoxWithConstraints(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.aspectRatio(5f / 7f)
|
.aspectRatio(5f / 7f)
|
||||||
.then(
|
.then(
|
||||||
@@ -94,6 +93,11 @@ fun BookCover(
|
|||||||
} else Modifier
|
} else Modifier
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
val density = LocalDensity.current
|
||||||
|
val iconSizeDp = with(density) {
|
||||||
|
(minOf(maxWidth, maxHeight).toPx() / 3f).toDp()
|
||||||
|
}
|
||||||
|
|
||||||
if (hasCustomDefault) {
|
if (hasCustomDefault) {
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = ImageRequest.Builder(context)
|
model = ImageRequest.Builder(context)
|
||||||
@@ -134,6 +138,17 @@ fun BookCover(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hasCustomDefault && !isOnlineCoverLoaded) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Book,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.secondary,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(iconSizeDp)
|
||||||
|
.align(Alignment.Center)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (!isOnlineCoverLoaded) {
|
if (!isOnlineCoverLoaded) {
|
||||||
CoverTextOverlay(
|
CoverTextOverlay(
|
||||||
name = name,
|
name = name,
|
||||||
@@ -142,20 +157,6 @@ fun BookCover(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!badgeText.isNullOrEmpty()) {
|
|
||||||
TextCard(
|
|
||||||
text = badgeText,
|
|
||||||
icon = if (showBadgeDot) Icons.Default.Update else null,
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.TopEnd)
|
|
||||||
.padding(2.dp),
|
|
||||||
backgroundColor = MaterialTheme.colorScheme.secondaryContainer,
|
|
||||||
contentColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
||||||
cornerRadius = 4.dp,
|
|
||||||
horizontalPadding = 4.dp,
|
|
||||||
verticalPadding = 0.dp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-3
@@ -4,6 +4,8 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Update
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -11,9 +13,10 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.StrokeCap
|
import androidx.compose.ui.graphics.StrokeCap
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import io.legado.app.ui.widget.components.card.TextCard
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BookCoverWithProgress(
|
fun BookshelfCover(
|
||||||
name: String?,
|
name: String?,
|
||||||
author: String?,
|
author: String?,
|
||||||
path: String?,
|
path: String?,
|
||||||
@@ -30,12 +33,25 @@ fun BookCoverWithProgress(
|
|||||||
author = author,
|
author = author,
|
||||||
path = path,
|
path = path,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
badgeText = badgeText,
|
|
||||||
showBadgeDot = showBadgeDot,
|
|
||||||
sourceOrigin = sourceOrigin,
|
sourceOrigin = sourceOrigin,
|
||||||
onLoadFinish = onLoadFinish
|
onLoadFinish = onLoadFinish
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!badgeText.isNullOrEmpty()) {
|
||||||
|
TextCard(
|
||||||
|
text = badgeText,
|
||||||
|
icon = if (showBadgeDot) Icons.Default.Update else null,
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.TopEnd)
|
||||||
|
.padding(2.dp),
|
||||||
|
backgroundColor = MaterialTheme.colorScheme.secondaryContainer,
|
||||||
|
contentColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||||
|
cornerRadius = 4.dp,
|
||||||
|
horizontalPadding = 4.dp,
|
||||||
|
verticalPadding = 0.dp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (isUpdating) {
|
if (isUpdating) {
|
||||||
LinearProgressIndicator(
|
LinearProgressIndicator(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
VERSION_MAJOR=3
|
VERSION_MAJOR=3
|
||||||
VERSION_MINOR=26
|
VERSION_MINOR=26
|
||||||
VERSION_PATCH=8
|
VERSION_PATCH=8
|
||||||
VERSION_SUFFIX=1
|
VERSION_SUFFIX=0
|
||||||
# 1 = Pre, 0 = Release
|
# 1 = Pre, 0 = Release
|
||||||
Reference in New Issue
Block a user