Drop kotlinx-collections-immutable usage (#3380)

This commit is contained in:
AntsyLich
2026-06-04 02:45:24 +06:00
committed by GitHub
parent 7f8851de6a
commit cd27b10750
91 changed files with 317 additions and 523 deletions
@@ -49,7 +49,6 @@ import eu.kanade.presentation.util.Screen
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.browse.migration.search.MigrateSearchScreen
import eu.kanade.tachiyomi.util.system.LocaleHelper
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.flow.update
import mihon.feature.migration.list.MigrationListScreen
import sh.calvin.reorderable.ReorderableCollectionItemScope
@@ -118,7 +117,7 @@ class MigrationConfigScreen(private val mangaIds: Collection<Long>) : Screen() {
scrollBehavior = it,
actions = {
AppBarActions(
persistentListOf(
listOf(
AppBar.Action(
title = stringResource(MR.strings.migrationConfigScreen_selectAllLabel),
icon = Icons.Outlined.SelectAll,
@@ -55,8 +55,6 @@ import eu.kanade.presentation.util.animateItemFastScroll
import eu.kanade.presentation.util.formatChapterNumber
import eu.kanade.presentation.util.rememberResourceBitmapPainter
import eu.kanade.tachiyomi.R
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import mihon.feature.migration.list.models.MigratingManga
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
@@ -71,7 +69,7 @@ import tachiyomi.presentation.core.util.plus
@Composable
fun MigrationListScreenContent(
items: ImmutableList<MigratingManga>,
items: List<MigratingManga>,
migrationComplete: Boolean,
finishedCount: Int,
onItemClick: (Manga) -> Unit,
@@ -91,7 +89,7 @@ fun MigrationListScreenContent(
},
actions = {
AppBarActions(
persistentListOf(
listOf(
AppBar.Action(
title = stringResource(MR.strings.migrationListScreen_copyActionLabel),
icon = if (items.size == 1) Icons.Outlined.ContentCopy else Icons.Outlined.CopyAll,
@@ -9,10 +9,6 @@ import eu.kanade.domain.manga.model.toSManga
import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.getNameForMangaInfo
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
@@ -86,7 +82,7 @@ class MigrationListScreenModel(
}
.awaitAll()
.filterNotNull()
mutableState.update { it.copy(items = manga.toImmutableList()) }
mutableState.update { it.copy(items = manga) }
runMigrations(manga)
}
}
@@ -327,7 +323,7 @@ class MigrationListScreenModel(
}
private fun removeManga(item: MigratingManga) {
mutableState.update { it.copy(items = items.toPersistentList().remove(item)) }
mutableState.update { it.copy(items = items.toMutableList().apply { remove(item) }) }
}
override fun onDispose() {
@@ -371,7 +367,7 @@ class MigrationListScreenModel(
}
data class State(
val items: ImmutableList<MigratingManga> = persistentListOf(),
val items: List<MigratingManga> = listOf(),
val finishedCount: Int = 0,
val migrationComplete: Boolean = false,
val dialog: Dialog? = null,
@@ -25,8 +25,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.presentation.components.AppBar
import eu.kanade.presentation.components.relativeDateText
import eu.kanade.presentation.util.isTabletUi
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.coroutines.launch
import mihon.feature.upcoming.components.UpcomingItem
import mihon.feature.upcoming.components.calendar.Calendar
@@ -136,8 +134,8 @@ private fun DateHeading(
@Composable
private fun UpcomingScreenSmallImpl(
listState: LazyListState,
items: ImmutableList<UpcomingUIModel>,
events: ImmutableMap<LocalDate, Int>,
items: List<UpcomingUIModel>,
events: Map<LocalDate, Int>,
paddingValues: PaddingValues,
selectedYearMonth: YearMonth,
setSelectedYearMonth: (YearMonth) -> Unit,
@@ -187,8 +185,8 @@ private fun UpcomingScreenSmallImpl(
@Composable
private fun UpcomingScreenLargeImpl(
listState: LazyListState,
items: ImmutableList<UpcomingUIModel>,
events: ImmutableMap<LocalDate, Int>,
items: List<UpcomingUIModel>,
events: Map<LocalDate, Int>,
paddingValues: PaddingValues,
selectedYearMonth: YearMonth,
setSelectedYearMonth: (YearMonth) -> Unit,
@@ -6,12 +6,6 @@ import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import eu.kanade.core.util.insertSeparatorsReversed
import eu.kanade.tachiyomi.util.lang.toLocalDate
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
@@ -41,7 +35,7 @@ class UpcomingScreenModel(
}
}
private fun List<Manga>.toUpcomingUIModels(): ImmutableList<UpcomingUIModel> {
private fun List<Manga>.toUpcomingUIModels(): List<UpcomingUIModel> {
var mangaCount = 0
return fastMap { UpcomingUIModel.Item(it) }
.insertSeparatorsReversed { before, after ->
@@ -56,16 +50,14 @@ class UpcomingScreenModel(
null
}
}
.toImmutableList()
}
private fun List<UpcomingUIModel>.toEvents(): ImmutableMap<LocalDate, Int> {
private fun List<UpcomingUIModel>.toEvents(): Map<LocalDate, Int> {
return filterIsInstance<UpcomingUIModel.Header>()
.associate { it.date to it.mangaCount }
.toImmutableMap()
}
private fun List<UpcomingUIModel>.getHeaderIndexes(): ImmutableMap<LocalDate, Int> {
private fun List<UpcomingUIModel>.getHeaderIndexes(): Map<LocalDate, Int> {
return fastMapIndexedNotNull { index, upcomingUIModel ->
if (upcomingUIModel is UpcomingUIModel.Header) {
upcomingUIModel.date to index
@@ -74,7 +66,6 @@ class UpcomingScreenModel(
}
}
.toMap()
.toImmutableMap()
}
fun setSelectedYearMonth(yearMonth: YearMonth) {
@@ -83,8 +74,8 @@ class UpcomingScreenModel(
data class State(
val selectedYearMonth: YearMonth = YearMonth.now(),
val items: ImmutableList<UpcomingUIModel> = persistentListOf(),
val events: ImmutableMap<LocalDate, Int> = persistentMapOf(),
val headerIndexes: ImmutableMap<LocalDate, Int> = persistentMapOf(),
val items: List<UpcomingUIModel> = listOf(),
val events: Map<LocalDate, Int> = mapOf(),
val headerIndexes: Map<LocalDate, Int> = mapOf(),
)
}
@@ -19,8 +19,6 @@ import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.fastForEach
import io.woong.compose.grid.SimpleGridCells
import io.woong.compose.grid.VerticalGrid
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.toImmutableList
import mihon.core.designsystem.utils.isExpandedWidthWindow
import mihon.core.designsystem.utils.isMediumWidthWindow
import tachiyomi.presentation.core.components.material.padding
@@ -37,7 +35,7 @@ private const val DAYS_OF_WEEK = 7
@Composable
fun Calendar(
selectedYearMonth: YearMonth,
events: ImmutableMap<LocalDate, Int>,
events: Map<LocalDate, Int>,
setSelectedYearMonth: (YearMonth) -> Unit,
onClickDay: (day: LocalDate) -> Unit,
modifier: Modifier = Modifier,
@@ -67,14 +65,13 @@ fun Calendar(
@Composable
private fun CalendarGrid(
selectedYearMonth: YearMonth,
events: ImmutableMap<LocalDate, Int>,
events: Map<LocalDate, Int>,
onClickDay: (day: LocalDate) -> Unit,
) {
val localeFirstDayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek.value
val weekDays = remember {
(0 until DAYS_OF_WEEK)
.map { DayOfWeek.of((localeFirstDayOfWeek - 1 + it) % DAYS_OF_WEEK + 1) }
.toImmutableList()
}
val emptyFieldCount = weekDays.indexOf(selectedYearMonth.atDay(1).dayOfWeek)