From 9f2ddaadde0326fb0fcf1ce91a2affc7f4af42c2 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 23 Jul 2022 15:58:05 +0200 Subject: [PATCH] Cleanup Library after Compose changes (#7584) --- .../presentation/library/LibraryScreen.kt | 3 ++- .../library/components/LazyLibraryGrid.kt | 22 +++++++++++++++++++ .../components/LibraryComfortableGrid.kt | 17 ++------------ .../library/components/LibraryCompactGrid.kt | 16 +------------- .../library/components/LibraryContent.kt | 12 +++------- .../components/LibraryCoverOnlyGrid.kt | 18 ++------------- .../tachiyomi/ui/library/LibraryPresenter.kt | 6 ++--- 7 files changed, 35 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt index f76dd149db..b44e953bf2 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt @@ -6,6 +6,7 @@ import eu.kanade.presentation.components.LibraryBottomActionMenu import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.library.components.LibraryContent import eu.kanade.presentation.library.components.LibraryToolbar +import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.ui.library.LibraryPresenter @Composable @@ -44,7 +45,7 @@ fun LibraryScreen( onMarkAsReadClicked = onMarkAsReadClicked, onMarkAsUnreadClicked = onMarkAsUnreadClicked, onDownloadClicked = onDownloadClicked, - onDeleteClicked = onDeleteClicked, + onDeleteClicked = onDeleteClicked.takeIf { presenter.selection.none { it.source == LocalSource.ID } }, ) }, ) { paddingValues -> diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt index e2e3114412..19768eedbe 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt @@ -6,13 +6,19 @@ import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyGridScope import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp +import androidx.compose.ui.zIndex +import eu.kanade.presentation.components.TextButton import eu.kanade.presentation.util.bottomNavPaddingValues import eu.kanade.presentation.util.plus +import eu.kanade.tachiyomi.R @Composable fun LazyLibraryGrid( @@ -29,3 +35,19 @@ fun LazyLibraryGrid( content = content, ) } + +fun LazyGridScope.globalSearchItem( + searchQuery: String?, + onGlobalSearchClicked: () -> Unit, +) { + item(span = { GridItemSpan(maxLineSpan) }) { + if (searchQuery.isNullOrEmpty().not()) { + TextButton(onClick = onGlobalSearchClicked) { + Text( + text = stringResource(R.string.action_global_search_query, searchQuery!!), + modifier = Modifier.zIndex(99f), + ) + } + } + } +} diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt index d8fb824a50..849406fa03 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt @@ -3,19 +3,14 @@ package eu.kanade.presentation.library.components import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.items import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex import eu.kanade.domain.manga.model.MangaCover -import eu.kanade.presentation.components.TextButton -import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.ui.library.LibraryItem @@ -32,16 +27,8 @@ fun LibraryComfortableGrid( LazyLibraryGrid( columns = columns, ) { - item(span = { GridItemSpan(maxLineSpan) }) { - if (searchQuery.isNullOrEmpty().not()) { - TextButton(onClick = onGlobalSearchClicked) { - Text( - text = stringResource(R.string.action_global_search_query, searchQuery!!), - modifier = Modifier.zIndex(99f), - ) - } - } - } + globalSearchItem(searchQuery, onGlobalSearchClicked) + items( items = items, key = { diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt index 302f61976a..0d47c4f4f5 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.LocalTextStyle @@ -18,12 +17,8 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shadow -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex -import eu.kanade.presentation.components.TextButton -import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.ui.library.LibraryItem @@ -40,16 +35,7 @@ fun LibraryCompactGrid( LazyLibraryGrid( columns = columns, ) { - item(span = { GridItemSpan(maxLineSpan) }) { - if (searchQuery.isNullOrEmpty().not()) { - TextButton(onClick = onGlobalSearchClicked) { - Text( - text = stringResource(R.string.action_global_search_query, searchQuery!!), - modifier = Modifier.zIndex(99f), - ) - } - } - } + globalSearchItem(searchQuery, onGlobalSearchClicked) items( items = items, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt index 1be3ea0fa0..d4e80d32b7 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt @@ -7,9 +7,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.State import androidx.compose.ui.Modifier -import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.rememberNestedScrollInteropConnection +import androidx.compose.ui.platform.LocalUriHandler import com.google.accompanist.pager.rememberPagerState import com.google.accompanist.swiperefresh.SwipeRefresh import com.google.accompanist.swiperefresh.rememberSwipeRefreshState @@ -22,7 +20,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.ui.library.LibraryItem import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting -import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.widget.EmptyView @Composable @@ -45,8 +42,6 @@ fun LibraryContent( getColumnsForOrientation: (Boolean) -> PreferenceMutableState, getLibraryForPage: @Composable (Int) -> State>, ) { - val nestedScrollInterop = rememberNestedScrollInteropConnection() - val pagerState = rememberPagerState(currentPage) val categories = state.categories @@ -83,7 +78,6 @@ fun LibraryContent( SwipeRefresh( state = rememberSwipeRefreshState(isRefreshing = false), - modifier = Modifier.nestedScroll(nestedScrollInterop), onRefresh = onRefresh, indicator = { s, trigger -> SwipeRefreshIndicator( @@ -93,12 +87,12 @@ fun LibraryContent( }, ) { if (state.searchQuery.isNullOrEmpty() && isLibraryEmpty) { - val context = LocalContext.current + val handler = LocalUriHandler.current EmptyScreen( R.string.information_empty_library, listOf( EmptyView.Action(R.string.getting_started_guide, R.drawable.ic_help_24dp) { - context.openInBrowser("https://tachiyomi.org/help/guides/getting-started") + handler.openUri("https://tachiyomi.org/help/guides/getting-started") }, ), ) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt index 391be95adb..41511c9ef4 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCoverOnlyGrid.kt @@ -1,15 +1,9 @@ package eu.kanade.presentation.library.components import androidx.compose.foundation.combinedClickable -import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.items -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.zIndex -import eu.kanade.presentation.components.TextButton -import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.ui.library.LibraryItem @@ -26,16 +20,8 @@ fun LibraryCoverOnlyGrid( LazyLibraryGrid( columns = columns, ) { - item(span = { GridItemSpan(maxLineSpan) }) { - if (searchQuery.isNullOrEmpty().not()) { - TextButton(onClick = onGlobalSearchClicked) { - Text( - text = stringResource(R.string.action_global_search_query, searchQuery!!), - modifier = Modifier.zIndex(99f), - ) - } - } - } + globalSearchItem(searchQuery, onGlobalSearchClicked) + items( items = items, key = { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 8ba8d325d8..775e34ee11 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -411,7 +411,7 @@ class LibraryPresenter( * @return an observable of the categories and its manga. */ private fun getLibraryObservable(): Observable { - return combine(getCategoriesObservable(), getLibraryMangasObservable()) { dbCategories, libraryManga -> + return combine(getCategoriesFlow(), getLibraryMangasFlow()) { dbCategories, libraryManga -> val categories = if (libraryManga.containsKey(0)) { arrayListOf(Category.default(context)) + dbCategories } else { @@ -435,7 +435,7 @@ class LibraryPresenter( * * @return an observable of the categories. */ - private fun getCategoriesObservable(): Flow> { + private fun getCategoriesFlow(): Flow> { return getCategories.subscribe() } @@ -445,7 +445,7 @@ class LibraryPresenter( * @return an observable containing a map with the category id as key and a list of manga as the * value. */ - private fun getLibraryMangasObservable(): Flow { + private fun getLibraryMangasFlow(): Flow { return getLibraryManga.subscribe() .map { list -> list.map { libraryManga ->