Skip to content

Commit

Permalink
prevent background crash when network error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielyrovas committed Feb 16, 2024
1 parent f3e4ba3 commit 5b090b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions app/src/main/java/org/yrovas/linklater/LinkDingAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bookmark> {
Expand Down Expand Up @@ -83,6 +87,7 @@ class LinkDingAPI(
}
response.body<TagResponse>().results
}.onFailure {
Log.i(TAG, "getTags: ${it.message}")
Result.failure<List<String>>(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 5b090b7

Please sign in to comment.