diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 84bab5c..02020d9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -236,7 +236,6 @@ dependencies { implementation(libs.google.accompanist.drawablepainter) implementation(libs.kotlinx.serialization.json) - implementation(libs.kotlinx.collections.immutable) implementation(libs.utilcodex) implementation(libs.activityResultLauncher) diff --git a/app/src/main/kotlin/li/songe/gkd/data/GlobalRule.kt b/app/src/main/kotlin/li/songe/gkd/data/GlobalRule.kt index e46a4bc..d25d5c8 100644 --- a/app/src/main/kotlin/li/songe/gkd/data/GlobalRule.kt +++ b/app/src/main/kotlin/li/songe/gkd/data/GlobalRule.kt @@ -1,6 +1,5 @@ package li.songe.gkd.data -import kotlinx.collections.immutable.ImmutableMap import li.songe.gkd.service.launcherAppId import li.songe.gkd.util.ResolvedGlobalGroup import li.songe.gkd.util.systemAppsFlow @@ -15,7 +14,7 @@ data class GlobalApp( class GlobalRule( rule: RawSubscription.RawGlobalRule, g: ResolvedGlobalGroup, - appInfoCache: ImmutableMap, + appInfoCache: Map, ) : ResolvedRule( rule = rule, g = g, diff --git a/app/src/main/kotlin/li/songe/gkd/data/SubsItem.kt b/app/src/main/kotlin/li/songe/gkd/data/SubsItem.kt index 0e4439a..644c889 100644 --- a/app/src/main/kotlin/li/songe/gkd/data/SubsItem.kt +++ b/app/src/main/kotlin/li/songe/gkd/data/SubsItem.kt @@ -10,7 +10,6 @@ import androidx.room.PrimaryKey import androidx.room.Query import androidx.room.Transaction import androidx.room.Update -import kotlinx.collections.immutable.toImmutableMap import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.serialization.Serializable @@ -113,6 +112,6 @@ fun deleteSubscription(vararg subsIds: Long) { } } } - subsIdToRawFlow.value = newMap.toImmutableMap() + subsIdToRawFlow.value = newMap } } diff --git a/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt index b6a294f..fda7c26 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt @@ -56,7 +56,6 @@ import androidx.compose.ui.window.Dialog import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import com.dylanc.activityresult.launcher.launchForResult -import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch @@ -354,7 +353,7 @@ fun useSubsManagePage(): ScaffoldExt { this[index] = subsItem.copy(order = index) } } - }.toImmutableList() + } draggedFlag.value = true } Box( diff --git a/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt b/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt index f1589d4..874fae8 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/AppInfoState.kt @@ -7,9 +7,6 @@ import android.content.IntentFilter import android.content.pm.PackageManager import android.os.Build import com.blankj.utilcode.util.LogUtils -import kotlinx.collections.immutable.persistentMapOf -import kotlinx.collections.immutable.toImmutableList -import kotlinx.collections.immutable.toImmutableMap import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.sync.Mutex @@ -20,11 +17,11 @@ import li.songe.gkd.appScope import li.songe.gkd.data.AppInfo import li.songe.gkd.data.toAppInfo -val appInfoCacheFlow = MutableStateFlow(persistentMapOf().toImmutableMap()) +val appInfoCacheFlow = MutableStateFlow(emptyMap()) val systemAppInfoCacheFlow by lazy { appInfoCacheFlow.map(appScope) { c -> - c.filter { a -> a.value.isSystem }.toImmutableMap() + c.filter { a -> a.value.isSystem } } } @@ -34,7 +31,7 @@ val orderedAppInfosFlow by lazy { appInfoCacheFlow.map(appScope) { c -> c.values.sortedWith { a, b -> collator.compare(a.name, b.name) - }.toImmutableList() + } } } @@ -92,7 +89,7 @@ private fun updateAppInfo(appId: String) { } else { newMap.remove(appId) } - appInfoCacheFlow.value = newMap.toImmutableMap() + appInfoCacheFlow.value = newMap } } } @@ -116,7 +113,7 @@ suspend fun initOrResetAppInfoCache() { } } } - appInfoCacheFlow.value = appMap.toImmutableMap() + appInfoCacheFlow.value = appMap } appRefreshingFlow.value = false LogUtils.d("initOrResetAppInfoCache end") diff --git a/app/src/main/kotlin/li/songe/gkd/util/SubsState.kt b/app/src/main/kotlin/li/songe/gkd/util/SubsState.kt index c710e21..f6e49d4 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/SubsState.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/SubsState.kt @@ -4,12 +4,6 @@ import com.blankj.utilcode.util.LogUtils import com.blankj.utilcode.util.NetworkUtils import io.ktor.client.request.get import io.ktor.client.statement.bodyAsText -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.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow @@ -36,8 +30,7 @@ import li.songe.json5.decodeFromJson5String import java.net.URI val subsItemsFlow by lazy { - DbSet.subsItemDao.query().map { s -> s.toImmutableList() } - .stateIn(appScope, SharingStarted.Eagerly, persistentListOf()) + DbSet.subsItemDao.query().stateIn(appScope, SharingStarted.Eagerly, emptyList()) } data class SubsEntry( @@ -56,9 +49,9 @@ data class SubsEntry( } } -val subsLoadErrorsFlow = MutableStateFlow>(persistentMapOf()) -val subsRefreshErrorsFlow = MutableStateFlow>(persistentMapOf()) -val subsIdToRawFlow = MutableStateFlow>(persistentMapOf()) +val subsLoadErrorsFlow = MutableStateFlow>(emptyMap()) +val subsRefreshErrorsFlow = MutableStateFlow>(emptyMap()) +val subsIdToRawFlow = MutableStateFlow>(emptyMap()) val subsEntriesFlow by lazy { combine( @@ -70,8 +63,8 @@ val subsEntriesFlow by lazy { subsItem = s, subscription = subsIdToRaw[s.id], ) - }.toImmutableList() - }.stateIn(appScope, SharingStarted.Eagerly, persistentListOf()) + } + }.stateIn(appScope, SharingStarted.Eagerly, emptyList()) } @@ -85,12 +78,12 @@ fun updateSubscription(subscription: RawSubscription) { } else { newMap[subscription.id] = subscription } - subsIdToRawFlow.value = newMap.toImmutableMap() + subsIdToRawFlow.value = newMap if (subsLoadErrorsFlow.value.contains(subscription.id)) { subsLoadErrorsFlow.update { it.toMutableMap().apply { remove(subscription.id) - }.toImmutableMap() + } } } withContext(Dispatchers.IO) { @@ -126,11 +119,11 @@ fun getGroupRawEnable( } data class RuleSummary( - val globalRules: ImmutableList = persistentListOf(), - val globalGroups: ImmutableList = persistentListOf(), - val appIdToRules: ImmutableMap> = persistentMapOf(), - val appIdToGroups: ImmutableMap> = persistentMapOf(), - val appIdToAllGroups: ImmutableMap> = persistentMapOf(), + val globalRules: List = emptyList(), + val globalGroups: List = emptyList(), + val appIdToRules: Map> = emptyMap(), + val appIdToGroups: Map> = emptyMap(), + val appIdToAllGroups: Map> = emptyMap(), ) { val appSize = appIdToRules.keys.size val appGroupSize = appIdToGroups.values.sumOf { s -> s.size } @@ -276,12 +269,11 @@ val ruleSummaryFlow by lazy { } } RuleSummary( - globalRules = globalRules.toImmutableList(), - globalGroups = globalGroups.toImmutableList(), - appIdToRules = appRules.mapValues { e -> e.value.toImmutableList() }.toImmutableMap(), - appIdToGroups = appGroups.mapValues { e -> e.value.toImmutableList() }.toImmutableMap(), - appIdToAllGroups = appAllGroups.mapValues { e -> e.value.toImmutableList() } - .toImmutableMap() + globalRules = globalRules, + globalGroups = globalGroups, + appIdToRules = appRules, + appIdToGroups = appGroups, + appIdToAllGroups = appAllGroups ) }.flowOn(Dispatchers.Default).stateIn(appScope, SharingStarted.Eagerly, RuleSummary()) } @@ -321,8 +313,8 @@ private fun refreshRawSubsList(items: List) { errors[s.id] = e } } - subsIdToRawFlow.value = subscriptions.toImmutableMap() - subsLoadErrorsFlow.value = errors.toImmutableMap() + subsIdToRawFlow.value = subscriptions + subsLoadErrorsFlow.value = errors } fun initSubsState() { @@ -416,14 +408,14 @@ fun checkSubsUpdate(showToast: Boolean = false) = appScope.launchTry(Dispatchers subsRefreshErrorsFlow.update { it.toMutableMap().apply { remove(subsEntry.subsItem.id) - }.toImmutableMap() + } } } } catch (e: Exception) { subsRefreshErrorsFlow.update { it.toMutableMap().apply { set(subsEntry.subsItem.id, e) - }.toImmutableMap() + } } LogUtils.d("检测更新失败", e) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 441e529..0aedffe 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,6 @@ kotlin_serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", v kotlin_stdlib_common = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "kotlin" } kotlin_test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } kotlinx_serialization_json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.7.3" } -kotlinx_collections_immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version = "0.3.8" } ktor_server_core = { module = "io.ktor:ktor-server-core", version.ref = "ktor" } ktor_server_cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor" } ktor_server_content_negotiation = { module = "io.ktor:ktor-server-content-negotiation", version.ref = "ktor" } diff --git a/selector/src/commonMain/kotlin/li/songe/selector/SyntaxError.kt b/selector/src/commonMain/kotlin/li/songe/selector/SyntaxError.kt index ff2a94c..7aba603 100644 --- a/selector/src/commonMain/kotlin/li/songe/selector/SyntaxError.kt +++ b/selector/src/commonMain/kotlin/li/songe/selector/SyntaxError.kt @@ -3,7 +3,7 @@ package li.songe.selector import kotlin.js.JsExport @JsExport -data class SyntaxError internal constructor( +data class SyntaxError @JsExport.Ignore constructor( val expectedValue: String, val position: Int, val source: String, diff --git a/selector/src/commonMain/kotlin/li/songe/selector/ValueExpression.kt b/selector/src/commonMain/kotlin/li/songe/selector/ValueExpression.kt index d850889..28513e1 100644 --- a/selector/src/commonMain/kotlin/li/songe/selector/ValueExpression.kt +++ b/selector/src/commonMain/kotlin/li/songe/selector/ValueExpression.kt @@ -17,7 +17,7 @@ sealed class ValueExpression(open val value: Any?, open val type: String) : Posi override val value: String, ) : ValueExpression(value, "var") - data class Identifier internal constructor( + data class Identifier( override val start: Int, val name: String, ) : Variable(name) { @@ -35,7 +35,7 @@ sealed class ValueExpression(open val value: Any?, open val type: String) : Posi val isNotEqual = name == "notEqual" } - data class MemberExpression internal constructor( + data class MemberExpression( override val start: Int, override val end: Int, val object0: Variable, @@ -61,7 +61,7 @@ sealed class ValueExpression(open val value: Any?, open val type: String) : Posi val isPropertyIfElse = property == "ifElse" } - data class CallExpression internal constructor( + data class CallExpression( override val start: Int, override val end: Int, val callee: Variable, @@ -173,26 +173,26 @@ sealed class ValueExpression(open val value: Any?, open val type: String) : Posi get() = emptyArray() } - data class NullLiteral internal constructor( + data class NullLiteral( override val start: Int, ) : LiteralExpression(null, "null") { override val end = start + 4 } - data class BooleanLiteral internal constructor( + data class BooleanLiteral( override val start: Int, override val value: Boolean ) : LiteralExpression(value, "boolean") { override val end = start + if (value) 4 else 5 } - data class IntLiteral internal constructor( + data class IntLiteral( override val start: Int, override val end: Int, override val value: Int ) : LiteralExpression(value, "int") - data class StringLiteral internal constructor( + data class StringLiteral @JsExport.Ignore constructor( override val start: Int, override val end: Int, override val value: String, diff --git a/stability_config.conf b/stability_config.conf index b534575..a788494 100644 --- a/stability_config.conf +++ b/stability_config.conf @@ -1 +1,2 @@ li.songe.gkd.* +kotlin.collections.*