From 5b090b7919bf049f5617ddf5263cc5878e4f176b Mon Sep 17 00:00:00 2001 From: Daniel Yrovas Date: Fri, 16 Feb 2024 22:59:55 +1100 Subject: [PATCH] prevent background crash when network error occurs --- .../main/java/org/yrovas/linklater/LinkDingAPI.kt | 13 +++++++++---- .../java/org/yrovas/linklater/SaveActivityState.kt | 1 - .../linklater/ui/screens/SaveBookmarkScreen.kt | 2 +- gradle/libs.versions.toml | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/yrovas/linklater/LinkDingAPI.kt b/app/src/main/java/org/yrovas/linklater/LinkDingAPI.kt index 647e93b..b62225a 100644 --- a/app/src/main/java/org/yrovas/linklater/LinkDingAPI.kt +++ b/app/src/main/java/org/yrovas/linklater/LinkDingAPI.kt @@ -47,10 +47,14 @@ class LinkDingAPI( } override suspend fun saveBookmark(bookmark: LocalBookmark): Boolean { - return Ktor.client.post("$endpoint/bookmarks/") { - setBody(bookmark) - header("Authorization", "Token $token") - }.status.value in 200..299 + return try { + Ktor.client.post("$endpoint/bookmarks/") { + setBody(bookmark) + header("Authorization", "Token $token") + }.status.value in 200..299 + } catch (e: Exception) { + false + } } override suspend fun getCachedBookmarks(context: Context): List { @@ -83,6 +87,7 @@ class LinkDingAPI( } response.body().results }.onFailure { + Log.i(TAG, "getTags: ${it.message}") Result.failure>(it) } } diff --git a/app/src/main/java/org/yrovas/linklater/SaveActivityState.kt b/app/src/main/java/org/yrovas/linklater/SaveActivityState.kt index 477e2b4..401d927 100644 --- a/app/src/main/java/org/yrovas/linklater/SaveActivityState.kt +++ b/app/src/main/java/org/yrovas/linklater/SaveActivityState.kt @@ -2,7 +2,6 @@ package org.yrovas.linklater import android.content.Context import android.util.Log -import androidx.annotation.Keep import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.* import org.yrovas.linklater.data.LocalBookmark diff --git a/app/src/main/java/org/yrovas/linklater/ui/screens/SaveBookmarkScreen.kt b/app/src/main/java/org/yrovas/linklater/ui/screens/SaveBookmarkScreen.kt index db8eb1b..abf0ed4 100644 --- a/app/src/main/java/org/yrovas/linklater/ui/screens/SaveBookmarkScreen.kt +++ b/app/src/main/java/org/yrovas/linklater/ui/screens/SaveBookmarkScreen.kt @@ -116,7 +116,7 @@ fun SaveBookmarkFields(saveActivityState: SaveActivityState, submit: () -> Unit) icon = Icons.Default.Tag, onChange = { saveActivityState.updateTagNames(tagNames = it) }) - var rows by remember { mutableStateOf(max(abs(tags.size / 5), 1)) } + var rows by remember { mutableIntStateOf(max(abs(tags.size / 4), 1)) } if (collapseTags && rows > 3) rows = 3 if (!collapseTags) rows = max(abs(tags.size / 4), 1) Column( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 86e9863..ad3b67f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] app-versionID = "org.yrovas.linklater" -app-versionCode = "1" -app-versionName = "0.1.0" +app-versionCode = "2" +app-versionName = "0.1.1" app-compileSDK = "34" app-targetSDK = "34" app-minimumSDK = "23"