mihon/app/src/main/java/eu/kanade/presentation/browse/MigrateMangaScreen.kt

103 lines
3.2 KiB
Kotlin
Raw Normal View History

package eu.kanade.presentation.browse
2022-07-16 21:00:01 -04:00
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
2022-07-16 21:00:01 -04:00
import androidx.compose.foundation.layout.statusBarsPadding
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
2022-07-16 21:00:01 -04:00
import eu.kanade.presentation.components.AppBar
import eu.kanade.presentation.components.EmptyScreen
import eu.kanade.presentation.components.LoadingScreen
2022-07-16 21:00:01 -04:00
import eu.kanade.presentation.components.Scaffold
import eu.kanade.presentation.components.ScrollbarLazyColumn
import eu.kanade.presentation.manga.components.BaseMangaListItem
2022-07-16 21:00:01 -04:00
import eu.kanade.presentation.util.plus
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(
2022-07-16 21:00:01 -04:00
navigateUp: () -> Unit,
title: String?,
presenter: MigrateMangaPresenter,
onClickItem: (Manga) -> Unit,
2022-05-10 17:54:52 -04:00
onClickCover: (Manga) -> Unit,
) {
val context = LocalContext.current
2022-07-16 21:00:01 -04:00
Scaffold(
modifier = Modifier.statusBarsPadding(),
topBar = {
AppBar(
title = title,
navigateUp = navigateUp,
)
2022-07-16 21:00:01 -04:00
},
) { paddingValues ->
when {
presenter.isLoading -> LoadingScreen()
presenter.isEmpty -> EmptyScreen(textResource = R.string.empty_screen)
else -> {
MigrateMangaContent(
paddingValues = paddingValues,
state = presenter,
onClickItem = onClickItem,
onClickCover = onClickCover,
)
}
}
}
LaunchedEffect(Unit) {
presenter.events.collectLatest { event ->
when (event) {
Event.FailedFetchingFavorites -> {
context.toast(R.string.internal_error)
}
}
}
}
}
@Composable
fun MigrateMangaContent(
2022-07-16 21:00:01 -04:00
paddingValues: PaddingValues,
state: MigrateMangaState,
onClickItem: (Manga) -> Unit,
2022-05-10 17:54:52 -04:00
onClickCover: (Manga) -> Unit,
) {
ScrollbarLazyColumn(
2022-07-16 21:00:01 -04:00
contentPadding = paddingValues + WindowInsets.navigationBars.asPaddingValues(),
) {
items(state.items) { manga ->
MigrateMangaItem(
manga = manga,
onClickItem = onClickItem,
2022-05-10 17:54:52 -04:00
onClickCover = onClickCover,
)
}
}
}
@Composable
fun MigrateMangaItem(
modifier: Modifier = Modifier,
manga: Manga,
onClickItem: (Manga) -> Unit,
2022-05-10 17:54:52 -04:00
onClickCover: (Manga) -> Unit,
) {
BaseMangaListItem(
modifier = modifier,
manga = manga,
onClickItem = { onClickItem(manga) },
2022-05-10 17:54:52 -04:00
onClickCover = { onClickCover(manga) },
)
}