Skip to content

Commit

Permalink
Show loading indicator when featured posts are being refreshed
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Aug 7, 2024
1 parent a9a0af0 commit 267d45a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import dev.sasikanth.rss.reader.utils.getTodayStartInstant
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -273,7 +272,6 @@ class HomePresenter(
}
}

@OptIn(FlowPreview::class)
private fun init() {
combine(observableActiveSource.activeSource, settingsRepository.postsType) {
activeSource,
Expand All @@ -286,6 +284,7 @@ class HomePresenter(
it.copy(
activeSource = activeSource,
postsType = postsType,
loadingState = HomeLoadingState.Loading,
featuredPosts = null,
posts = null
)
Expand Down Expand Up @@ -339,6 +338,7 @@ class HomePresenter(
NTuple4(activeSource, postsAfter, unreadOnly, featuredPostsIds)
}
}
.onEach { _state.update { it.copy(loadingState = HomeLoadingState.Idle) } }
.distinctUntilChanged()
.onEach { (activeSource, postsAfter, unreadOnly, featuredPostsIds) ->
val posts =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
Expand Down Expand Up @@ -182,7 +180,7 @@ internal fun HomeScreen(
)
},
body = { paddingValues ->
Box {
Box(modifier = Modifier.fillMaxSize()) {
when {
hasFeeds == null || (posts == null || featuredPosts == null) -> {
// no-op
Expand Down Expand Up @@ -223,9 +221,7 @@ internal fun HomeScreen(
PullRefreshIndicator(
refreshing = state.isRefreshing,
state = swipeRefreshState,
modifier =
Modifier.windowInsetsPadding(WindowInsets.statusBars)
.align(Alignment.TopCenter)
modifier = Modifier.padding(paddingValues).align(Alignment.TopCenter)
)
}
},
Expand Down

0 comments on commit 267d45a

Please sign in to comment.