Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.jocmp.capy.buildArticlePager
import com.jocmp.capy.common.UnauthorizedError
import com.jocmp.capy.common.launchIO
import com.jocmp.capy.common.launchUI
import com.jocmp.capy.common.withUIContext
import com.jocmp.capy.countAll
import com.jocmp.capy.findArticlePages
import com.jocmp.capy.logging.CapyLog
Expand All @@ -43,6 +44,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import java.io.IOException
import java.time.OffsetDateTime

@OptIn(ExperimentalCoroutinesApi::class)
Expand Down Expand Up @@ -275,21 +277,35 @@ class ArticleScreenViewModel(
refreshJob?.cancel()

refreshJob = viewModelScope.launch(Dispatchers.IO) {
account.refresh(filter).onFailure { throwable ->
if (throwable is UnauthorizedError && _showUnauthorizedMessage == UnauthorizedMessageState.HIDE) {
_showUnauthorizedMessage = UnauthorizedMessageState.SHOW
val result = account.refresh(filter)

withUIContext {
result.onFailure { throwable ->
if (throwable is UnauthorizedError && _showUnauthorizedMessage == UnauthorizedMessageState.HIDE) {
_showUnauthorizedMessage = UnauthorizedMessageState.SHOW
} else {
val res = when (throwable) {
is IOException -> R.string.refresh_failure_network_error
else -> R.string.refresh_failure_fallback
}

context.toast(res)
}
}
}

onComplete()
onComplete()
}
}
}

fun refresh(filter: ArticleFilter, onComplete: () -> Unit) {
initialize(filter) {
updateArticlesSince()
onComplete()
}
initialize(
filter,
onComplete = {
updateArticlesSince()
onComplete()
}
)
}

fun selectArticle(articleID: String) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,6 @@
<string name="media_share_failure">Failed to share image</string>
<string name="media_share">Share</string>
<string name="feed_nav_drawer_refresh_all">Refresh all</string>
<string name="refresh_failure_network_error">Refresh failed. Check your connection.</string>
<string name="refresh_failure_fallback">Refresh failed</string>
</resources>