From bc1f6ba5177735e76b2b42f7884edfbe8f30006e Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 24 Jul 2022 14:48:54 +0200 Subject: [PATCH] Tweaks on Library screen (#7597) - Toolbar not having padding in landscape - Fix library always refreshing everything even though user is refreshing category - Tab text using primary color - Fix Grid having to big of a top padding - Fix Pager crashing when initial page is greater than the number of categories --- .../java/eu/kanade/presentation/library/LibraryScreen.kt | 5 +++-- .../presentation/library/components/LazyLibraryGrid.kt | 2 +- .../presentation/library/components/LibraryContent.kt | 9 +++++---- .../presentation/library/components/LibraryTabs.kt | 5 ++++- .../presentation/library/components/LibraryToolbar.kt | 8 ++++---- .../eu/kanade/tachiyomi/ui/library/LibraryController.kt | 2 +- 6 files changed, 18 insertions(+), 13 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 b44e953bf2..483bb6d8d8 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt @@ -2,6 +2,7 @@ package eu.kanade.presentation.library import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import eu.kanade.domain.category.model.Category import eu.kanade.presentation.components.LibraryBottomActionMenu import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.library.components.LibraryContent @@ -23,7 +24,7 @@ fun LibraryScreen( onClickSelectAll: () -> Unit, onClickInvertSelection: () -> Unit, onClickFilter: () -> Unit, - onClickRefresh: () -> Unit, + onClickRefresh: (Category?) -> Unit, ) { Scaffold( topBar = { @@ -35,7 +36,7 @@ fun LibraryScreen( onClickSelectAll = onClickSelectAll, onClickInvertSelection = onClickInvertSelection, onClickFilter = onClickFilter, - onClickRefresh = onClickRefresh, + onClickRefresh = { onClickRefresh(null) }, ) }, bottomBar = { 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 19768eedbe..79f1b1d89f 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 @@ -29,7 +29,7 @@ fun LazyLibraryGrid( LazyVerticalGrid( modifier = modifier, columns = if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns), - contentPadding = bottomNavPaddingValues + PaddingValues(12.dp) + WindowInsets.navigationBars.asPaddingValues(), + contentPadding = bottomNavPaddingValues + PaddingValues(12.dp, 2.dp) + WindowInsets.navigationBars.asPaddingValues(), verticalArrangement = Arrangement.spacedBy(12.dp), horizontalArrangement = Arrangement.spacedBy(12.dp), content = content, 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 d4e80d32b7..1b20b8df6b 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 @@ -12,6 +12,7 @@ import com.google.accompanist.pager.rememberPagerState import com.google.accompanist.swiperefresh.SwipeRefresh import com.google.accompanist.swiperefresh.rememberSwipeRefreshState import eu.kanade.core.prefs.PreferenceMutableState +import eu.kanade.domain.category.model.Category import eu.kanade.presentation.components.EmptyScreen import eu.kanade.presentation.components.LoadingScreen import eu.kanade.presentation.components.SwipeRefreshIndicator @@ -35,17 +36,17 @@ fun LibraryContent( onChangeCurrentPage: (Int) -> Unit, onMangaClicked: (Long) -> Unit, onToggleSelection: (LibraryManga) -> Unit, - onRefresh: () -> Unit, + onRefresh: (Category?) -> Unit, onGlobalSearchClicked: () -> Unit, getNumberOfMangaForCategory: @Composable (Long) -> State, getDisplayModeForPage: @Composable (Int) -> State, getColumnsForOrientation: (Boolean) -> PreferenceMutableState, getLibraryForPage: @Composable (Int) -> State>, ) { - val pagerState = rememberPagerState(currentPage) - val categories = state.categories + val pagerState = rememberPagerState(currentPage.coerceAtMost(categories.lastIndex)) + if (categories.isEmpty()) { LoadingScreen() return @@ -78,7 +79,7 @@ fun LibraryContent( SwipeRefresh( state = rememberSwipeRefreshState(isRefreshing = false), - onRefresh = onRefresh, + onRefresh = { onRefresh(categories[currentPage]) }, indicator = { s, trigger -> SwipeRefreshIndicator( state = s, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt index b479cbdb2a..ac27d2e088 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt @@ -54,7 +54,10 @@ fun LibraryTabs( Row( verticalAlignment = Alignment.CenterVertically, ) { - Text(text = category.name) + Text( + text = category.name, + color = if (state.currentPage == index) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onBackground, + ) if (count != null) { Pill( text = "$count", diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt index 650981a16c..305a75f973 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt @@ -3,7 +3,7 @@ package eu.kanade.presentation.library.components import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.statusBarsPadding +import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.foundation.text.BasicTextField import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ArrowBack @@ -79,7 +79,7 @@ fun LibraryRegularToolbar( val pillAlpha = if (isSystemInDarkTheme()) 0.12f else 0.08f val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current SmallTopAppBar( - modifier = Modifier.statusBarsPadding(), + modifier = Modifier.safeDrawingPadding(), title = { Row(verticalAlignment = Alignment.CenterVertically) { Text( @@ -124,7 +124,7 @@ fun LibrarySelectionToolbar( .drawBehind { drawRect(backgroundColor.copy(alpha = 1f)) } - .statusBarsPadding(), + .safeDrawingPadding(), navigationIcon = { IconButton(onClick = onClickUnselectAll) { Icon(Icons.Outlined.Close, contentDescription = "close") @@ -156,7 +156,7 @@ fun LibrarySearchToolbar( ) { val focusRequester = remember { FocusRequester.Default } SmallTopAppBar( - modifier = Modifier.statusBarsPadding(), + modifier = Modifier.safeDrawingPadding(), navigationIcon = { IconButton(onClick = onClickCloseSearch) { Icon(Icons.Outlined.ArrowBack, contentDescription = "back") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 0482f3a081..35dc02338e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -62,7 +62,7 @@ class LibraryController( onDeleteClicked = ::showDeleteMangaDialog, onClickFilter = ::showSettingsSheet, onClickRefresh = { - if (LibraryUpdateService.start(context)) { + if (LibraryUpdateService.start(context, it)) { context.toast(R.string.updating_library) } },