From 84dd4dbad08cd4ba30a36720e84ac80ca9c5be1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eamil=20NART?= Date: Tue, 9 Jan 2018 22:17:12 +0300 Subject: [PATCH] Fix invalid image json parsing --- .../main/java/com/imgurisnotimgur/api/ImgurApi.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/imgurisnotimgur/api/ImgurApi.kt b/app/src/main/java/com/imgurisnotimgur/api/ImgurApi.kt index 21f5e31..1c9fbaa 100644 --- a/app/src/main/java/com/imgurisnotimgur/api/ImgurApi.kt +++ b/app/src/main/java/com/imgurisnotimgur/api/ImgurApi.kt @@ -242,8 +242,16 @@ class ImgurApi { val jsonResponse = body.string() val gson = Gson() val imgurJson = getJsonData(jsonResponse) - val imgurImage = gson.fromJson(imgurJson, Image::class.java) - return Image(imgurImage.id, id, SecretUtils.getSecrets(context).second.accountUsername, imgurImage.points, imgurImage.createdAt, imgurImage.albumId, imgurImage.isAlbum) + val imgurImage = gson.fromJson(imgurJson, ImgurGalleryAlbum::class.java) + return Image ( + if (imgurImage.is_album) { imgurImage.cover } else { imgurImage.id }, + if (imgurImage.title != null) { imgurImage.title } else { imgurImage.id }, + SecretUtils.getSecrets(context).second.accountUsername, + imgurImage.points, + imgurImage.datetime, + if (imgurImage.is_album) { imgurImage.id } else { "" }, + imgurImage.is_album + ) } } } \ No newline at end of file