BaseSourceItem.kt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package eu.kanade.presentation.source.components
  2. import androidx.compose.foundation.combinedClickable
  3. import androidx.compose.foundation.layout.Column
  4. import androidx.compose.foundation.layout.Row
  5. import androidx.compose.foundation.layout.RowScope
  6. import androidx.compose.foundation.layout.padding
  7. import androidx.compose.material3.MaterialTheme
  8. import androidx.compose.material3.Text
  9. import androidx.compose.runtime.Composable
  10. import androidx.compose.ui.Alignment
  11. import androidx.compose.ui.Modifier
  12. import androidx.compose.ui.text.style.TextOverflow
  13. import androidx.compose.ui.unit.dp
  14. import eu.kanade.domain.source.model.Source
  15. import eu.kanade.presentation.source.SourceIcon
  16. import eu.kanade.presentation.util.horizontalPadding
  17. import eu.kanade.tachiyomi.util.system.LocaleHelper
  18. @Composable
  19. fun BaseSourceItem(
  20. modifier: Modifier = Modifier,
  21. source: Source,
  22. showLanguageInContent: Boolean = true,
  23. onClickItem: () -> Unit = {},
  24. onLongClickItem: () -> Unit = {},
  25. icon: @Composable RowScope.(Source) -> Unit = defaultIcon,
  26. action: @Composable RowScope.(Source) -> Unit = {},
  27. content: @Composable RowScope.(Source, Boolean) -> Unit = defaultContent,
  28. ) {
  29. Row(
  30. modifier = modifier
  31. .combinedClickable(
  32. onClick = onClickItem,
  33. onLongClick = onLongClickItem
  34. )
  35. .padding(horizontal = horizontalPadding, vertical = 8.dp),
  36. verticalAlignment = Alignment.CenterVertically
  37. ) {
  38. icon.invoke(this, source)
  39. content.invoke(this, source, showLanguageInContent)
  40. action.invoke(this, source)
  41. }
  42. }
  43. private val defaultIcon: @Composable RowScope.(Source) -> Unit = { source ->
  44. SourceIcon(source = source)
  45. }
  46. private val defaultContent: @Composable RowScope.(Source, Boolean) -> Unit = { source, showLanguageInContent ->
  47. Column(
  48. modifier = Modifier
  49. .padding(horizontal = horizontalPadding)
  50. .weight(1f)
  51. ) {
  52. Text(
  53. text = source.name,
  54. maxLines = 1,
  55. overflow = TextOverflow.Ellipsis,
  56. style = MaterialTheme.typography.bodyMedium
  57. )
  58. if (showLanguageInContent) {
  59. Text(
  60. text = LocaleHelper.getDisplayName(source.lang),
  61. maxLines = 1,
  62. overflow = TextOverflow.Ellipsis,
  63. style = MaterialTheme.typography.bodySmall
  64. )
  65. }
  66. }
  67. }