Add import for new color scheme format

This commit is contained in:
MM20
2025-06-07 14:06:09 +02:00
parent f21feba000
commit 889aa37915
15 changed files with 642 additions and 64 deletions
@@ -0,0 +1,22 @@
package de.mm20.launcher2.serialization
import androidx.core.graphics.toColorInt
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
object ColorIntAsHexSerializer : KSerializer<Int> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor(javaClass.canonicalName!!, PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): Int {
return decoder.decodeString().toColorInt()
}
override fun serialize(encoder: Encoder, value: Int) {
encoder.encodeString("#" + value.toUInt().toString(16).padStart(8, '0'))
}
}
@@ -0,0 +1,30 @@
package de.mm20.launcher2.serialization
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.util.UUID
object UUIDSerializer: KSerializer<UUID> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(
"UUIDSerializer",
PrimitiveKind.STRING
)
override fun serialize(encoder: Encoder, value: UUID) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): UUID {
val string = decoder.decodeString()
return try {
UUID.fromString(string)
} catch (e: IllegalArgumentException) {
throw SerializationException("Invalid UUID format: $string", e)
}
}
}
@@ -828,6 +828,7 @@
<string name="theme_color_scheme_custom_color">Custom</string>
<string name="preference_restore_default">Restore default</string>
<string name="import_theme_apply">Apply theme</string>
<string name="import_theme_exists">Theme already exists and will be updated</string>
<string name="import_theme_error">The selected file could not be read. Please make sure that you selected a valid theme file (*.kvtheme), and that the file is not corrupt.</string>
<string name="shortcut_label_unavailable">Unavailable</string>
<string name="app_label_locked_profile">Locked</string>
@@ -1032,6 +1033,7 @@
<string name="bad_configuration_title">Congratulations, you\'ve locked yourself out!</string>
<string name="bad_configuration_summary">You\'ve discovered a combination of settings that makes both the search and settings inaccessible — effectively locking you out of the launcher.</string>
<string name="theme_export_title">Export theme</string>
<string name="theme_import_title">Import theme</string>
<string name="theme_bundle_name">Name</string>
<string name="theme_bundle_author">Author</string>
</resources>