Skip to content

Commit

Permalink
Catch OperationCanceledException exception when loading active stories
Browse files Browse the repository at this point in the history
  • Loading branch information
sictiru committed Jun 14, 2024
1 parent 1dbe85e commit f5dd0bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ protected void updateAdapter(@Nullable Cursor cursor) {
ensureSufficientStories();
}

private void setCursor(Cursor cursor) {
private void setCursor(@Nullable Cursor cursor) {
if (cursor != null) {
if (!dbHelper.isFeedSetReady(getFeedSet())) {
// the DB hasn't caught up yet from the last story list; don't display stale stories.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.newsblur.viewModel

import android.database.Cursor
import android.os.CancellationSignal
import android.os.OperationCanceledException
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.newsblur.database.BlurDatabaseHelper
import com.newsblur.util.CursorFilters
import com.newsblur.util.FeedSet
import com.newsblur.util.Log
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -24,8 +26,12 @@ class StoriesViewModel

fun getActiveStories(fs: FeedSet, cursorFilters: CursorFilters) {
viewModelScope.launch(Dispatchers.IO) {
dbHelper.getActiveStoriesCursor(fs, cursorFilters, cancellationSignal).let {
_activeStoriesLiveData.postValue(it)
try {
dbHelper.getActiveStoriesCursor(fs, cursorFilters, cancellationSignal).let {
_activeStoriesLiveData.postValue(it)
}
} catch (e: OperationCanceledException) {
Log.e(this.javaClass.name, "Caught ${e.javaClass.name} in getActiveStories.")
}
}
}
Expand Down

0 comments on commit f5dd0bf

Please sign in to comment.