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
This commit is contained in:
Andreas 2022-07-24 14:48:54 +02:00 committed by GitHub
parent 59f8c1a288
commit bc1f6ba517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 13 deletions

View File

@ -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 = {

View File

@ -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,

View File

@ -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<Int?>,
getDisplayModeForPage: @Composable (Int) -> State<DisplayModeSetting>,
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
) {
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,

View File

@ -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",

View File

@ -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")

View File

@ -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)
}
},