Pass listing query to BrowseSourceScreen (#8763)

* Pass listing query to BrowseSourceScreen

* Don't use referential equality
This commit is contained in:
stevenyomi 2022-12-18 06:28:25 +08:00 committed by GitHub
parent dac04f2929
commit 46417fe427
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 14 deletions

View file

@ -15,7 +15,6 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.OpenInNew
import androidx.compose.material.icons.outlined.NewReleases
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBarDefaults
@ -68,7 +67,7 @@ fun NewUpdateScreen(
vertical = MaterialTheme.padding.small,
),
) {
Button(
TextButton(
modifier = Modifier.fillMaxWidth(),
onClick = onAcceptUpdate,
) {

View file

@ -50,7 +50,6 @@ import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceScreenModel.Listing
import eu.kanade.tachiyomi.ui.manga.MangaScreen
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchUI
@ -78,7 +77,7 @@ class MigrateSearchScreen(private val mangaId: Long) : Screen {
if (!screenModel.incognitoMode.get()) {
screenModel.lastUsedSourceId.set(it.id)
}
navigator.push(SourceSearchScreen(state.manga!!, it.id, Listing.Search(state.searchQuery, it.getFilterList())))
navigator.push(SourceSearchScreen(state.manga!!, it.id, state.searchQuery))
},
onClickItem = { screenModel.setDialog(MigrateSearchDialog.Migrate(it)) },
onLongClickItem = { navigator.push(MangaScreen(it.id, true)) },

View file

@ -40,7 +40,7 @@ import kotlinx.coroutines.launch
data class SourceSearchScreen(
private val oldManga: Manga,
private val sourceId: Long,
private val listing: BrowseSourceScreenModel.Listing,
private val query: String?,
) : Screen {
@Composable
@ -50,7 +50,7 @@ data class SourceSearchScreen(
val navigator = LocalNavigator.currentOrThrow
val scope = rememberCoroutineScope()
val screenModel = rememberScreenModel { BrowseSourceScreenModel(sourceId, listing) }
val screenModel = rememberScreenModel { BrowseSourceScreenModel(sourceId, query) }
val state by screenModel.state.collectAsState()
val snackbarHostState = remember { SnackbarHostState() }

View file

@ -48,7 +48,7 @@ fun Screen.sourcesTab(): TabContent {
contentPadding = contentPadding,
onClickItem = { source, listing ->
screenModel.onOpenSource(source)
navigator.push(BrowseSourceScreen(source.id, listing))
navigator.push(BrowseSourceScreen(source.id, listing.query))
},
onClickPin = screenModel::togglePin,
onLongClickItem = screenModel::showSourceDialog,

View file

@ -62,7 +62,7 @@ import kotlinx.coroutines.flow.receiveAsFlow
data class BrowseSourceScreen(
private val sourceId: Long,
private val listing: Listing,
private val listingQuery: String?,
) : Screen, AssistContentScreen {
private var assistUrl: String? = null
@ -79,7 +79,7 @@ data class BrowseSourceScreen(
val haptic = LocalHapticFeedback.current
val uriHandler = LocalUriHandler.current
val screenModel = rememberScreenModel { BrowseSourceScreenModel(sourceId, listing) }
val screenModel = rememberScreenModel { BrowseSourceScreenModel(sourceId, listingQuery) }
val state by screenModel.state.collectAsState()
val snackbarHostState = remember { SnackbarHostState() }

View file

@ -79,7 +79,7 @@ import eu.kanade.tachiyomi.source.model.Filter as SourceModelFilter
class BrowseSourceScreenModel(
private val sourceId: Long,
listing: Listing,
listingQuery: String?,
private val sourceManager: SourceManager = Injekt.get(),
sourcePreferences: SourcePreferences = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(),
@ -95,7 +95,7 @@ class BrowseSourceScreenModel(
private val updateManga: UpdateManga = Injekt.get(),
private val insertTrack: InsertTrack = Injekt.get(),
private val syncChaptersWithTrackServiceTwoWay: SyncChaptersWithTrackServiceTwoWay = Injekt.get(),
) : StateScreenModel<BrowseSourceScreenModel.State>(State(listing)) {
) : StateScreenModel<BrowseSourceScreenModel.State>(State(Listing.valueOf(listingQuery))) {
private val loggedServices by lazy { Injekt.get<TrackManager>().services.filter { it.isLogged } }
@ -133,7 +133,19 @@ class BrowseSourceScreenModel(
.stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow())
init {
mutableState.update { it.copy(filters = source.getFilterList()) }
mutableState.update {
val initialListing = it.listing
val listing = if (initialListing is Listing.Search) {
initialListing.copy(filters = source.getFilterList())
} else {
initialListing
}
it.copy(
listing = listing,
filters = source.getFilterList(),
)
}
}
fun getColumnsPreference(orientation: Int): GridCells {
@ -374,6 +386,16 @@ class BrowseSourceScreenModel(
object Popular : Listing(query = GetRemoteManga.QUERY_POPULAR, filters = FilterList())
object Latest : Listing(query = GetRemoteManga.QUERY_LATEST, filters = FilterList())
data class Search(override val query: String?, override val filters: FilterList) : Listing(query = query, filters = filters)
companion object {
fun valueOf(query: String?): Listing {
return when (query) {
GetRemoteManga.QUERY_POPULAR -> Popular
GetRemoteManga.QUERY_LATEST -> Latest
else -> Search(query = query, filters = FilterList()) // filters are filled in later
}
}
}
}
sealed class Dialog {

View file

@ -10,7 +10,6 @@ import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.presentation.browse.GlobalSearchScreen
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceScreen
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceScreenModel.Listing
import eu.kanade.tachiyomi.ui.manga.MangaScreen
class GlobalSearchScreen(
@ -47,7 +46,7 @@ class GlobalSearchScreen(
if (!screenModel.incognitoMode.get()) {
screenModel.lastUsedSourceId.set(it.id)
}
navigator.push(BrowseSourceScreen(it.id, Listing.Search(state.searchQuery, it.getFilterList())))
navigator.push(BrowseSourceScreen(it.id, state.searchQuery))
},
onClickItem = { navigator.push(MangaScreen(it.id, true)) },
onLongClickItem = { navigator.push(MangaScreen(it.id, true)) },