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,
|
onClickSyncNow: () -> Unit,
|
||||||
// SY -->
|
// SY -->
|
||||||
onClickSyncExh: (() -> Unit)?,
|
onClickSyncExh: (() -> Unit)?,
|
||||||
|
isSyncEnabled: Boolean,
|
||||||
// SY <--
|
// SY <--
|
||||||
searchQuery: String?,
|
searchQuery: String?,
|
||||||
onSearchQueryChange: (String?) -> Unit,
|
onSearchQueryChange: (String?) -> Unit,
|
||||||
@ -64,6 +65,7 @@ fun LibraryToolbar(
|
|||||||
onClickSyncNow = onClickSyncNow,
|
onClickSyncNow = onClickSyncNow,
|
||||||
// SY -->
|
// SY -->
|
||||||
onClickSyncExh = onClickSyncExh,
|
onClickSyncExh = onClickSyncExh,
|
||||||
|
isSyncEnabled = isSyncEnabled,
|
||||||
// SY <--
|
// SY <--
|
||||||
scrollBehavior = scrollBehavior,
|
scrollBehavior = scrollBehavior,
|
||||||
)
|
)
|
||||||
@ -82,6 +84,7 @@ private fun LibraryRegularToolbar(
|
|||||||
onClickSyncNow: () -> Unit,
|
onClickSyncNow: () -> Unit,
|
||||||
// SY -->
|
// SY -->
|
||||||
onClickSyncExh: (() -> Unit)?,
|
onClickSyncExh: (() -> Unit)?,
|
||||||
|
isSyncEnabled: Boolean,
|
||||||
// SY <--
|
// SY <--
|
||||||
scrollBehavior: TopAppBarScrollBehavior?,
|
scrollBehavior: TopAppBarScrollBehavior?,
|
||||||
) {
|
) {
|
||||||
@ -128,10 +131,6 @@ private fun LibraryRegularToolbar(
|
|||||||
title = stringResource(MR.strings.action_open_random_manga),
|
title = stringResource(MR.strings.action_open_random_manga),
|
||||||
onClick = onClickOpenRandomManga,
|
onClick = onClickOpenRandomManga,
|
||||||
),
|
),
|
||||||
AppBar.OverflowAction(
|
|
||||||
title = stringResource(SYMR.strings.sync_library),
|
|
||||||
onClick = onClickSyncNow,
|
|
||||||
),
|
|
||||||
).builder().apply {
|
).builder().apply {
|
||||||
// SY -->
|
// SY -->
|
||||||
if (onClickSyncExh != null) {
|
if (onClickSyncExh != null) {
|
||||||
@ -142,6 +141,14 @@ private fun LibraryRegularToolbar(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (isSyncEnabled) {
|
||||||
|
add(
|
||||||
|
AppBar.OverflowAction(
|
||||||
|
title = stringResource(SYMR.strings.sync_library),
|
||||||
|
onClick = onClickSyncNow,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
}.build(),
|
}.build(),
|
||||||
)
|
)
|
||||||
|
@ -22,6 +22,7 @@ import eu.kanade.domain.base.BasePreferences
|
|||||||
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
import eu.kanade.domain.chapter.interactor.SetReadStatus
|
||||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||||
import eu.kanade.domain.source.service.SourcePreferences
|
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.components.SEARCH_DEBOUNCE_MILLIS
|
||||||
import eu.kanade.presentation.library.components.LibraryToolbarTitle
|
import eu.kanade.presentation.library.components.LibraryToolbarTitle
|
||||||
import eu.kanade.presentation.manga.DownloadAction
|
import eu.kanade.presentation.manga.DownloadAction
|
||||||
@ -151,6 +152,7 @@ class LibraryScreenModel(
|
|||||||
private val searchEngine: SearchEngine = Injekt.get(),
|
private val searchEngine: SearchEngine = Injekt.get(),
|
||||||
private val setCustomMangaInfo: SetCustomMangaInfo = Injekt.get(),
|
private val setCustomMangaInfo: SetCustomMangaInfo = Injekt.get(),
|
||||||
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId = Injekt.get(),
|
private val getMergedChaptersByMangaId: GetMergedChaptersByMangaId = Injekt.get(),
|
||||||
|
private val syncPreferences: SyncPreferences = Injekt.get(),
|
||||||
// SY <--
|
// SY <--
|
||||||
) : StateScreenModel<LibraryScreenModel.State>(State()) {
|
) : StateScreenModel<LibraryScreenModel.State>(State()) {
|
||||||
|
|
||||||
@ -274,6 +276,13 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.launchIn(screenModelScope)
|
.launchIn(screenModelScope)
|
||||||
|
syncPreferences.syncService()
|
||||||
|
.changes()
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.onEach { syncService ->
|
||||||
|
mutableState.update { it.copy(isSyncEnabled = syncService != 0) }
|
||||||
|
}
|
||||||
|
.launchIn(screenModelScope)
|
||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1360,6 +1369,7 @@ class LibraryScreenModel(
|
|||||||
val dialog: Dialog? = null,
|
val dialog: Dialog? = null,
|
||||||
// SY -->
|
// SY -->
|
||||||
val showSyncExh: Boolean = false,
|
val showSyncExh: Boolean = false,
|
||||||
|
val isSyncEnabled: Boolean = false,
|
||||||
val ogCategories: List<Category> = emptyList(),
|
val ogCategories: List<Category> = emptyList(),
|
||||||
val groupType: Int = LibraryGroup.BY_DEFAULT,
|
val groupType: Int = LibraryGroup.BY_DEFAULT,
|
||||||
// SY <--
|
// SY <--
|
||||||
|
@ -172,6 +172,7 @@ object LibraryTab : Tab {
|
|||||||
},
|
},
|
||||||
// SY -->
|
// SY -->
|
||||||
onClickSyncExh = screenModel::openFavoritesSyncDialog.takeIf { state.showSyncExh },
|
onClickSyncExh = screenModel::openFavoritesSyncDialog.takeIf { state.showSyncExh },
|
||||||
|
isSyncEnabled = state.isSyncEnabled,
|
||||||
// SY <--
|
// SY <--
|
||||||
searchQuery = state.searchQuery,
|
searchQuery = state.searchQuery,
|
||||||
onSearchQueryChange = screenModel::search,
|
onSearchQueryChange = screenModel::search,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user