Use Compose fast* functions in more places

This commit is contained in:
arkon
2022-10-30 12:27:12 -04:00
parent 156191af44
commit 86c3d8c064
7 changed files with 46 additions and 36 deletions

View File

@@ -25,6 +25,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
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.coroutineScope
import cafe.adriel.voyager.core.model.rememberScreenModel
@@ -240,14 +241,14 @@ private class ClearDatabaseScreenModel : StateScreenModel<ClearDatabaseScreenMod
fun selectAll() = mutableState.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 ->
if (state !is State.Ready) return@update state
state.copy(
selection = state.items
.map { it.id }
.fastMap { it.id }
.filterNot { it in state.selection },
)
}

View File

@@ -16,6 +16,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.util.fastMap
import androidx.core.net.toUri
import com.hippo.unifile.UniFile
import eu.kanade.domain.category.interactor.GetCategories
@@ -204,8 +205,8 @@ class SettingsDownloadScreen : SearchableSettings {
itemLabel = { it.visualName },
onDismissRequest = { showDialog = false },
onValueChanged = { newIncluded, newExcluded ->
downloadNewChapterCategoriesPref.set(newIncluded.map { it.id.toString() }.toSet())
downloadNewChapterCategoriesExcludePref.set(newExcluded.map { it.id.toString() }.toSet())
downloadNewChapterCategoriesPref.set(newIncluded.fastMap { it.id.toString() }.toSet())
downloadNewChapterCategoriesExcludePref.set(newExcluded.fastMap { it.id.toString() }.toSet())
showDialog = false
},
)

View File

@@ -25,6 +25,7 @@ import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.util.fastMap
import androidx.core.content.ContextCompat
import cafe.adriel.voyager.navigator.currentOrThrow
import com.bluelinelabs.conductor.Router
@@ -124,9 +125,9 @@ class SettingsLibraryScreen : SearchableSettings {
// For default category
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)) +
allCategories.map { it.visualName(context) }
allCategories.fastMap { it.visualName(context) }
return Preference.PreferenceGroup(
title = stringResource(R.string.categories),