mirror of
https://github.com/mihonapp/mihon.git
synced 2024-10-31 21:20:59 -04:00
26b46cace0
Co-authored-by: arkon <arkon@users.noreply.github.com>
101 lines
3 KiB
Kotlin
101 lines
3 KiB
Kotlin
package eu.kanade.presentation.browse
|
|
|
|
import androidx.compose.foundation.layout.PaddingValues
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.lazy.items
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import eu.kanade.domain.manga.model.Manga
|
|
import eu.kanade.presentation.components.AppBar
|
|
import eu.kanade.presentation.components.EmptyScreen
|
|
import eu.kanade.presentation.components.FastScrollLazyColumn
|
|
import eu.kanade.presentation.components.LoadingScreen
|
|
import eu.kanade.presentation.components.Scaffold
|
|
import eu.kanade.presentation.manga.components.BaseMangaListItem
|
|
import eu.kanade.tachiyomi.R
|
|
import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrateMangaPresenter
|
|
import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrateMangaPresenter.Event
|
|
import eu.kanade.tachiyomi.util.system.toast
|
|
import kotlinx.coroutines.flow.collectLatest
|
|
|
|
@Composable
|
|
fun MigrateMangaScreen(
|
|
navigateUp: () -> Unit,
|
|
title: String?,
|
|
presenter: MigrateMangaPresenter,
|
|
onClickItem: (Manga) -> Unit,
|
|
onClickCover: (Manga) -> Unit,
|
|
) {
|
|
val context = LocalContext.current
|
|
Scaffold(
|
|
topBar = { scrollBehavior ->
|
|
AppBar(
|
|
title = title,
|
|
navigateUp = navigateUp,
|
|
scrollBehavior = scrollBehavior,
|
|
)
|
|
},
|
|
) { contentPadding ->
|
|
when {
|
|
presenter.isLoading -> LoadingScreen()
|
|
presenter.isEmpty -> EmptyScreen(
|
|
textResource = R.string.empty_screen,
|
|
modifier = Modifier.padding(contentPadding),
|
|
)
|
|
else -> {
|
|
MigrateMangaContent(
|
|
contentPadding = contentPadding,
|
|
state = presenter,
|
|
onClickItem = onClickItem,
|
|
onClickCover = onClickCover,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
LaunchedEffect(Unit) {
|
|
presenter.events.collectLatest { event ->
|
|
when (event) {
|
|
Event.FailedFetchingFavorites -> {
|
|
context.toast(R.string.internal_error)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun MigrateMangaContent(
|
|
contentPadding: PaddingValues,
|
|
state: MigrateMangaState,
|
|
onClickItem: (Manga) -> Unit,
|
|
onClickCover: (Manga) -> Unit,
|
|
) {
|
|
FastScrollLazyColumn(
|
|
contentPadding = contentPadding,
|
|
) {
|
|
items(state.items) { manga ->
|
|
MigrateMangaItem(
|
|
manga = manga,
|
|
onClickItem = onClickItem,
|
|
onClickCover = onClickCover,
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun MigrateMangaItem(
|
|
modifier: Modifier = Modifier,
|
|
manga: Manga,
|
|
onClickItem: (Manga) -> Unit,
|
|
onClickCover: (Manga) -> Unit,
|
|
) {
|
|
BaseMangaListItem(
|
|
modifier = modifier,
|
|
manga = manga,
|
|
onClickItem = { onClickItem(manga) },
|
|
onClickCover = { onClickCover(manga) },
|
|
)
|
|
}
|