Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace Gson to kotlin serialization
- Loading branch information
Showing
6 changed files
with
50 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package juniojsv.minimum.models | ||
|
||
import android.content.Intent | ||
import com.google.gson.annotations.SerializedName | ||
import java.util.UUID | ||
|
||
data class Application( | ||
@SerializedName("application_label") override val label: String, | ||
override val label: String, | ||
val packageName: String, | ||
val launchIntent: Intent, | ||
val isNew: Boolean = false, | ||
val isPinned: Boolean = false, | ||
val group: UUID? = null, | ||
@SerializedName("application_id") override val id: UUID = UUID.randomUUID() | ||
) : ApplicationBase(label, id) { | ||
override val id: UUID = UUID.randomUUID() | ||
) : ApplicationBase() { | ||
override val priority: Int = if (isPinned) 1 else 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
app/src/main/java/juniojsv/minimum/models/ApplicationsGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package juniojsv.minimum.models | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import juniojsv.minimum.utils.UUIDSerializer | ||
import kotlinx.serialization.Serializable | ||
import java.util.UUID | ||
|
||
/** | ||
* @param mergeWith is the id of target [ApplicationsGroup] to move all items of this group | ||
*/ | ||
@Serializable | ||
data class ApplicationsGroup( | ||
@SerializedName("group_label") override val label: String, | ||
@SerializedName("group_id") override val id: UUID = UUID.randomUUID(), | ||
override val label: String, | ||
@Serializable(with = UUIDSerializer::class) override val id: UUID = UUID.randomUUID(), | ||
val isPinned: Boolean, | ||
val mergeWith: UUID? = null | ||
) : ApplicationBase(label, id) { | ||
@Serializable(with = UUIDSerializer::class) val mergeWith: UUID? = null | ||
) : ApplicationBase() { | ||
override val priority: Int = if (isPinned) 1 else 0 | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/juniojsv/minimum/utils/UUIDSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package juniojsv.minimum.utils | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import java.util.UUID | ||
|
||
object UUIDSerializer : KSerializer<UUID> { | ||
override val descriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING) | ||
|
||
override fun deserialize(decoder: Decoder): UUID { | ||
return UUID.fromString(decoder.decodeString()) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: UUID) { | ||
encoder.encodeString(value.toString()) | ||
} | ||
} |