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 4f0558f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 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

0 comments on commit 4f0558f

Please sign in to comment.