mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 17:15:09 +01:00
Use Compose fast* functions in more places
This commit is contained in:
parent
156191af44
commit
86c3d8c064
@ -29,6 +29,7 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.util.fastFirstOrNull
|
||||||
import eu.kanade.presentation.theme.TachiyomiTheme
|
import eu.kanade.presentation.theme.TachiyomiTheme
|
||||||
import eu.kanade.presentation.util.secondaryItemAlpha
|
import eu.kanade.presentation.util.secondaryItemAlpha
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
@ -100,9 +101,9 @@ fun EmptyScreen(
|
|||||||
modifier = modifier.fillMaxSize(),
|
modifier = modifier.fillMaxSize(),
|
||||||
) { measurables, constraints ->
|
) { measurables, constraints ->
|
||||||
val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0)
|
val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0)
|
||||||
val facePlaceable = measurables.first { it.layoutId == "face" }
|
val facePlaceable = measurables.fastFirstOrNull { it.layoutId == "face" }!!
|
||||||
.measure(looseConstraints)
|
.measure(looseConstraints)
|
||||||
val actionsPlaceable = measurables.firstOrNull { it.layoutId == "actions" }
|
val actionsPlaceable = measurables.fastFirstOrNull { it.layoutId == "actions" }
|
||||||
?.measure(looseConstraints)
|
?.measure(looseConstraints)
|
||||||
|
|
||||||
layout(constraints.maxWidth, constraints.maxHeight) {
|
layout(constraints.maxWidth, constraints.maxHeight) {
|
||||||
|
@ -7,6 +7,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalUriHandler
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
|
import androidx.compose.ui.util.fastAll
|
||||||
import eu.kanade.domain.category.model.Category
|
import eu.kanade.domain.category.model.Category
|
||||||
import eu.kanade.domain.library.model.display
|
import eu.kanade.domain.library.model.display
|
||||||
import eu.kanade.domain.manga.model.isLocal
|
import eu.kanade.domain.manga.model.isLocal
|
||||||
@ -62,7 +63,7 @@ fun LibraryScreen(
|
|||||||
onChangeCategoryClicked = onChangeCategoryClicked,
|
onChangeCategoryClicked = onChangeCategoryClicked,
|
||||||
onMarkAsReadClicked = onMarkAsReadClicked,
|
onMarkAsReadClicked = onMarkAsReadClicked,
|
||||||
onMarkAsUnreadClicked = onMarkAsUnreadClicked,
|
onMarkAsUnreadClicked = onMarkAsUnreadClicked,
|
||||||
onDownloadClicked = onDownloadClicked.takeIf { presenter.selection.none { it.manga.isLocal() } },
|
onDownloadClicked = onDownloadClicked.takeIf { presenter.selection.fastAll { !it.manga.isLocal() } },
|
||||||
onDeleteClicked = onDeleteClicked,
|
onDeleteClicked = onDeleteClicked,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -43,6 +43,9 @@ import androidx.compose.ui.platform.LocalDensity
|
|||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.util.fastAll
|
||||||
|
import androidx.compose.ui.util.fastAny
|
||||||
|
import androidx.compose.ui.util.fastMap
|
||||||
import eu.kanade.domain.chapter.model.Chapter
|
import eu.kanade.domain.chapter.model.Chapter
|
||||||
import eu.kanade.presentation.components.ChapterDownloadAction
|
import eu.kanade.presentation.components.ChapterDownloadAction
|
||||||
import eu.kanade.presentation.components.ExtendedFloatingActionButton
|
import eu.kanade.presentation.components.ExtendedFloatingActionButton
|
||||||
@ -204,7 +207,7 @@ private fun MangaScreenSmallImpl(
|
|||||||
val chapters = remember(state) { state.processedChapters.toList() }
|
val chapters = remember(state) { state.processedChapters.toList() }
|
||||||
|
|
||||||
val internalOnBackPressed = {
|
val internalOnBackPressed = {
|
||||||
if (chapters.any { it.selected }) {
|
if (chapters.fastAny { it.selected }) {
|
||||||
onAllChapterSelected(false)
|
onAllChapterSelected(false)
|
||||||
} else {
|
} else {
|
||||||
onBackClicked()
|
onBackClicked()
|
||||||
@ -258,13 +261,13 @@ private fun MangaScreenSmallImpl(
|
|||||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = chapters.any { !it.chapter.read } && chapters.none { it.selected },
|
visible = chapters.fastAny { !it.chapter.read } && chapters.fastAll { !it.selected },
|
||||||
enter = fadeIn(),
|
enter = fadeIn(),
|
||||||
exit = fadeOut(),
|
exit = fadeOut(),
|
||||||
) {
|
) {
|
||||||
ExtendedFloatingActionButton(
|
ExtendedFloatingActionButton(
|
||||||
text = {
|
text = {
|
||||||
val id = if (chapters.any { it.chapter.read }) {
|
val id = if (chapters.fastAny { it.chapter.read }) {
|
||||||
R.string.action_resume
|
R.string.action_resume
|
||||||
} else {
|
} else {
|
||||||
R.string.action_start
|
R.string.action_start
|
||||||
@ -283,7 +286,7 @@ private fun MangaScreenSmallImpl(
|
|||||||
SwipeRefresh(
|
SwipeRefresh(
|
||||||
refreshing = state.isRefreshingData,
|
refreshing = state.isRefreshingData,
|
||||||
onRefresh = onRefresh,
|
onRefresh = onRefresh,
|
||||||
enabled = chapters.none { it.selected },
|
enabled = chapters.fastAll { !it.selected },
|
||||||
indicatorPadding = contentPadding,
|
indicatorPadding = contentPadding,
|
||||||
) {
|
) {
|
||||||
val layoutDirection = LocalLayoutDirection.current
|
val layoutDirection = LocalLayoutDirection.current
|
||||||
@ -414,7 +417,7 @@ fun MangaScreenLargeImpl(
|
|||||||
SwipeRefresh(
|
SwipeRefresh(
|
||||||
refreshing = state.isRefreshingData,
|
refreshing = state.isRefreshingData,
|
||||||
onRefresh = onRefresh,
|
onRefresh = onRefresh,
|
||||||
enabled = chapters.none { it.selected },
|
enabled = chapters.fastAll { !it.selected },
|
||||||
indicatorPadding = PaddingValues(
|
indicatorPadding = PaddingValues(
|
||||||
start = insetPadding.calculateStartPadding(layoutDirection),
|
start = insetPadding.calculateStartPadding(layoutDirection),
|
||||||
top = with(density) { topBarHeight.toDp() },
|
top = with(density) { topBarHeight.toDp() },
|
||||||
@ -424,7 +427,7 @@ fun MangaScreenLargeImpl(
|
|||||||
val chapterListState = rememberLazyListState()
|
val chapterListState = rememberLazyListState()
|
||||||
|
|
||||||
val internalOnBackPressed = {
|
val internalOnBackPressed = {
|
||||||
if (chapters.any { it.selected }) {
|
if (chapters.fastAny { it.selected }) {
|
||||||
onAllChapterSelected(false)
|
onAllChapterSelected(false)
|
||||||
} else {
|
} else {
|
||||||
onBackClicked()
|
onBackClicked()
|
||||||
@ -437,7 +440,7 @@ fun MangaScreenLargeImpl(
|
|||||||
MangaToolbar(
|
MangaToolbar(
|
||||||
modifier = Modifier.onSizeChanged { topBarHeight = it.height },
|
modifier = Modifier.onSizeChanged { topBarHeight = it.height },
|
||||||
title = state.manga.title,
|
title = state.manga.title,
|
||||||
titleAlphaProvider = { if (chapters.any { it.selected }) 1f else 0f },
|
titleAlphaProvider = { if (chapters.fastAny { it.selected }) 1f else 0f },
|
||||||
backgroundAlphaProvider = { 1f },
|
backgroundAlphaProvider = { 1f },
|
||||||
hasFilters = state.manga.chaptersFiltered(),
|
hasFilters = state.manga.chaptersFiltered(),
|
||||||
incognitoMode = state.isIncognitoMode,
|
incognitoMode = state.isIncognitoMode,
|
||||||
@ -472,13 +475,13 @@ fun MangaScreenLargeImpl(
|
|||||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = chapters.any { !it.chapter.read } && chapters.none { it.selected },
|
visible = chapters.fastAny { !it.chapter.read } && chapters.fastAll { !it.selected },
|
||||||
enter = fadeIn(),
|
enter = fadeIn(),
|
||||||
exit = fadeOut(),
|
exit = fadeOut(),
|
||||||
) {
|
) {
|
||||||
ExtendedFloatingActionButton(
|
ExtendedFloatingActionButton(
|
||||||
text = {
|
text = {
|
||||||
val id = if (chapters.any { it.chapter.read }) {
|
val id = if (chapters.fastAny { it.chapter.read }) {
|
||||||
R.string.action_resume
|
R.string.action_resume
|
||||||
} else {
|
} else {
|
||||||
R.string.action_start
|
R.string.action_start
|
||||||
@ -584,29 +587,29 @@ private fun SharedMangaBottomActionMenu(
|
|||||||
visible = selected.isNotEmpty(),
|
visible = selected.isNotEmpty(),
|
||||||
modifier = modifier.fillMaxWidth(fillFraction),
|
modifier = modifier.fillMaxWidth(fillFraction),
|
||||||
onBookmarkClicked = {
|
onBookmarkClicked = {
|
||||||
onMultiBookmarkClicked.invoke(selected.map { it.chapter }, true)
|
onMultiBookmarkClicked.invoke(selected.fastMap { it.chapter }, true)
|
||||||
}.takeIf { selected.any { !it.chapter.bookmark } },
|
}.takeIf { selected.fastAny { !it.chapter.bookmark } },
|
||||||
onRemoveBookmarkClicked = {
|
onRemoveBookmarkClicked = {
|
||||||
onMultiBookmarkClicked.invoke(selected.map { it.chapter }, false)
|
onMultiBookmarkClicked.invoke(selected.fastMap { it.chapter }, false)
|
||||||
}.takeIf { selected.all { it.chapter.bookmark } },
|
}.takeIf { selected.fastAll { it.chapter.bookmark } },
|
||||||
onMarkAsReadClicked = {
|
onMarkAsReadClicked = {
|
||||||
onMultiMarkAsReadClicked(selected.map { it.chapter }, true)
|
onMultiMarkAsReadClicked(selected.fastMap { it.chapter }, true)
|
||||||
}.takeIf { selected.any { !it.chapter.read } },
|
}.takeIf { selected.fastAny { !it.chapter.read } },
|
||||||
onMarkAsUnreadClicked = {
|
onMarkAsUnreadClicked = {
|
||||||
onMultiMarkAsReadClicked(selected.map { it.chapter }, false)
|
onMultiMarkAsReadClicked(selected.fastMap { it.chapter }, false)
|
||||||
}.takeIf { selected.any { it.chapter.read || it.chapter.lastPageRead > 0L } },
|
}.takeIf { selected.fastAny { it.chapter.read || it.chapter.lastPageRead > 0L } },
|
||||||
onMarkPreviousAsReadClicked = {
|
onMarkPreviousAsReadClicked = {
|
||||||
onMarkPreviousAsReadClicked(selected[0].chapter)
|
onMarkPreviousAsReadClicked(selected[0].chapter)
|
||||||
}.takeIf { selected.size == 1 },
|
}.takeIf { selected.size == 1 },
|
||||||
onDownloadClicked = {
|
onDownloadClicked = {
|
||||||
onDownloadChapter!!(selected.toList(), ChapterDownloadAction.START)
|
onDownloadChapter!!(selected.toList(), ChapterDownloadAction.START)
|
||||||
}.takeIf {
|
}.takeIf {
|
||||||
onDownloadChapter != null && selected.any { it.downloadState != Download.State.DOWNLOADED }
|
onDownloadChapter != null && selected.fastAny { it.downloadState != Download.State.DOWNLOADED }
|
||||||
},
|
},
|
||||||
onDeleteClicked = {
|
onDeleteClicked = {
|
||||||
onMultiDeleteClicked(selected.map { it.chapter })
|
onMultiDeleteClicked(selected.fastMap { it.chapter })
|
||||||
}.takeIf {
|
}.takeIf {
|
||||||
onDownloadChapter != null && selected.any { it.downloadState == Download.State.DOWNLOADED }
|
onDownloadChapter != null && selected.fastAny { it.downloadState == Download.State.DOWNLOADED }
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -662,7 +665,7 @@ private fun onChapterItemClick(
|
|||||||
) {
|
) {
|
||||||
when {
|
when {
|
||||||
chapterItem.selected -> onToggleSelection(false)
|
chapterItem.selected -> onToggleSelection(false)
|
||||||
chapters.any { it.selected } -> onToggleSelection(true)
|
chapters.fastAny { it.selected } -> onToggleSelection(true)
|
||||||
else -> onChapterClicked(chapterItem.chapter)
|
else -> onChapterClicked(chapterItem.chapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.util.fastMap
|
||||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||||
import cafe.adriel.voyager.core.model.coroutineScope
|
import cafe.adriel.voyager.core.model.coroutineScope
|
||||||
import cafe.adriel.voyager.core.model.rememberScreenModel
|
import cafe.adriel.voyager.core.model.rememberScreenModel
|
||||||
@ -240,14 +241,14 @@ private class ClearDatabaseScreenModel : StateScreenModel<ClearDatabaseScreenMod
|
|||||||
|
|
||||||
fun selectAll() = mutableState.update { state ->
|
fun selectAll() = mutableState.update { state ->
|
||||||
if (state !is State.Ready) return@update state
|
if (state !is State.Ready) return@update state
|
||||||
state.copy(selection = state.items.map { it.id })
|
state.copy(selection = state.items.fastMap { it.id })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun invertSelection() = mutableState.update { state ->
|
fun invertSelection() = mutableState.update { state ->
|
||||||
if (state !is State.Ready) return@update state
|
if (state !is State.Ready) return@update state
|
||||||
state.copy(
|
state.copy(
|
||||||
selection = state.items
|
selection = state.items
|
||||||
.map { it.id }
|
.fastMap { it.id }
|
||||||
.filterNot { it in state.selection },
|
.filterNot { it in state.selection },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.pluralStringResource
|
import androidx.compose.ui.res.pluralStringResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.util.fastMap
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
import eu.kanade.domain.category.interactor.GetCategories
|
import eu.kanade.domain.category.interactor.GetCategories
|
||||||
@ -204,8 +205,8 @@ class SettingsDownloadScreen : SearchableSettings {
|
|||||||
itemLabel = { it.visualName },
|
itemLabel = { it.visualName },
|
||||||
onDismissRequest = { showDialog = false },
|
onDismissRequest = { showDialog = false },
|
||||||
onValueChanged = { newIncluded, newExcluded ->
|
onValueChanged = { newIncluded, newExcluded ->
|
||||||
downloadNewChapterCategoriesPref.set(newIncluded.map { it.id.toString() }.toSet())
|
downloadNewChapterCategoriesPref.set(newIncluded.fastMap { it.id.toString() }.toSet())
|
||||||
downloadNewChapterCategoriesExcludePref.set(newExcluded.map { it.id.toString() }.toSet())
|
downloadNewChapterCategoriesExcludePref.set(newExcluded.fastMap { it.id.toString() }.toSet())
|
||||||
showDialog = false
|
showDialog = false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -25,6 +25,7 @@ import androidx.compose.ui.draw.clipToBounds
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.pluralStringResource
|
import androidx.compose.ui.res.pluralStringResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.util.fastMap
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||||
import com.bluelinelabs.conductor.Router
|
import com.bluelinelabs.conductor.Router
|
||||||
@ -124,9 +125,9 @@ class SettingsLibraryScreen : SearchableSettings {
|
|||||||
|
|
||||||
// For default category
|
// For default category
|
||||||
val ids = listOf(libraryPreferences.defaultCategory().defaultValue()) +
|
val ids = listOf(libraryPreferences.defaultCategory().defaultValue()) +
|
||||||
allCategories.map { it.id.toInt() }
|
allCategories.fastMap { it.id.toInt() }
|
||||||
val labels = listOf(stringResource(R.string.default_category_summary)) +
|
val labels = listOf(stringResource(R.string.default_category_summary)) +
|
||||||
allCategories.map { it.visualName(context) }
|
allCategories.fastMap { it.visualName(context) }
|
||||||
|
|
||||||
return Preference.PreferenceGroup(
|
return Preference.PreferenceGroup(
|
||||||
title = stringResource(R.string.categories),
|
title = stringResource(R.string.categories),
|
||||||
|
@ -21,6 +21,8 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.util.fastAll
|
||||||
|
import androidx.compose.ui.util.fastAny
|
||||||
import eu.kanade.presentation.components.AppBar
|
import eu.kanade.presentation.components.AppBar
|
||||||
import eu.kanade.presentation.components.ChapterDownloadAction
|
import eu.kanade.presentation.components.ChapterDownloadAction
|
||||||
import eu.kanade.presentation.components.EmptyScreen
|
import eu.kanade.presentation.components.EmptyScreen
|
||||||
@ -241,24 +243,24 @@ private fun UpdatesBottomBar(
|
|||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
onBookmarkClicked = {
|
onBookmarkClicked = {
|
||||||
onMultiBookmarkClicked.invoke(selected, true)
|
onMultiBookmarkClicked.invoke(selected, true)
|
||||||
}.takeIf { selected.any { !it.update.bookmark } },
|
}.takeIf { selected.fastAny { !it.update.bookmark } },
|
||||||
onRemoveBookmarkClicked = {
|
onRemoveBookmarkClicked = {
|
||||||
onMultiBookmarkClicked.invoke(selected, false)
|
onMultiBookmarkClicked.invoke(selected, false)
|
||||||
}.takeIf { selected.all { it.update.bookmark } },
|
}.takeIf { selected.fastAll { it.update.bookmark } },
|
||||||
onMarkAsReadClicked = {
|
onMarkAsReadClicked = {
|
||||||
onMultiMarkAsReadClicked(selected, true)
|
onMultiMarkAsReadClicked(selected, true)
|
||||||
}.takeIf { selected.any { !it.update.read } },
|
}.takeIf { selected.fastAny { !it.update.read } },
|
||||||
onMarkAsUnreadClicked = {
|
onMarkAsUnreadClicked = {
|
||||||
onMultiMarkAsReadClicked(selected, false)
|
onMultiMarkAsReadClicked(selected, false)
|
||||||
}.takeIf { selected.any { it.update.read } },
|
}.takeIf { selected.fastAny { it.update.read } },
|
||||||
onDownloadClicked = {
|
onDownloadClicked = {
|
||||||
onDownloadChapter(selected, ChapterDownloadAction.START)
|
onDownloadChapter(selected, ChapterDownloadAction.START)
|
||||||
}.takeIf {
|
}.takeIf {
|
||||||
selected.any { it.downloadStateProvider() != Download.State.DOWNLOADED }
|
selected.fastAny { it.downloadStateProvider() != Download.State.DOWNLOADED }
|
||||||
},
|
},
|
||||||
onDeleteClicked = {
|
onDeleteClicked = {
|
||||||
onMultiDeleteClicked(selected)
|
onMultiDeleteClicked(selected)
|
||||||
}.takeIf { selected.any { it.downloadStateProvider() == Download.State.DOWNLOADED } },
|
}.takeIf { selected.fastAny { it.downloadStateProvider() == Download.State.DOWNLOADED } },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user