Skip to content

Commit

Permalink
made browse lists remember the scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
MavikBow committed Feb 1, 2025
1 parent 214b0e4 commit 514d454
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fun BrowseAnimeSourceContent(
source: AnimeSource?,
animeList: LazyPagingItems<StateFlow<Anime>>,
columns: GridCells,
entries: Int = 0,
topBarHeight: Int = 0,
displayMode: LibraryDisplayMode,
snackbarHostState: SnackbarHostState,
contentPadding: PaddingValues,
Expand Down Expand Up @@ -129,6 +131,8 @@ fun BrowseAnimeSourceContent(
LibraryDisplayMode.List -> {
BrowseAnimeSourceList(
animeList = animeList,
entries = entries,
topBarHeight = topBarHeight,
contentPadding = contentPadding,
onAnimeClick = onAnimeClick,
onAnimeLongClick = onAnimeLongClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import androidx.paging.compose.LazyPagingItems
Expand All @@ -20,12 +25,19 @@ import tachiyomi.presentation.core.util.plus
@Composable
fun BrowseAnimeSourceList(
animeList: LazyPagingItems<StateFlow<Anime>>,
entries: Int,
topBarHeight: Int,
contentPadding: PaddingValues,
onAnimeClick: (Anime) -> Unit,
onAnimeLongClick: (Anime) -> Unit,
) {
var containerHeight by remember { mutableIntStateOf(0)}
LazyColumn(
contentPadding = contentPadding + PaddingValues(vertical = 8.dp),
modifier = Modifier
.onGloballyPositioned { layoutCoordinates ->
containerHeight = layoutCoordinates.size.height - topBarHeight
}
) {
item {
if (animeList.loadState.prepend is LoadState.Loading) {
Expand All @@ -39,6 +51,8 @@ fun BrowseAnimeSourceList(
anime = anime,
onClick = { onAnimeClick(anime) },
onLongClick = { onAnimeLongClick(anime) },
entries = entries,
containerHeight = containerHeight,
)
}

Expand All @@ -55,6 +69,8 @@ private fun BrowseAnimeSourceListItem(
anime: Anime,
onClick: () -> Unit = {},
onLongClick: () -> Unit = onClick,
entries: Int,
containerHeight: Int,
) {
EntryListItem(
title = anime.title,
Expand All @@ -71,5 +87,7 @@ private fun BrowseAnimeSourceListItem(
},
onLongClick = onLongClick,
onClick = onClick,
entries = entries,
containerHeight = containerHeight,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fun BrowseSourceContent(
source: MangaSource?,
mangaList: LazyPagingItems<StateFlow<Manga>>,
columns: GridCells,
entries: Int = 0,
topBarHeight: Int = 0,
displayMode: LibraryDisplayMode,
snackbarHostState: SnackbarHostState,
contentPadding: PaddingValues,
Expand Down Expand Up @@ -129,6 +131,8 @@ fun BrowseSourceContent(
LibraryDisplayMode.List -> {
BrowseMangaSourceList(
mangaList = mangaList,
entries = entries,
topBarHeight = topBarHeight,
contentPadding = contentPadding,
onMangaClick = onMangaClick,
onMangaLongClick = onMangaLongClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import androidx.paging.compose.LazyPagingItems
Expand All @@ -19,12 +24,19 @@ import tachiyomi.presentation.core.util.plus
@Composable
fun BrowseMangaSourceList(
mangaList: LazyPagingItems<StateFlow<Manga>>,
entries: Int,
topBarHeight: Int,
contentPadding: PaddingValues,
onMangaClick: (Manga) -> Unit,
onMangaLongClick: (Manga) -> Unit,
) {
var containerHeight by remember { mutableIntStateOf(0) }
LazyColumn(
contentPadding = contentPadding + PaddingValues(vertical = 8.dp),
modifier = Modifier
.onGloballyPositioned { layoutCoordinates ->
containerHeight = layoutCoordinates.size.height - topBarHeight
}
) {
item {
if (mangaList.loadState.prepend is LoadState.Loading) {
Expand All @@ -38,6 +50,8 @@ fun BrowseMangaSourceList(
manga = manga,
onClick = { onMangaClick(manga) },
onLongClick = { onMangaLongClick(manga) },
entries = entries,
containerHeight = containerHeight,
)
}

Expand All @@ -54,6 +68,8 @@ private fun BrowseMangaSourceListItem(
manga: Manga,
onClick: () -> Unit = {},
onLongClick: () -> Unit = onClick,
entries: Int,
containerHeight: Int,
) {
EntryListItem(
title = manga.title,
Expand All @@ -70,5 +86,7 @@ private fun BrowseMangaSourceListItem(
},
onLongClick = onLongClick,
onClick = onClick,
entries = entries,
containerHeight = containerHeight,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalUriHandler
Expand Down Expand Up @@ -124,9 +127,15 @@ data class BrowseAnimeSourceScreen(
assistUrl = (screenModel.source as? AnimeHttpSource)?.baseUrl
}

var topBarHeight by remember { mutableIntStateOf(0) }
Scaffold(
topBar = {
Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) {
Column(modifier = Modifier
.background(MaterialTheme.colorScheme.surface)
.onGloballyPositioned { layoutCoordinates ->
topBarHeight = layoutCoordinates.size.height
},
) {
BrowseAnimeSourceToolbar(
searchQuery = state.toolbarQuery,
onSearchQueryChange = screenModel::setToolbarQuery,
Expand Down Expand Up @@ -214,6 +223,8 @@ data class BrowseAnimeSourceScreen(
source = screenModel.source,
animeList = pagingFlow.collectAsLazyPagingItems(),
columns = screenModel.getColumnsPreference(LocalConfiguration.current.orientation),
entries = screenModel.getColumnsPreferenceForCurrentOrientation(LocalConfiguration.current.orientation),
topBarHeight = topBarHeight,
displayMode = screenModel.displayMode,
snackbarHostState = snackbarHostState,
contentPadding = paddingValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ class BrowseAnimeSourceScreenModel(
return if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns)
}

// returns the number from the size slider
fun getColumnsPreferenceForCurrentOrientation(orientation: Int) : Int {
val isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE
return if (isLandscape) {
libraryPreferences.animeLandscapeColumns()
} else {
libraryPreferences.animePortraitColumns()
}.get()
}

fun resetFilters() {
if (source !is AnimeCatalogueSource) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalUriHandler
Expand Down Expand Up @@ -124,9 +127,15 @@ data class BrowseMangaSourceScreen(
assistUrl = (screenModel.source as? HttpSource)?.baseUrl
}

var topBarHeight by remember { mutableIntStateOf(0) }
Scaffold(
topBar = {
Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) {
Column(modifier = Modifier
.background(MaterialTheme.colorScheme.surface)
.onGloballyPositioned { layoutCoordinates ->
topBarHeight = layoutCoordinates.size.height
},
) {
BrowseMangaSourceToolbar(
searchQuery = state.toolbarQuery,
onSearchQueryChange = screenModel::setToolbarQuery,
Expand Down Expand Up @@ -214,6 +223,8 @@ data class BrowseMangaSourceScreen(
source = screenModel.source,
mangaList = pagingFlow.collectAsLazyPagingItems(),
columns = screenModel.getColumnsPreference(LocalConfiguration.current.orientation),
entries = screenModel.getColumnsPreferenceForCurrentOrientation(LocalConfiguration.current.orientation),
topBarHeight = topBarHeight,
displayMode = screenModel.displayMode,
snackbarHostState = snackbarHostState,
contentPadding = paddingValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ class BrowseMangaSourceScreenModel(
return if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns)
}

// returns the number from the size slider
fun getColumnsPreferenceForCurrentOrientation(orientation: Int) : Int {
val isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE
return if (isLandscape) {
libraryPreferences.mangaLandscapeColumns()
} else {
libraryPreferences.mangaPortraitColumns()
}.get()
}

fun resetFilters() {
if (source !is CatalogueSource) return

Expand Down

0 comments on commit 514d454

Please sign in to comment.