Refine FavouritesScreen layout

This commit is contained in:
FooIbar committed 2023-11-21 21:53:44 +08:00
1 parent c3c7e88c15
commit bb2d500067
2 files changed
+120 -113

No files matched your search

@@ -11,6 +11,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.only
@@ -60,6 +62,7 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
@@ -285,23 +288,27 @@ fun FavouritesScreen(navigator: NavController) {
}
},
) {
val layoutDirection = LocalLayoutDirection.current
val marginH = dimensionResource(id = R.dimen.gallery_list_margin_h)
val marginV = dimensionResource(id = R.dimen.gallery_list_margin_v)
val realPadding = PaddingValues(
top = it.calculateTopPadding() + 8.dp,
bottom = it.calculateBottomPadding(),
top = it.calculateTopPadding() + marginV,
bottom = it.calculateBottomPadding() + marginV,
start = it.calculateStartPadding(layoutDirection) + marginH,
end = it.calculateEndPadding(layoutDirection) + marginH,
)
val listMode by remember {
Settings.listModeBackField.valueFlow()
}.collectAsState(Settings.listMode)
val marginH = dimensionResource(id = R.dimen.gallery_list_margin_h)
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
Box(modifier = Modifier.fillMaxSize()) {
when (val state = data.loadState.refresh) {
is LoadState.Loading -> if (data.itemCount == 0) CircularProgressIndicator()
is LoadState.Loading -> if (data.itemCount == 0) {
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
}
is LoadState.Error -> {
Column(
modifier = Modifier.widthIn(max = 228.dp).clip(ShapeDefaults.Small).clickable { data.retry() },
modifier = Modifier.align(Alignment.Center).widthIn(max = 228.dp)
.clip(ShapeDefaults.Small).clickable { data.retry() },
horizontalAlignment = Alignment.CenterHorizontally,
) {
Icon(
@@ -325,7 +332,7 @@ fun FavouritesScreen(navigator: NavController) {
val height = (3 * Settings.listThumbSize * 3).pxToDp.dp
val showPages = Settings.showGalleryPages
FastScrollLazyColumn(
modifier = Modifier.padding(horizontal = marginH) then combinedModifier,
modifier = combinedModifier,
contentPadding = realPadding,
verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.gallery_list_interval)),
) {
@@ -370,7 +377,7 @@ fun FavouritesScreen(navigator: NavController) {
val gridInterval = dimensionResource(R.dimen.gallery_grid_interval)
FastScrollLazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Adaptive(Settings.thumbSizeDp.dp),
modifier = Modifier.padding(horizontal = marginH) then combinedModifier,
modifier = combinedModifier,
verticalItemSpacing = gridInterval,
horizontalArrangement = Arrangement.spacedBy(gridInterval),
contentPadding = realPadding,
@@ -294,71 +294,75 @@ fun SearchBarScreen(
containerColor = background,
)
}
SearchBar(
modifier = Modifier.fillMaxWidth().align(Alignment.TopCenter) then scrollAwayModifier,
state = searchFieldState,
onSearch = {
hideSearchView()
onApplySearch()
},
active = active,
onActiveChange = {
if (it) {
onSearchViewExpanded()
} else {
onSearchViewHidden()
}
active = it
},
title = title?.let { { Text(it) } },
placeholder = searchFieldHint?.let { { Text(it) } },
leadingIcon = {
if (active) {
IconButton(onClick = { hideSearchView() }) {
Icon(Icons.AutoMirrored.Default.ArrowBack, contentDescription = null)
// Workaround for BTF2 cursor not showing
// https://issuetracker.google.com/issues/307323842
CompositionLocalProvider(LocalWindowInfo provides FocusedWindowInfo) {
SearchBar(
modifier = Modifier.fillMaxWidth().align(Alignment.TopCenter) then scrollAwayModifier,
state = searchFieldState,
onSearch = {
hideSearchView()
onApplySearch()
},
active = active,
onActiveChange = {
if (it) {
onSearchViewExpanded()
} else {
onSearchViewHidden()
}
} else {
IconButton(onClick = { activity.openDrawer() }) {
Icon(Icons.Default.Menu, contentDescription = null)
}
}
},
trailingIcon = {
if (active) {
if (searchFieldState.text.isNotEmpty()) {
IconButton(onClick = { searchFieldState.clearText() }) {
Icon(Icons.Default.Close, contentDescription = null)
active = it
},
title = title?.let { { Text(it) } },
placeholder = searchFieldHint?.let { { Text(it) } },
leadingIcon = {
if (active) {
IconButton(onClick = { hideSearchView() }) {
Icon(Icons.AutoMirrored.Default.ArrowBack, contentDescription = null)
}
} else {
IconButton(onClick = { activity.openDrawer() }) {
Icon(Icons.Default.Menu, contentDescription = null)
}
}
} else {
Row {
trailingIcon()
},
trailingIcon = {
if (active) {
if (searchFieldState.text.isNotEmpty()) {
IconButton(onClick = { searchFieldState.clearText() }) {
Icon(Icons.Default.Close, contentDescription = null)
}
}
} else {
Row {
trailingIcon()
}
}
}
},
) {
LazyColumn(contentPadding = WindowInsets.navigationBars.union(WindowInsets.ime).asPaddingValues()) {
items(mSuggestionList) {
ListItem(
headlineContent = { Text(text = it.keyword) },
supportingContent = it.hint.ifNotNullThen { Text(text = it.hint!!) },
leadingContent = it.canOpenDirectly.ifTrueThen {
Icon(
imageVector = Icons.AutoMirrored.Default.MenuBook,
contentDescription = null,
)
},
trailingContent = it.canDelete.ifTrueThen {
IconButton(onClick = { deleteKeyword(it.keyword) }) {
},
) {
LazyColumn(contentPadding = WindowInsets.navigationBars.union(WindowInsets.ime).asPaddingValues()) {
items(mSuggestionList) {
ListItem(
headlineContent = { Text(text = it.keyword) },
supportingContent = it.hint.ifNotNullThen { Text(text = it.hint!!) },
leadingContent = it.canOpenDirectly.ifTrueThen {
Icon(
imageVector = Icons.Default.Close,
imageVector = Icons.AutoMirrored.Default.MenuBook,
contentDescription = null,
)
}
},
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
modifier = Modifier.clickable { it.onClick() },
)
},
trailingContent = it.canDelete.ifTrueThen {
IconButton(onClick = { deleteKeyword(it.keyword) }) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = null,
)
}
},
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
modifier = Modifier.clickable { it.onClick() },
)
}
}
}
}
@@ -394,52 +398,48 @@ abstract class SearchBarScene : BaseScene() {
val compositionContext = rememberCompositionContext()
val density = LocalDensity.current
val margin = with(density) { 8.dp.roundToPx() }
// Workaround for BTF2 cursor not showing
// https://issuetracker.google.com/issues/307323842
CompositionLocalProvider(LocalWindowInfo provides FocusedWindowInfo) {
SearchBarScreen(
title = searchBarTitle,
searchFieldState = searchFieldState,
searchFieldHint = searchFieldHint,
showSearchFab = showSearchFab,
onApplySearch = onApplySearch,
onSearchExpanded = ::onSearchViewExpanded,
onSearchHidden = ::onSearchViewHidden,
suggestionProvider = mSuggestionProvider,
searchBarOffsetY = ofs,
trailingIcon = {
TrailingIcon()
},
) { contentPadding ->
val topPadding = with(density) { contentPadding.calculateTopPadding().roundToPx() }
val bottomPadding = with(density) { contentPadding.calculateBottomPadding().roundToPx() }
AndroidViewBinding(
modifier = Modifier.fillMaxSize(),
factory = { inflater, parent, _ ->
onCreateViewWithToolbar(inflater, parent, savedInstanceState).also {
recyclerView.addOnScrollListener(onScrollListener)
createDrawerView(savedInstanceState)?.apply {
if (this is ComposeView) {
val owner = viewLifecycleOwner
setViewTreeLifecycleOwner(owner)
setViewTreeViewModelStoreOwner(owner as ViewModelStoreOwner)
setViewTreeSavedStateRegistryOwner(owner as SavedStateRegistryOwner)
setParentCompositionContext(compositionContext)
}
sideSheetDialog = SideSheetDialog(parent.context).also {
it.setContentView(this)
}
SearchBarScreen(
title = searchBarTitle,
searchFieldState = searchFieldState,
searchFieldHint = searchFieldHint,
showSearchFab = showSearchFab,
onApplySearch = onApplySearch,
onSearchExpanded = ::onSearchViewExpanded,
onSearchHidden = ::onSearchViewHidden,
suggestionProvider = mSuggestionProvider,
searchBarOffsetY = ofs,
trailingIcon = {
TrailingIcon()
},
) { contentPadding ->
val topPadding = with(density) { contentPadding.calculateTopPadding().roundToPx() }
val bottomPadding = with(density) { contentPadding.calculateBottomPadding().roundToPx() }
AndroidViewBinding(
modifier = Modifier.fillMaxSize(),
factory = { inflater, parent, _ ->
onCreateViewWithToolbar(inflater, parent, savedInstanceState).also {
recyclerView.addOnScrollListener(onScrollListener)
createDrawerView(savedInstanceState)?.apply {
if (this is ComposeView) {
val owner = viewLifecycleOwner
setViewTreeLifecycleOwner(owner)
setViewTreeViewModelStoreOwner(owner as ViewModelStoreOwner)
setViewTreeSavedStateRegistryOwner(owner as SavedStateRegistryOwner)
setParentCompositionContext(compositionContext)
}
sideSheetDialog = SideSheetDialog(parent.context).also {
it.setContentView(this)
}
}
},
onRelease = {
onRelease()
},
) {
fabLayout.updatePadding(bottom = bottomPadding)
fastScroller.updatePadding(top = topPadding + margin, bottom = bottomPadding)
recyclerView.updatePadding(top = topPadding + margin, bottom = bottomPadding)
}
}
},
onRelease = {
onRelease()
},
) {
fabLayout.updatePadding(bottom = bottomPadding)
fastScroller.updatePadding(top = topPadding + margin, bottom = bottomPadding)
recyclerView.updatePadding(top = topPadding + margin, bottom = bottomPadding)
}
}
}