Skip to content

Commit

Permalink
Hide sync library option when sync is disabled
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
FuSan21 committed Sep 12, 2024
1 parent dea3891 commit 089d804
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
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,7 @@ class LibraryScreenModel(
}
}
.launchIn(screenModelScope)
mutableState.update { it.copy(isSyncEnabled = syncPreferences.isSyncEnabled()) }
// SY <--
}

Expand Down Expand Up @@ -1362,6 +1365,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

0 comments on commit 089d804

Please sign in to comment.