LibraryCompactGrid.kt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package eu.kanade.presentation.library.components
  2. import androidx.compose.foundation.background
  3. import androidx.compose.foundation.combinedClickable
  4. import androidx.compose.foundation.layout.Box
  5. import androidx.compose.foundation.layout.BoxScope
  6. import androidx.compose.foundation.layout.PaddingValues
  7. import androidx.compose.foundation.layout.fillMaxHeight
  8. import androidx.compose.foundation.layout.fillMaxSize
  9. import androidx.compose.foundation.layout.fillMaxWidth
  10. import androidx.compose.foundation.layout.padding
  11. import androidx.compose.foundation.lazy.grid.items
  12. import androidx.compose.foundation.shape.RoundedCornerShape
  13. import androidx.compose.material3.MaterialTheme
  14. import androidx.compose.material3.Text
  15. import androidx.compose.runtime.Composable
  16. import androidx.compose.ui.Alignment
  17. import androidx.compose.ui.Modifier
  18. import androidx.compose.ui.draw.clip
  19. import androidx.compose.ui.graphics.Brush
  20. import androidx.compose.ui.graphics.Color
  21. import androidx.compose.ui.graphics.Shadow
  22. import androidx.compose.ui.text.style.TextOverflow
  23. import androidx.compose.ui.unit.dp
  24. import androidx.compose.ui.unit.sp
  25. import eu.kanade.domain.library.model.LibraryManga
  26. import eu.kanade.tachiyomi.ui.library.LibraryItem
  27. @Composable
  28. fun LibraryCompactGrid(
  29. items: List<LibraryItem>,
  30. columns: Int,
  31. contentPadding: PaddingValues,
  32. selection: List<LibraryManga>,
  33. onClick: (LibraryManga) -> Unit,
  34. onLongClick: (LibraryManga) -> Unit,
  35. searchQuery: String?,
  36. onGlobalSearchClicked: () -> Unit,
  37. ) {
  38. LazyLibraryGrid(
  39. modifier = Modifier.fillMaxSize(),
  40. columns = columns,
  41. contentPadding = contentPadding,
  42. ) {
  43. globalSearchItem(searchQuery, onGlobalSearchClicked)
  44. items(
  45. items = items,
  46. contentType = { "library_compact_grid_item" },
  47. ) { libraryItem ->
  48. LibraryCompactGridItem(
  49. item = libraryItem,
  50. isSelected = libraryItem.libraryManga in selection,
  51. onClick = onClick,
  52. onLongClick = onLongClick,
  53. )
  54. }
  55. }
  56. }
  57. @Composable
  58. fun LibraryCompactGridItem(
  59. item: LibraryItem,
  60. isSelected: Boolean,
  61. onClick: (LibraryManga) -> Unit,
  62. onLongClick: (LibraryManga) -> Unit,
  63. ) {
  64. val libraryManga = item.libraryManga
  65. val manga = libraryManga.manga
  66. LibraryGridCover(
  67. modifier = Modifier
  68. .selectedOutline(isSelected)
  69. .combinedClickable(
  70. onClick = {
  71. onClick(libraryManga)
  72. },
  73. onLongClick = {
  74. onLongClick(libraryManga)
  75. },
  76. ),
  77. mangaCover = eu.kanade.domain.manga.model.MangaCover(
  78. manga.id,
  79. manga.source,
  80. manga.favorite,
  81. manga.thumbnailUrl,
  82. manga.coverLastModified,
  83. ),
  84. downloadCount = item.downloadCount,
  85. unreadCount = item.unreadCount,
  86. isLocal = item.isLocal,
  87. language = item.sourceLanguage,
  88. ) {
  89. Box(
  90. modifier = Modifier
  91. .clip(RoundedCornerShape(bottomStart = 4.dp, bottomEnd = 4.dp))
  92. .background(
  93. Brush.verticalGradient(
  94. 0f to Color.Transparent,
  95. 1f to Color(0xAA000000),
  96. ),
  97. )
  98. .fillMaxHeight(0.33f)
  99. .fillMaxWidth()
  100. .align(Alignment.BottomCenter),
  101. )
  102. MangaGridCompactText(manga.title)
  103. }
  104. }
  105. @Composable
  106. fun BoxScope.MangaGridCompactText(
  107. text: String,
  108. ) {
  109. Text(
  110. text = text,
  111. modifier = Modifier
  112. .padding(8.dp)
  113. .align(Alignment.BottomStart),
  114. color = Color.White,
  115. fontSize = 12.sp,
  116. maxLines = 2,
  117. overflow = TextOverflow.Ellipsis,
  118. style = MaterialTheme.typography.titleSmall.copy(
  119. shadow = Shadow(
  120. color = Color.Black,
  121. blurRadius = 4f,
  122. ),
  123. ),
  124. )
  125. }