123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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.PaddingValues
- import androidx.compose.foundation.layout.fillMaxHeight
- import androidx.compose.foundation.layout.fillMaxSize
- import androidx.compose.foundation.layout.fillMaxWidth
- import androidx.compose.foundation.layout.padding
- import androidx.compose.foundation.lazy.grid.items
- import androidx.compose.foundation.shape.RoundedCornerShape
- import androidx.compose.material3.MaterialTheme
- 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.Brush
- import androidx.compose.ui.graphics.Color
- import androidx.compose.ui.graphics.Shadow
- import androidx.compose.ui.text.style.TextOverflow
- import androidx.compose.ui.unit.dp
- import androidx.compose.ui.unit.sp
- import eu.kanade.domain.library.model.LibraryManga
- import eu.kanade.tachiyomi.ui.library.LibraryItem
- @Composable
- fun LibraryCompactGrid(
- items: List<LibraryItem>,
- columns: Int,
- contentPadding: PaddingValues,
- selection: List<LibraryManga>,
- onClick: (LibraryManga) -> Unit,
- onLongClick: (LibraryManga) -> Unit,
- searchQuery: String?,
- onGlobalSearchClicked: () -> Unit,
- ) {
- LazyLibraryGrid(
- modifier = Modifier.fillMaxSize(),
- columns = columns,
- contentPadding = contentPadding,
- ) {
- globalSearchItem(searchQuery, onGlobalSearchClicked)
- items(
- items = items,
- contentType = { "library_compact_grid_item" },
- ) { libraryItem ->
- LibraryCompactGridItem(
- item = libraryItem,
- isSelected = libraryItem.libraryManga in selection,
- onClick = onClick,
- onLongClick = onLongClick,
- )
- }
- }
- }
- @Composable
- fun LibraryCompactGridItem(
- item: LibraryItem,
- isSelected: Boolean,
- onClick: (LibraryManga) -> Unit,
- onLongClick: (LibraryManga) -> Unit,
- ) {
- val libraryManga = item.libraryManga
- val manga = libraryManga.manga
- LibraryGridCover(
- modifier = Modifier
- .selectedOutline(isSelected)
- .combinedClickable(
- onClick = {
- onClick(libraryManga)
- },
- onLongClick = {
- onLongClick(libraryManga)
- },
- ),
- mangaCover = eu.kanade.domain.manga.model.MangaCover(
- manga.id,
- manga.source,
- manga.favorite,
- manga.thumbnailUrl,
- manga.coverLastModified,
- ),
- downloadCount = item.downloadCount,
- unreadCount = item.unreadCount,
- isLocal = item.isLocal,
- language = item.sourceLanguage,
- ) {
- Box(
- modifier = Modifier
- .clip(RoundedCornerShape(bottomStart = 4.dp, bottomEnd = 4.dp))
- .background(
- Brush.verticalGradient(
- 0f to Color.Transparent,
- 1f to Color(0xAA000000),
- ),
- )
- .fillMaxHeight(0.33f)
- .fillMaxWidth()
- .align(Alignment.BottomCenter),
- )
- 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,
- overflow = TextOverflow.Ellipsis,
- style = MaterialTheme.typography.titleSmall.copy(
- shadow = Shadow(
- color = Color.Black,
- blurRadius = 4f,
- ),
- ),
- )
- }
|