102 lines
4.1 KiB
Kotlin
102 lines
4.1 KiB
Kotlin
package eu.kanade.presentation.browse
|
|
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.State
|
|
import androidx.compose.runtime.collectAsState
|
|
import androidx.compose.runtime.getValue
|
|
import eu.kanade.presentation.browse.components.GlobalSearchToolbar
|
|
import eu.kanade.presentation.components.BulkSelectionToolbar
|
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
|
import eu.kanade.tachiyomi.ui.browse.BulkFavoriteScreenModel
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SearchItemResult
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SearchScreenModel
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SourceFilter
|
|
import tachiyomi.domain.manga.model.Manga
|
|
import tachiyomi.presentation.core.components.material.Scaffold
|
|
|
|
@Composable
|
|
fun MigrateSearchScreen(
|
|
state: SearchScreenModel.State,
|
|
fromSourceId: Long?,
|
|
navigateUp: () -> Unit,
|
|
onChangeSearchQuery: (String?) -> Unit,
|
|
onSearch: (String) -> Unit,
|
|
onChangeSearchFilter: (SourceFilter) -> Unit,
|
|
onToggleResults: () -> Unit,
|
|
getManga: @Composable (Manga) -> State<Manga>,
|
|
onClickSource: (CatalogueSource) -> Unit,
|
|
onClickItem: (Manga) -> Unit,
|
|
onLongClickItem: (Manga) -> Unit,
|
|
// KMK -->
|
|
bulkFavoriteScreenModel: BulkFavoriteScreenModel,
|
|
// KMK <--
|
|
) {
|
|
// KMK -->
|
|
val bulkFavoriteState by bulkFavoriteScreenModel.state.collectAsState()
|
|
// KMK <--
|
|
|
|
Scaffold(
|
|
topBar = { scrollBehavior ->
|
|
// KMK -->
|
|
if (bulkFavoriteState.selectionMode) {
|
|
BulkSelectionToolbar(
|
|
selectedCount = bulkFavoriteState.selection.size,
|
|
isRunning = bulkFavoriteState.isRunning,
|
|
onClickClearSelection = bulkFavoriteScreenModel::toggleSelectionMode,
|
|
onChangeCategoryClick = bulkFavoriteScreenModel::addFavorite,
|
|
onSelectAll = {
|
|
state.filteredItems.forEach { (_, result) ->
|
|
when (result) {
|
|
is SearchItemResult.Success -> {
|
|
result.result.forEach { manga ->
|
|
bulkFavoriteScreenModel.select(manga)
|
|
}
|
|
}
|
|
else -> {}
|
|
}
|
|
}
|
|
},
|
|
onReverseSelection = {
|
|
bulkFavoriteScreenModel.reverseSelection(
|
|
state.filteredItems.values
|
|
.filterIsInstance<SearchItemResult.Success>()
|
|
.flatMap { it.result },
|
|
)
|
|
},
|
|
)
|
|
} else {
|
|
// KMK <--
|
|
GlobalSearchToolbar(
|
|
searchQuery = state.searchQuery,
|
|
progress = state.progress,
|
|
total = state.total,
|
|
navigateUp = navigateUp,
|
|
onChangeSearchQuery = onChangeSearchQuery,
|
|
onSearch = onSearch,
|
|
sourceFilter = state.sourceFilter,
|
|
onChangeSearchFilter = onChangeSearchFilter,
|
|
onlyShowHasResults = state.onlyShowHasResults,
|
|
onToggleResults = onToggleResults,
|
|
scrollBehavior = scrollBehavior,
|
|
// KMK -->
|
|
toggleSelectionMode = bulkFavoriteScreenModel::toggleSelectionMode,
|
|
isRunning = bulkFavoriteState.isRunning,
|
|
// KMK <--
|
|
)
|
|
}
|
|
},
|
|
) { paddingValues ->
|
|
GlobalSearchContent(
|
|
fromSourceId = fromSourceId,
|
|
items = state.filteredItems,
|
|
contentPadding = paddingValues,
|
|
getManga = getManga,
|
|
onClickSource = onClickSource,
|
|
onClickItem = onClickItem,
|
|
onLongClickItem = onLongClickItem,
|
|
// KMK -->
|
|
selection = bulkFavoriteState.selection,
|
|
// KMK <--
|
|
)
|
|
}
|
|
}
|