Skip to content

Commit

Permalink
Fix deserialization exception
Browse files Browse the repository at this point in the history
I hope this time json schema is stable
  • Loading branch information
HeroBrine1st committed Aug 9, 2024
1 parent 7889467 commit 376a756
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ package ru.herobrine1st.e621.api.common
import ru.herobrine1st.e621.api.model.PostReduced
import ru.herobrine1st.e621.api.model.Rating

data class PostReducedCommon(
data class AvatarImageCommon(
val id: Int,
val previewUrl: String? = null,
val croppedUrl: String? = null,
val url: String,
val rating: Rating,
)
fun PostReduced.toCommon() = PostReducedCommon(id = id, previewUrl = previewUrl, croppedUrl = croppedUrl, rating = rating)

fun PostReduced.toCommon() = AvatarImageCommon(id = id, url = previewUrl, rating = rating)
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ data class CommentData(
data class UserData(
val id: Int,
val displayName: String,
val avatarPost: PostReducedCommon?,
val avatarPost: AvatarImageCommon?,
)
}

30 changes: 18 additions & 12 deletions app/src/main/java/ru/herobrine1st/e621/api/model/Post.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,30 @@ data class Post(

@Serializable
data class PostReduced(
val status: String,
val id: Int,
val flags: String,
val tags: String,
val rating: Rating,
@SerialName("file_ext")
val type: FileType,
val id: Int,
val createdAt: Instant,
val rating: Rating,
val previewWidth: Int,
val previewHeight: Int,
val width: Int,
val height: Int,
val tags: String,
val score: Int,
val uploaderId: Int,
val size: Int,
val createdAt: Instant,
val uploader: String,
val md5: String? = null, // o_O
val previewUrl: String? = null,
val croppedUrl: String? = null
val uploaderId: Int,
val score: Int,
@SerialName("fav_count")
val favoriteCount: Int,
@SerialName("is_favorited")
val isFavourite: Boolean,
val pools: List<PoolId>,
val md5: String?,
val previewUrl: String,
val largeUrl: String,
val fileUrl: String,
val previewWidth: Int,
val previewHeight: Int
)

fun Post.selectSample() = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,25 @@ import androidx.compose.ui.platform.LocalContext
import coil.compose.AsyncImage
import coil.request.ImageRequest
import coil.transform.CircleCropTransformation
import ru.herobrine1st.e621.api.common.PostReducedCommon
import ru.herobrine1st.e621.api.common.AvatarImageCommon
import ru.herobrine1st.e621.api.model.Rating
import ru.herobrine1st.e621.ui.component.placeholder.PlaceholderHighlight
import ru.herobrine1st.e621.ui.component.placeholder.material3.fade
import ru.herobrine1st.e621.ui.component.placeholder.material3.placeholder

@Composable
fun CommentAvatar(
avatarPost: PostReducedCommon?,
avatarPost: AvatarImageCommon?,
safeModeEnabled: Boolean,
modifier: Modifier = Modifier,
placeholder: Boolean = false,
onAvatarClick: () -> Unit = {}
) {
var isPlaceholderActive by remember { mutableStateOf(true) }
if (avatarPost != null &&
(avatarPost.rating == Rating.SAFE || !safeModeEnabled) &&
(avatarPost.previewUrl != null || avatarPost.croppedUrl != null)
) {
val url = avatarPost.previewUrl ?: avatarPost.croppedUrl
if (avatarPost != null && (avatarPost.rating == Rating.SAFE || !safeModeEnabled)) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(url)
.data(avatarPost.url)
.crossfade(true)
.transformations(CircleCropTransformation()) // clip(CircleShape) is wrong (white/black zones are present)
.build(),
Expand Down

0 comments on commit 376a756

Please sign in to comment.