From 376a7564b36a4aff1bedefc89c50b57bff8c4ee3 Mon Sep 17 00:00:00 2001 From: HeroBrine1st Erquilenne Date: Fri, 9 Aug 2024 17:47:18 +0300 Subject: [PATCH] Fix deserialization exception I hope this time json schema is stable --- ...tReducedCommon.kt => AvatarImageCommon.kt} | 8 ++--- .../e621/api/common/CommentData.kt | 2 +- .../ru/herobrine1st/e621/api/model/Post.kt | 30 +++++++++++-------- .../ui/screen/post/component/CommentAvatar.kt | 12 +++----- 4 files changed, 27 insertions(+), 25 deletions(-) rename app/src/main/java/ru/herobrine1st/e621/api/common/{PostReducedCommon.kt => AvatarImageCommon.kt} (82%) diff --git a/app/src/main/java/ru/herobrine1st/e621/api/common/PostReducedCommon.kt b/app/src/main/java/ru/herobrine1st/e621/api/common/AvatarImageCommon.kt similarity index 82% rename from app/src/main/java/ru/herobrine1st/e621/api/common/PostReducedCommon.kt rename to app/src/main/java/ru/herobrine1st/e621/api/common/AvatarImageCommon.kt index d590e5cc..0ef5a70d 100644 --- a/app/src/main/java/ru/herobrine1st/e621/api/common/PostReducedCommon.kt +++ b/app/src/main/java/ru/herobrine1st/e621/api/common/AvatarImageCommon.kt @@ -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) \ No newline at end of file + +fun PostReduced.toCommon() = AvatarImageCommon(id = id, url = previewUrl, rating = rating) \ No newline at end of file diff --git a/app/src/main/java/ru/herobrine1st/e621/api/common/CommentData.kt b/app/src/main/java/ru/herobrine1st/e621/api/common/CommentData.kt index 8b74ecc5..1801e3ad 100644 --- a/app/src/main/java/ru/herobrine1st/e621/api/common/CommentData.kt +++ b/app/src/main/java/ru/herobrine1st/e621/api/common/CommentData.kt @@ -82,7 +82,7 @@ data class CommentData( data class UserData( val id: Int, val displayName: String, - val avatarPost: PostReducedCommon?, + val avatarPost: AvatarImageCommon?, ) } diff --git a/app/src/main/java/ru/herobrine1st/e621/api/model/Post.kt b/app/src/main/java/ru/herobrine1st/e621/api/model/Post.kt index aa4b5ff7..4f9d889f 100644 --- a/app/src/main/java/ru/herobrine1st/e621/api/model/Post.kt +++ b/app/src/main/java/ru/herobrine1st/e621/api/model/Post.kt @@ -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, + val md5: String?, + val previewUrl: String, + val largeUrl: String, + val fileUrl: String, + val previewWidth: Int, + val previewHeight: Int ) fun Post.selectSample() = when { diff --git a/app/src/main/java/ru/herobrine1st/e621/ui/screen/post/component/CommentAvatar.kt b/app/src/main/java/ru/herobrine1st/e621/ui/screen/post/component/CommentAvatar.kt index 8053ec5c..1902bb91 100644 --- a/app/src/main/java/ru/herobrine1st/e621/ui/screen/post/component/CommentAvatar.kt +++ b/app/src/main/java/ru/herobrine1st/e621/ui/screen/post/component/CommentAvatar.kt @@ -36,7 +36,7 @@ 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 @@ -44,21 +44,17 @@ 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(),