GlobalSearchCardRow.kt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package eu.kanade.presentation.browse.components
  2. import androidx.compose.foundation.layout.Arrangement
  3. import androidx.compose.foundation.layout.Box
  4. import androidx.compose.foundation.layout.PaddingValues
  5. import androidx.compose.foundation.layout.width
  6. import androidx.compose.foundation.lazy.LazyRow
  7. import androidx.compose.foundation.lazy.items
  8. import androidx.compose.material3.MaterialTheme
  9. import androidx.compose.runtime.Composable
  10. import androidx.compose.runtime.State
  11. import androidx.compose.runtime.getValue
  12. import androidx.compose.ui.Modifier
  13. import androidx.compose.ui.unit.dp
  14. import eu.kanade.presentation.library.components.CommonMangaItemDefaults
  15. import eu.kanade.presentation.library.components.MangaComfortableGridItem
  16. import tachiyomi.domain.manga.model.Manga
  17. import tachiyomi.domain.manga.model.MangaCover
  18. import tachiyomi.domain.manga.model.asMangaCover
  19. import tachiyomi.presentation.core.components.material.padding
  20. @Composable
  21. fun GlobalSearchCardRow(
  22. titles: List<Manga>,
  23. getManga: @Composable (Manga) -> State<Manga>,
  24. onClick: (Manga) -> Unit,
  25. onLongClick: (Manga) -> Unit,
  26. ) {
  27. LazyRow(
  28. contentPadding = PaddingValues(MaterialTheme.padding.small),
  29. horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.tiny),
  30. ) {
  31. items(titles) {
  32. val title by getManga(it)
  33. GlobalSearchCard(
  34. title = title.title,
  35. cover = title.asMangaCover(),
  36. isFavorite = title.favorite,
  37. onClick = { onClick(title) },
  38. onLongClick = { onLongClick(title) },
  39. )
  40. }
  41. }
  42. }
  43. @Composable
  44. private fun GlobalSearchCard(
  45. title: String,
  46. cover: MangaCover,
  47. isFavorite: Boolean,
  48. onClick: () -> Unit,
  49. onLongClick: () -> Unit,
  50. ) {
  51. Box(modifier = Modifier.width(96.dp)) {
  52. MangaComfortableGridItem(
  53. title = title,
  54. coverData = cover,
  55. coverBadgeStart = {
  56. InLibraryBadge(enabled = isFavorite)
  57. },
  58. coverAlpha = if (isFavorite) CommonMangaItemDefaults.BrowseFavoriteCoverAlpha else 1f,
  59. onClick = onClick,
  60. onLongClick = onLongClick,
  61. )
  62. }
  63. }