mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 15:47:03 +05:30
refactor(android): switch over to PagingData transformations
This commit is contained in:
parent
051b7ab2bb
commit
74a7835a53
19 changed files with 187 additions and 151 deletions
|
@ -9,7 +9,6 @@
|
|||
package dev.msfjarvis.claw.model
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import dev.msfjarvis.claw.database.local.SavedPost
|
||||
import io.mcarle.konvert.api.KonvertTo
|
||||
import io.mcarle.konvert.api.Mapping
|
||||
import kotlinx.serialization.SerialName
|
||||
|
@ -18,7 +17,7 @@ import kotlinx.serialization.Serializable
|
|||
@Serializable
|
||||
@Poko
|
||||
@KonvertTo(
|
||||
value = SavedPost::class,
|
||||
value = UIPost::class,
|
||||
mappings =
|
||||
[
|
||||
Mapping(target = "submitterName", expression = "it.submitter.username"),
|
||||
|
|
|
@ -17,6 +17,14 @@ import kotlinx.serialization.Serializable
|
|||
|
||||
@Serializable
|
||||
@Poko
|
||||
@KonvertTo(
|
||||
value = UIPost::class,
|
||||
mappings =
|
||||
[
|
||||
Mapping(target = "submitterName", expression = "it.submitter.username"),
|
||||
Mapping(target = "submitterAvatarUrl", expression = "it.submitter.avatarUrl"),
|
||||
],
|
||||
)
|
||||
@KonvertTo(
|
||||
value = SavedPost::class,
|
||||
mappings =
|
||||
|
|
50
model/src/main/kotlin/dev/msfjarvis/claw/model/UIPost.kt
Normal file
50
model/src/main/kotlin/dev/msfjarvis/claw/model/UIPost.kt
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright © 2021-2024 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model
|
||||
|
||||
import dev.msfjarvis.claw.database.local.SavedPost
|
||||
import io.mcarle.konvert.api.KonvertFrom
|
||||
import io.mcarle.konvert.api.KonvertTo
|
||||
import io.mcarle.konvert.api.Mapping
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
@KonvertTo(
|
||||
value = SavedPost::class,
|
||||
mappings =
|
||||
[
|
||||
Mapping(target = "submitterName", expression = "it.submitter.username"),
|
||||
Mapping(target = "submitterAvatarUrl", expression = "it.submitter.avatarUrl"),
|
||||
],
|
||||
)
|
||||
data class UIPost(
|
||||
val shortId: String,
|
||||
val createdAt: String,
|
||||
val title: String,
|
||||
val url: String,
|
||||
val description: String,
|
||||
val commentCount: Int,
|
||||
val commentsUrl: String,
|
||||
@SerialName("submitter_user") val submitter: User,
|
||||
val tags: List<String>,
|
||||
val comments: List<Comment> = emptyList(),
|
||||
val isSaved: Boolean = false,
|
||||
val isRead: Boolean = false,
|
||||
) {
|
||||
@KonvertFrom(
|
||||
value = SavedPost::class,
|
||||
mappings =
|
||||
[
|
||||
Mapping(
|
||||
target = "submitter",
|
||||
expression = "User(it.submitterName, \"\", null, it.submitterAvatarUrl, \"\")",
|
||||
),
|
||||
Mapping(target = "commentCount", expression = "it.commentCount ?: 0"),
|
||||
Mapping(target = "isSaved", expression = "true"),
|
||||
],
|
||||
)
|
||||
companion object
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue