Hide sync library option when sync is disabled (#1275)
* Hide sync library option when sync is disabled - Add isSyncEnabled parameter to LibraryToolbar and LibraryRegularToolbar - Pass isSyncEnabled from LibraryTab to LibraryToolbar - Conditionally display sync library action based on isSyncEnabled - Update LibraryContent to include isSyncEnabled parameter - Adjust LibraryTab to handle sync-related functionality - Remove direct dependency on SyncPreferences in LibraryToolbar * Update LibraryScreenModel to react to sync service changes - Replace static isSyncEnabled update with dynamic observation - Use syncPreferences.syncService().changes() to update isSyncEnabled state - Ensure isSyncEnabled is updated whenever the sync service changes Co-authored-by: jobobby04 <jobobby04@users.noreply.github.com> * Fix sync service state update in LibraryScreenModel - Resolve ambiguity in lambda parameters - Correctly update isSyncEnabled state based on syncService value * Optimize sync service state updates in LibraryScreenModel - Add distinctUntilChanged() to filter out consecutive duplicate emissions - Simplify mutableState.update lambda for better readability - Remove redundant boolean comparison in isSyncEnabled assignment --------- Co-authored-by: jobobby04 <jobobby04@users.noreply.github.com>
This commit is contained in:
parent
41e523e074
commit
697b0de226
@ -41,6 +41,7 @@ fun LibraryToolbar(
|
||||
onClickSyncNow: () -> Unit,
|
||||
// SY -->
|
||||
onClickSyncExh: (() -> Unit)?,
|
||||
isSyncEnabled: Boolean,
|
||||
// SY <--
|
||||
searchQuery: String?,
|
||||
onSearchQueryChange: (String?) -> Unit,
|
||||
@ -64,6 +65,7 @@ fun LibraryToolbar(
|
||||
onClickSyncNow = onClickSyncNow,
|
||||
// SY -->
|
||||
onClickSyncExh = onClickSyncExh,
|
||||
isSyncEnabled = isSyncEnabled,
|
||||
// SY <--
|
||||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
@ -82,6 +84,7 @@ private fun LibraryRegularToolbar(
|
||||
onClickSyncNow: () -> Unit,
|
||||
// SY -->
|
||||
onClickSyncExh: (() -> Unit)?,
|
||||
isSyncEnabled: Boolean,
|
||||
// SY <--
|
||||
scrollBehavior: TopAppBarScrollBehavior?,
|
||||
) {
|
||||
@ -128,10 +131,6 @@ private fun LibraryRegularToolbar(
|
||||
title = stringResource(MR.strings.action_open_random_manga),
|
||||
onClick = onClickOpenRandomManga,
|
||||
),
|
||||
AppBar.OverflowAction(
|
||||
title = stringResource(SYMR.strings.sync_library),
|
||||
onClick = onClickSyncNow,
|
||||
),
|
||||
).builder().apply {
|
||||
// SY -->
|
||||
if (onClickSyncExh != null) {
|
||||
@ -142,6 +141,14 @@ private fun LibraryRegularToolbar(
|
||||
),
|
||||
)
|
||||
}
|
||||
if (isSyncEnabled) {
|
||||
add(
|
||||
AppBar.OverflowAction(
|
||||
title = stringResource(SYMR.strings.sync_library),
|
||||
onClick = onClickSyncNow,
|
||||
),
|
||||
)
|
||||
}
|
||||
// SY <--
|
||||
}.build(),
|
||||
)
|
||||
|
@ -22,6 +22,7 @@ import eu.kanade.domain.base.BasePreferences
|
||||
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.domain.sync.SyncPreferences
|
||||
import eu.kanade.presentation.components.SEARCH_DEBOUNCE_MILLIS
|
||||
import eu.kanade.presentation.library.components.LibraryToolbarTitle
|
||||
import eu.kanade.presentation.manga.DownloadAction
|
||||
@ -151,6 +152,7 @@ class LibraryScreenModel(
|
||||
private val searchEngine: SearchEngine = Injekt.get(),
|
||||
private val setCustomMangaInfo: SetCustomMangaInfo = Injekt.get(),
|
||||
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId = Injekt.get(),
|
||||
private val syncPreferences: SyncPreferences = Injekt.get(),
|
||||
// SY <--
|
||||
) : StateScreenModel<LibraryScreenModel.State>(State()) {
|
||||
|
||||
@ -274,6 +276,13 @@ class LibraryScreenModel(
|
||||
}
|
||||
}
|
||||
.launchIn(screenModelScope)
|
||||
syncPreferences.syncService()
|
||||
.changes()
|
||||
.distinctUntilChanged()
|
||||
.onEach { syncService ->
|
||||
mutableState.update { it.copy(isSyncEnabled = syncService != 0) }
|
||||
}
|
||||
.launchIn(screenModelScope)
|
||||
// SY <--
|
||||
}
|
||||
|
||||
@ -1360,6 +1369,7 @@ class LibraryScreenModel(
|
||||
val dialog: Dialog? = null,
|
||||
// SY -->
|
||||
val showSyncExh: Boolean = false,
|
||||
val isSyncEnabled: Boolean = false,
|
||||
val ogCategories: List<Category> = emptyList(),
|
||||
val groupType: Int = LibraryGroup.BY_DEFAULT,
|
||||
// SY <--
|
||||
|
@ -172,6 +172,7 @@ object LibraryTab : Tab {
|
||||
},
|
||||
// SY -->
|
||||
onClickSyncExh = screenModel::openFavoritesSyncDialog.takeIf { state.showSyncExh },
|
||||
isSyncEnabled = state.isSyncEnabled,
|
||||
// SY <--
|
||||
searchQuery = state.searchQuery,
|
||||
onSearchQueryChange = screenModel::search,
|
||||
|
Loading…
x
Reference in New Issue
Block a user