2022-05-07 23:34:55 -04:00
|
|
|
package eu.kanade.presentation.browse
|
2022-04-30 09:37:10 -04:00
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.WindowInsets
|
|
|
|
import androidx.compose.foundation.layout.asPaddingValues
|
|
|
|
import androidx.compose.foundation.layout.navigationBars
|
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
|
import androidx.compose.runtime.Composable
|
2022-07-16 14:44:37 -04:00
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
2022-04-30 09:37:10 -04:00
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
|
|
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
2022-07-16 14:44:37 -04:00
|
|
|
import androidx.compose.ui.platform.LocalContext
|
2022-04-30 09:37:10 -04:00
|
|
|
import eu.kanade.domain.manga.model.Manga
|
|
|
|
import eu.kanade.presentation.components.EmptyScreen
|
|
|
|
import eu.kanade.presentation.components.LoadingScreen
|
2022-05-23 18:03:46 -04:00
|
|
|
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
2022-04-30 09:37:10 -04:00
|
|
|
import eu.kanade.presentation.manga.components.BaseMangaListItem
|
|
|
|
import eu.kanade.tachiyomi.R
|
2022-07-16 14:44:37 -04:00
|
|
|
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
|
2022-04-30 09:37:10 -04:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun MigrateMangaScreen(
|
|
|
|
nestedScrollInterop: NestedScrollConnection,
|
2022-07-16 14:44:37 -04:00
|
|
|
presenter: MigrateMangaPresenter,
|
2022-04-30 09:37:10 -04:00
|
|
|
onClickItem: (Manga) -> Unit,
|
2022-05-10 17:54:52 -04:00
|
|
|
onClickCover: (Manga) -> Unit,
|
2022-04-30 09:37:10 -04:00
|
|
|
) {
|
2022-07-16 14:44:37 -04:00
|
|
|
val context = LocalContext.current
|
|
|
|
when {
|
|
|
|
presenter.isLoading -> LoadingScreen()
|
|
|
|
presenter.isEmpty -> EmptyScreen(textResource = R.string.empty_screen)
|
|
|
|
else -> {
|
2022-04-30 09:37:10 -04:00
|
|
|
MigrateMangaContent(
|
|
|
|
nestedScrollInterop = nestedScrollInterop,
|
2022-07-16 14:44:37 -04:00
|
|
|
state = presenter,
|
2022-04-30 09:37:10 -04:00
|
|
|
onClickItem = onClickItem,
|
|
|
|
onClickCover = onClickCover,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2022-07-16 14:44:37 -04:00
|
|
|
LaunchedEffect(Unit) {
|
|
|
|
presenter.events.collectLatest { event ->
|
|
|
|
when (event) {
|
|
|
|
Event.FailedFetchingFavorites -> {
|
|
|
|
context.toast(R.string.internal_error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 09:37:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun MigrateMangaContent(
|
|
|
|
nestedScrollInterop: NestedScrollConnection,
|
2022-07-16 14:44:37 -04:00
|
|
|
state: MigrateMangaState,
|
2022-04-30 09:37:10 -04:00
|
|
|
onClickItem: (Manga) -> Unit,
|
2022-05-10 17:54:52 -04:00
|
|
|
onClickCover: (Manga) -> Unit,
|
2022-04-30 09:37:10 -04:00
|
|
|
) {
|
2022-05-23 18:03:46 -04:00
|
|
|
ScrollbarLazyColumn(
|
2022-04-30 09:37:10 -04:00
|
|
|
modifier = Modifier.nestedScroll(nestedScrollInterop),
|
|
|
|
contentPadding = WindowInsets.navigationBars.asPaddingValues(),
|
|
|
|
) {
|
2022-07-16 14:44:37 -04:00
|
|
|
items(state.items) { manga ->
|
2022-04-30 09:37:10 -04:00
|
|
|
MigrateMangaItem(
|
|
|
|
manga = manga,
|
|
|
|
onClickItem = onClickItem,
|
2022-05-10 17:54:52 -04:00
|
|
|
onClickCover = onClickCover,
|
2022-04-30 09:37:10 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun MigrateMangaItem(
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
manga: Manga,
|
|
|
|
onClickItem: (Manga) -> Unit,
|
2022-05-10 17:54:52 -04:00
|
|
|
onClickCover: (Manga) -> Unit,
|
2022-04-30 09:37:10 -04:00
|
|
|
) {
|
|
|
|
BaseMangaListItem(
|
|
|
|
modifier = modifier,
|
|
|
|
manga = manga,
|
|
|
|
onClickItem = { onClickItem(manga) },
|
2022-05-10 17:54:52 -04:00
|
|
|
onClickCover = { onClickCover(manga) },
|
2022-04-30 09:37:10 -04:00
|
|
|
)
|
|
|
|
}
|