Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide sync library option when sync is disabled #1275

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun LibraryToolbar(
onClickSyncNow: () -> Unit,
// SY -->
onClickSyncExh: (() -> Unit)?,
isSyncEnabled: Boolean,
// SY <--
searchQuery: String?,
onSearchQueryChange: (String?) -> Unit,
Expand All @@ -64,6 +65,7 @@ fun LibraryToolbar(
onClickSyncNow = onClickSyncNow,
// SY -->
onClickSyncExh = onClickSyncExh,
isSyncEnabled = isSyncEnabled,
// SY <--
scrollBehavior = scrollBehavior,
)
Expand All @@ -82,6 +84,7 @@ private fun LibraryRegularToolbar(
onClickSyncNow: () -> Unit,
// SY -->
onClickSyncExh: (() -> Unit)?,
isSyncEnabled: Boolean,
// SY <--
scrollBehavior: TopAppBarScrollBehavior?,
) {
Expand Down Expand Up @@ -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) {
Expand All @@ -142,6 +141,14 @@ private fun LibraryRegularToolbar(
),
)
}
if (isSyncEnabled) {
add(
AppBar.OverflowAction(
title = stringResource(SYMR.strings.sync_library),
onClick = onClickSyncNow,
),
)
}
// SY <--
}.build(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {

Expand Down Expand Up @@ -276,6 +278,13 @@ class LibraryScreenModel(
}
}
.launchIn(screenModelScope)
syncPreferences.syncService()
.changes()
.distinctUntilChanged()
.onEach { syncService ->
mutableState.update { it.copy(isSyncEnabled = syncService != 0) }
}
.launchIn(screenModelScope)
// SY <--
}

Expand Down Expand Up @@ -1362,6 +1371,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 <--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ object LibraryTab : Tab {
},
// SY -->
onClickSyncExh = screenModel::openFavoritesSyncDialog.takeIf { state.showSyncExh },
isSyncEnabled = state.isSyncEnabled,
// SY <--
searchQuery = state.searchQuery,
onSearchQueryChange = screenModel::search,
Expand Down