Cleanup Library after Compose changes (#7584)

This commit is contained in:
Andreas 2022-07-23 15:58:05 +02:00 committed by GitHub
parent fc328e141c
commit 9f2ddaadde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 59 deletions

View file

@ -6,6 +6,7 @@ import eu.kanade.presentation.components.LibraryBottomActionMenu
import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.components.Scaffold
import eu.kanade.presentation.library.components.LibraryContent import eu.kanade.presentation.library.components.LibraryContent
import eu.kanade.presentation.library.components.LibraryToolbar import eu.kanade.presentation.library.components.LibraryToolbar
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.ui.library.LibraryPresenter import eu.kanade.tachiyomi.ui.library.LibraryPresenter
@Composable @Composable
@ -44,7 +45,7 @@ fun LibraryScreen(
onMarkAsReadClicked = onMarkAsReadClicked, onMarkAsReadClicked = onMarkAsReadClicked,
onMarkAsUnreadClicked = onMarkAsUnreadClicked, onMarkAsUnreadClicked = onMarkAsUnreadClicked,
onDownloadClicked = onDownloadClicked, onDownloadClicked = onDownloadClicked,
onDeleteClicked = onDeleteClicked, onDeleteClicked = onDeleteClicked.takeIf { presenter.selection.none { it.source == LocalSource.ID } },
) )
}, },
) { paddingValues -> ) { paddingValues ->

View file

@ -6,13 +6,19 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.lazy.grid.GridCells 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.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp 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.bottomNavPaddingValues
import eu.kanade.presentation.util.plus import eu.kanade.presentation.util.plus
import eu.kanade.tachiyomi.R
@Composable @Composable
fun LazyLibraryGrid( fun LazyLibraryGrid(
@ -29,3 +35,19 @@ fun LazyLibraryGrid(
content = content, 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),
)
}
}
}
}

View file

@ -3,19 +3,14 @@ package eu.kanade.presentation.library.components
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import eu.kanade.domain.manga.model.MangaCover 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.data.database.models.LibraryManga
import eu.kanade.tachiyomi.ui.library.LibraryItem import eu.kanade.tachiyomi.ui.library.LibraryItem
@ -32,16 +27,8 @@ fun LibraryComfortableGrid(
LazyLibraryGrid( LazyLibraryGrid(
columns = columns, columns = columns,
) { ) {
item(span = { GridItemSpan(maxLineSpan) }) { globalSearchItem(searchQuery, onGlobalSearchClicked)
if (searchQuery.isNullOrEmpty().not()) {
TextButton(onClick = onGlobalSearchClicked) {
Text(
text = stringResource(R.string.action_global_search_query, searchQuery!!),
modifier = Modifier.zIndex(99f),
)
}
}
}
items( items(
items = items, items = items,
key = { key = {

View file

@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LocalTextStyle 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.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shadow import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp 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.data.database.models.LibraryManga
import eu.kanade.tachiyomi.ui.library.LibraryItem import eu.kanade.tachiyomi.ui.library.LibraryItem
@ -40,16 +35,7 @@ fun LibraryCompactGrid(
LazyLibraryGrid( LazyLibraryGrid(
columns = columns, columns = columns,
) { ) {
item(span = { GridItemSpan(maxLineSpan) }) { globalSearchItem(searchQuery, onGlobalSearchClicked)
if (searchQuery.isNullOrEmpty().not()) {
TextButton(onClick = onGlobalSearchClicked) {
Text(
text = stringResource(R.string.action_global_search_query, searchQuery!!),
modifier = Modifier.zIndex(99f),
)
}
}
}
items( items(
items = items, items = items,

View file

@ -7,9 +7,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State import androidx.compose.runtime.State
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import com.google.accompanist.pager.rememberPagerState import com.google.accompanist.pager.rememberPagerState
import com.google.accompanist.swiperefresh.SwipeRefresh import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState 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.data.database.models.LibraryManga
import eu.kanade.tachiyomi.ui.library.LibraryItem import eu.kanade.tachiyomi.ui.library.LibraryItem
import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting
import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.widget.EmptyView import eu.kanade.tachiyomi.widget.EmptyView
@Composable @Composable
@ -45,8 +42,6 @@ fun LibraryContent(
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>, getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>, getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
) { ) {
val nestedScrollInterop = rememberNestedScrollInteropConnection()
val pagerState = rememberPagerState(currentPage) val pagerState = rememberPagerState(currentPage)
val categories = state.categories val categories = state.categories
@ -83,7 +78,6 @@ fun LibraryContent(
SwipeRefresh( SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing = false), state = rememberSwipeRefreshState(isRefreshing = false),
modifier = Modifier.nestedScroll(nestedScrollInterop),
onRefresh = onRefresh, onRefresh = onRefresh,
indicator = { s, trigger -> indicator = { s, trigger ->
SwipeRefreshIndicator( SwipeRefreshIndicator(
@ -93,12 +87,12 @@ fun LibraryContent(
}, },
) { ) {
if (state.searchQuery.isNullOrEmpty() && isLibraryEmpty) { if (state.searchQuery.isNullOrEmpty() && isLibraryEmpty) {
val context = LocalContext.current val handler = LocalUriHandler.current
EmptyScreen( EmptyScreen(
R.string.information_empty_library, R.string.information_empty_library,
listOf( listOf(
EmptyView.Action(R.string.getting_started_guide, R.drawable.ic_help_24dp) { 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")
}, },
), ),
) )

View file

@ -1,15 +1,9 @@
package eu.kanade.presentation.library.components package eu.kanade.presentation.library.components
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier 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.data.database.models.LibraryManga
import eu.kanade.tachiyomi.ui.library.LibraryItem import eu.kanade.tachiyomi.ui.library.LibraryItem
@ -26,16 +20,8 @@ fun LibraryCoverOnlyGrid(
LazyLibraryGrid( LazyLibraryGrid(
columns = columns, columns = columns,
) { ) {
item(span = { GridItemSpan(maxLineSpan) }) { globalSearchItem(searchQuery, onGlobalSearchClicked)
if (searchQuery.isNullOrEmpty().not()) {
TextButton(onClick = onGlobalSearchClicked) {
Text(
text = stringResource(R.string.action_global_search_query, searchQuery!!),
modifier = Modifier.zIndex(99f),
)
}
}
}
items( items(
items = items, items = items,
key = { key = {

View file

@ -411,7 +411,7 @@ class LibraryPresenter(
* @return an observable of the categories and its manga. * @return an observable of the categories and its manga.
*/ */
private fun getLibraryObservable(): Observable<Library> { private fun getLibraryObservable(): Observable<Library> {
return combine(getCategoriesObservable(), getLibraryMangasObservable()) { dbCategories, libraryManga -> return combine(getCategoriesFlow(), getLibraryMangasFlow()) { dbCategories, libraryManga ->
val categories = if (libraryManga.containsKey(0)) { val categories = if (libraryManga.containsKey(0)) {
arrayListOf(Category.default(context)) + dbCategories arrayListOf(Category.default(context)) + dbCategories
} else { } else {
@ -435,7 +435,7 @@ class LibraryPresenter(
* *
* @return an observable of the categories. * @return an observable of the categories.
*/ */
private fun getCategoriesObservable(): Flow<List<Category>> { private fun getCategoriesFlow(): Flow<List<Category>> {
return getCategories.subscribe() 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 * @return an observable containing a map with the category id as key and a list of manga as the
* value. * value.
*/ */
private fun getLibraryMangasObservable(): Flow<LibraryMap> { private fun getLibraryMangasFlow(): Flow<LibraryMap> {
return getLibraryManga.subscribe() return getLibraryManga.subscribe()
.map { list -> .map { list ->
list.map { libraryManga -> list.map { libraryManga ->