hide Pinned chip in Global/Migrate Search if no pinned sources available

This commit is contained in:
Cuong-Tran 2024-10-19 00:23:59 +07:00
parent 6bb8535af4
commit 8895015388
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
8 changed files with 44 additions and 15 deletions

View file

@ -39,6 +39,7 @@ fun GlobalSearchScreen(
onLongClickItem: (Manga) -> Unit,
// KMK -->
bulkFavoriteScreenModel: BulkFavoriteScreenModel,
hasPinnedSources: Boolean,
// KMK <--
) {
// KMK -->
@ -91,6 +92,7 @@ fun GlobalSearchScreen(
// KMK -->
toggleSelectionMode = bulkFavoriteScreenModel::toggleSelectionMode,
isRunning = bulkFavoriteState.isRunning,
hasPinnedSources = hasPinnedSources,
// KMK <--
)
}

View file

@ -29,6 +29,7 @@ fun MigrateSearchScreen(
onLongClickItem: (Manga) -> Unit,
// KMK -->
bulkFavoriteScreenModel: BulkFavoriteScreenModel,
hasPinnedSources: Boolean,
// KMK <--
) {
// KMK -->
@ -81,6 +82,7 @@ fun MigrateSearchScreen(
// KMK -->
toggleSelectionMode = bulkFavoriteScreenModel::toggleSelectionMode,
isRunning = bulkFavoriteState.isRunning,
hasPinnedSources = hasPinnedSources,
// KMK <--
)
}

View file

@ -51,6 +51,7 @@ fun GlobalSearchToolbar(
// KMK -->
toggleSelectionMode: () -> Unit,
isRunning: Boolean,
hasPinnedSources: Boolean,
// KMK <--
) {
Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) {
@ -89,21 +90,25 @@ fun GlobalSearchToolbar(
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
) {
// TODO: make this UX better; it only applies when triggering a new search
FilterChip(
selected = sourceFilter == SourceFilter.PinnedOnly,
onClick = { onChangeSearchFilter(SourceFilter.PinnedOnly) },
leadingIcon = {
Icon(
imageVector = Icons.Outlined.PushPin,
contentDescription = null,
modifier = Modifier
.size(FilterChipDefaults.IconSize),
)
},
label = {
Text(text = stringResource(MR.strings.pinned_sources))
},
)
// KMK -->
if (hasPinnedSources) {
// KMK <--
FilterChip(
selected = sourceFilter == SourceFilter.PinnedOnly,
onClick = { onChangeSearchFilter(SourceFilter.PinnedOnly) },
leadingIcon = {
Icon(
imageVector = Icons.Outlined.PushPin,
contentDescription = null,
modifier = Modifier
.size(FilterChipDefaults.IconSize),
)
},
label = {
Text(text = stringResource(MR.strings.pinned_sources))
},
)
}
FilterChip(
selected = sourceFilter == SourceFilter.All,
onClick = { onChangeSearchFilter(SourceFilter.All) },

View file

@ -69,6 +69,7 @@ class MigrateSearchScreen(private val mangaId: Long, private val validSources: L
onLongClickItem = { navigator.push(MangaScreen(it.id, true)) },
// KMK -->
bulkFavoriteScreenModel = bulkFavoriteScreenModel,
hasPinnedSources = screenModel.hasPinnedSources(),
// KMK <--
)

View file

@ -33,6 +33,10 @@ class MigrateSearchScreenModel(
}
search()
}
// KMK -->
shouldPinnedSourcesHidden()
// KMK <--
}
override fun getEnabledSources(): List<CatalogueSource> {

View file

@ -111,6 +111,7 @@ class GlobalSearchScreen(
},
// KMK -->
bulkFavoriteScreenModel = bulkFavoriteScreenModel,
hasPinnedSources = screenModel.hasPinnedSources(),
// KMK <--
)
}

View file

@ -16,6 +16,10 @@ class GlobalSearchScreenModel(
}
search()
}
// KMK -->
shouldPinnedSourcesHidden()
// KMK <--
}
override fun getEnabledSources(): List<CatalogueSource> {

View file

@ -101,6 +101,16 @@ abstract class SearchScreenModel(
)
}
// KMK -->
fun hasPinnedSources(): Boolean = getEnabledSources().any { "${it.id}" in pinnedSources }
fun shouldPinnedSourcesHidden() {
if (!hasPinnedSources()) {
preferences.globalSearchPinnedState().set(SourceFilter.All)
}
}
// KMK <--
private fun getSelectedSources(): List<CatalogueSource> {
val enabledSources = getEnabledSources()