From fb9ceecabd986fd917940c4eee10ec3c958b7c41 Mon Sep 17 00:00:00 2001 From: Amine Date: Mon, 30 Dec 2024 22:45:18 +0100 Subject: [PATCH] chore: can links be empty ? --- .../android/fragments/ArticleFragment.kt | 8 ++++++- .../readerforselfossv2/model/SelfossModel.kt | 24 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index 83fd978..84226de 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -52,6 +52,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import org.acra.ktx.sendSilentlyWithAcra import org.kodein.di.DI import org.kodein.di.DIAware import org.kodein.di.android.x.closestDI @@ -103,7 +104,12 @@ class ArticleFragment : Fragment(), DIAware { try { binding = FragmentArticleBinding.inflate(inflater, container, false) - url = item.getLinkDecoded() + try { + url = item.getLinkDecoded() + } catch (e: Exception) { + e.sendSilentlyWithAcra() + } + contentText = item.content contentTitle = item.title.getHtmlDecoded() contentImage = item.getThumbnail(repository.baseUrl) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt index 70073bd..9b2bd99 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt @@ -2,6 +2,7 @@ package bou.amine.apps.readerforselfossv2.model import bou.amine.apps.readerforselfossv2.utils.DateUtils import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded +import bou.amine.apps.readerforselfossv2.utils.isEmptyOrNullOrNullString import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -10,7 +11,12 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.encodeCollection -import kotlinx.serialization.json.* +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.boolean +import kotlinx.serialization.json.booleanOrNull +import kotlinx.serialization.json.int +import kotlinx.serialization.json.jsonPrimitive class SelfossModel { @Serializable @@ -134,6 +140,10 @@ class SelfossModel { stringUrl = "http:$stringUrl" } + if (stringUrl.isEmptyOrNullOrNullString()) { + throw Exception("Link ${link} was translated to ${stringUrl}, but was empty. Handle this.") + } + return stringUrl } @@ -176,7 +186,10 @@ class SelfossModel { encoder: Encoder, value: List, ) { - encoder.encodeCollection(PrimitiveSerialDescriptor("tags", PrimitiveKind.STRING), value.size) { this.toString() } + encoder.encodeCollection( + PrimitiveSerialDescriptor("tags", PrimitiveKind.STRING), + value.size + ) { this.toString() } } } @@ -191,7 +204,10 @@ class SelfossModel { } override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("BooleanOrIntForSomeSelfossVersions", PrimitiveKind.BOOLEAN) + get() = PrimitiveSerialDescriptor( + "BooleanOrIntForSomeSelfossVersions", + PrimitiveKind.BOOLEAN + ) override fun serialize( encoder: Encoder, @@ -200,4 +216,4 @@ class SelfossModel { TODO("Not yet implemented") } } -} +} \ No newline at end of file