mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 16:01:49 +01:00
Fix derivedStateOf errors (#8008)
This commit is contained in:
parent
82cd316493
commit
6865c21c75
@ -11,6 +11,7 @@ import eu.kanade.presentation.library.components.LibraryContent
|
|||||||
import eu.kanade.presentation.library.components.LibraryToolbar
|
import eu.kanade.presentation.library.components.LibraryToolbar
|
||||||
import eu.kanade.tachiyomi.source.LocalSource
|
import eu.kanade.tachiyomi.source.LocalSource
|
||||||
import eu.kanade.tachiyomi.ui.library.LibraryPresenter
|
import eu.kanade.tachiyomi.ui.library.LibraryPresenter
|
||||||
|
import eu.kanade.tachiyomi.ui.library.setting.display
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LibraryScreen(
|
fun LibraryScreen(
|
||||||
@ -72,7 +73,7 @@ fun LibraryScreen(
|
|||||||
onRefresh = onClickRefresh,
|
onRefresh = onClickRefresh,
|
||||||
onGlobalSearchClicked = onGlobalSearchClicked,
|
onGlobalSearchClicked = onGlobalSearchClicked,
|
||||||
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
|
||||||
getDisplayModeForPage = { presenter.getDisplayMode(index = it) },
|
getDisplayModeForPage = { presenter.categories[it].display },
|
||||||
getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) },
|
getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) },
|
||||||
getLibraryForPage = { presenter.getMangaForCategory(page = it) },
|
getLibraryForPage = { presenter.getMangaForCategory(page = it) },
|
||||||
isIncognitoMode = presenter.isIncognitoMode,
|
isIncognitoMode = presenter.isIncognitoMode,
|
||||||
|
@ -45,9 +45,9 @@ fun LibraryContent(
|
|||||||
onRefresh: (Category?) -> Boolean,
|
onRefresh: (Category?) -> Boolean,
|
||||||
onGlobalSearchClicked: () -> Unit,
|
onGlobalSearchClicked: () -> Unit,
|
||||||
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
|
||||||
getDisplayModeForPage: @Composable (Int) -> State<LibraryDisplayMode>,
|
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
|
||||||
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
||||||
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
|
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(contentPadding),
|
modifier = Modifier.padding(contentPadding),
|
||||||
|
@ -3,7 +3,6 @@ package eu.kanade.presentation.library.components
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@ -24,9 +23,9 @@ fun LibraryPager(
|
|||||||
selectedManga: List<LibraryManga>,
|
selectedManga: List<LibraryManga>,
|
||||||
searchQuery: String?,
|
searchQuery: String?,
|
||||||
onGlobalSearchClicked: () -> Unit,
|
onGlobalSearchClicked: () -> Unit,
|
||||||
getDisplayModeForPage: @Composable (Int) -> State<LibraryDisplayMode>,
|
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
|
||||||
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
|
||||||
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
|
getLibraryForPage: @Composable (Int) -> List<LibraryItem>,
|
||||||
onClickManga: (LibraryManga) -> Unit,
|
onClickManga: (LibraryManga) -> Unit,
|
||||||
onLongClickManga: (LibraryManga) -> Unit,
|
onLongClickManga: (LibraryManga) -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -40,8 +39,8 @@ fun LibraryPager(
|
|||||||
// To make sure only one offscreen page is being composed
|
// To make sure only one offscreen page is being composed
|
||||||
return@HorizontalPager
|
return@HorizontalPager
|
||||||
}
|
}
|
||||||
val library by getLibraryForPage(page)
|
val library = getLibraryForPage(page)
|
||||||
val displayMode by getDisplayModeForPage(page)
|
val displayMode = getDisplayModeForPage(page)
|
||||||
val columns by if (displayMode != LibraryDisplayMode.List) {
|
val columns by if (displayMode != LibraryDisplayMode.List) {
|
||||||
val configuration = LocalConfiguration.current
|
val configuration = LocalConfiguration.current
|
||||||
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
|
@ -43,9 +43,7 @@ import eu.kanade.tachiyomi.source.SourceManager
|
|||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
import eu.kanade.tachiyomi.ui.library.setting.LibraryDisplayMode
|
|
||||||
import eu.kanade.tachiyomi.ui.library.setting.LibrarySort
|
import eu.kanade.tachiyomi.ui.library.setting.LibrarySort
|
||||||
import eu.kanade.tachiyomi.ui.library.setting.display
|
|
||||||
import eu.kanade.tachiyomi.ui.library.setting.sort
|
import eu.kanade.tachiyomi.ui.library.setting.sort
|
||||||
import eu.kanade.tachiyomi.util.lang.combineLatest
|
import eu.kanade.tachiyomi.util.lang.combineLatest
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
@ -642,13 +640,12 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun getMangaForCategory(page: Int): androidx.compose.runtime.State<List<LibraryItem>> {
|
fun getMangaForCategory(page: Int): List<LibraryItem> {
|
||||||
val categoryId = remember(categories) {
|
val unfiltered = remember(categories, loadedManga) {
|
||||||
categories.getOrNull(page)?.id ?: -1
|
val categoryId = categories.getOrNull(page)?.id ?: -1
|
||||||
|
loadedManga[categoryId] ?: emptyList()
|
||||||
}
|
}
|
||||||
val unfiltered = loadedManga[categoryId] ?: emptyList()
|
return remember(unfiltered) {
|
||||||
|
|
||||||
return derivedStateOf {
|
|
||||||
val query = searchQuery
|
val query = searchQuery
|
||||||
if (query.isNullOrBlank().not()) {
|
if (query.isNullOrBlank().not()) {
|
||||||
unfiltered.filter {
|
unfiltered.filter {
|
||||||
@ -660,14 +657,6 @@ class LibraryPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun getDisplayMode(index: Int): androidx.compose.runtime.State<LibraryDisplayMode> {
|
|
||||||
val category = categories[index]
|
|
||||||
return derivedStateOf {
|
|
||||||
category.display
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearSelection() {
|
fun clearSelection() {
|
||||||
state.selection = emptyList()
|
state.selection = emptyList()
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import androidx.compose.material3.SnackbarHostState
|
|||||||
import androidx.compose.material3.SnackbarResult
|
import androidx.compose.material3.SnackbarResult
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
@ -111,13 +110,6 @@ class MangaController : FullComposeController<MangaPresenter> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val dialog by derivedStateOf {
|
|
||||||
when (val state = state) {
|
|
||||||
MangaScreenState.Loading -> null
|
|
||||||
is MangaScreenState.Success -> state.dialog
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val successState = state as MangaScreenState.Success
|
val successState = state as MangaScreenState.Success
|
||||||
val isHttpSource = remember { successState.source is HttpSource }
|
val isHttpSource = remember { successState.source is HttpSource }
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@ -152,7 +144,7 @@ class MangaController : FullComposeController<MangaPresenter> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val onDismissRequest = { presenter.dismissDialog() }
|
val onDismissRequest = { presenter.dismissDialog() }
|
||||||
when (val dialog = dialog) {
|
when (val dialog = (state as? MangaScreenState.Success)?.dialog) {
|
||||||
is Dialog.ChangeCategory -> {
|
is Dialog.ChangeCategory -> {
|
||||||
ChangeCategoryDialog(
|
ChangeCategoryDialog(
|
||||||
initialSelection = dialog.initialSelection,
|
initialSelection = dialog.initialSelection,
|
||||||
|
Loading…
Reference in New Issue
Block a user