Skip to content

Commit

Permalink
[1.131.*] Pre-release merge (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Apr 18, 2024
2 parents 8650299 + 6a6dd77 commit 6295df3
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,56 @@ class HomePresenter(
}

private fun init() {
observableActiveSource.activeSource
.onEach { selectedSource ->
combine(observableActiveSource.activeSource, settingsRepository.postsType) {
activeSource,
postsType ->
Pair(activeSource, postsType)
}
.onEach { (activeSource, postsType) ->
_state.update {
it.copy(activeSource = selectedSource, posts = null, featuredPosts = null)
it.copy(
activeSource = activeSource,
postsType = postsType,
featuredPosts = null,
posts = null
)
}
}
.combine(settingsRepository.postsType) { selectedSource, postsType ->
_state.update { it.copy(postsType = postsType) }
selectedSource to postsType
.flatMapLatest {
val postsType = _state.value.postsType
val activeSource = _state.value.activeSource

val unreadOnly =
when (postsType) {
PostsType.ALL,
PostsType.TODAY,
PostsType.LAST_24_HOURS -> null
PostsType.UNREAD -> true
}

val postsAfter =
when (postsType) {
PostsType.ALL,
PostsType.UNREAD -> Instant.DISTANT_PAST
PostsType.TODAY -> {
getTodayStartInstant()
}
PostsType.LAST_24_HOURS -> {
getLast24HourStart()
}
}

rssRepository.featuredPosts(
selectedFeedId = activeSource?.id,
unreadOnly = unreadOnly,
after = postsAfter
)
}
.flatMapLatest { (selectedSource, postsType) ->
.onEach { featuredPosts ->
val featuredPostIds = featuredPosts.map { it.id }
val postsType = _state.value.postsType
val activeSource = _state.value.activeSource

val unreadOnly =
when (postsType) {
PostsType.ALL,
Expand All @@ -258,24 +297,16 @@ class HomePresenter(
val posts =
createPager(config = createPagingConfig(pageSize = 20, enablePlaceholders = true)) {
rssRepository.posts(
selectedFeedId = selectedSource?.id,
selectedFeedId = activeSource?.id,
featuredPostsIds = featuredPostIds,
unreadOnly = unreadOnly,
after = postsAfter
after = postsAfter,
)
}
.flow
.cachedIn(coroutineScope)

rssRepository
.featuredPosts(
selectedFeedId = selectedSource?.id,
unreadOnly = unreadOnly,
after = postsAfter
)
.map { featuredPosts -> Pair(featuredPosts.toImmutableList(), posts) }
}
.onEach { (featuredPosts, posts) ->
_state.update { it.copy(featuredPosts = featuredPosts, posts = posts) }
_state.update { it.copy(featuredPosts = featuredPosts.toImmutableList(), posts = posts) }
}
.launchIn(coroutineScope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,41 +135,43 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif
}
}

Box(modifier = modifier) {
val bottomSheetSwipeTransition =
updateTransition(
targetState = bottomSheetScaffoldState.currentFraction,
label = "Bottom Sheet Swipe Progress"
)
val bottomSheetCornerSize by
bottomSheetSwipeTransition.animateDp { BOTTOM_SHEET_CORNER_SIZE * it.inverse() }
val bottomSheetSwipeTransition =
updateTransition(
targetState = bottomSheetScaffoldState.currentFraction,
label = "Bottom Sheet Swipe Progress"
)
val bottomSheetCornerSize by
bottomSheetSwipeTransition.animateDp { BOTTOM_SHEET_CORNER_SIZE * it.inverse() }
val sheetPeekHeight =
BOTTOM_SHEET_PEEK_HEIGHT +
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
val showScrollToTop by remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } }

BottomSheetScaffold(
modifier =
Modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal)),
scaffoldState = bottomSheetScaffoldState,
backgroundColor = AppTheme.colorScheme.surfaceContainerLowest,
sheetBackgroundColor = AppTheme.colorScheme.tintedBackground,
sheetContentColor = AppTheme.colorScheme.tintedForeground,
sheetElevation = 0.dp,
sheetPeekHeight =
BOTTOM_SHEET_PEEK_HEIGHT +
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding(),
sheetShape =
RoundedCornerShape(topStart = bottomSheetCornerSize, topEnd = bottomSheetCornerSize),
sheetGesturesEnabled = !feedsState.isInMultiSelectMode,
topBar = {
HomeTopAppBar(
source = state.activeSource,
postsType = state.postsType,
listState = listState,
onSearchClicked = { homePresenter.dispatch(HomeEvent.SearchClicked) },
onBookmarksClicked = { homePresenter.dispatch(HomeEvent.BookmarksClicked) },
onSettingsClicked = { homePresenter.dispatch(HomeEvent.SettingsClicked) },
onPostTypeChanged = { homePresenter.dispatch(HomeEvent.OnPostsTypeChanged(it)) }
)
},
content = { paddingValues ->
BottomSheetScaffold(
modifier =
modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal)),
scaffoldState = bottomSheetScaffoldState,
backgroundColor = AppTheme.colorScheme.surfaceContainerLowest,
sheetBackgroundColor = AppTheme.colorScheme.tintedBackground,
sheetContentColor = AppTheme.colorScheme.tintedForeground,
sheetElevation = 0.dp,
sheetPeekHeight = sheetPeekHeight,
sheetShape =
RoundedCornerShape(topStart = bottomSheetCornerSize, topEnd = bottomSheetCornerSize),
sheetGesturesEnabled = !feedsState.isInMultiSelectMode,
topBar = {
HomeTopAppBar(
source = state.activeSource,
postsType = state.postsType,
listState = listState,
onSearchClicked = { homePresenter.dispatch(HomeEvent.SearchClicked) },
onBookmarksClicked = { homePresenter.dispatch(HomeEvent.BookmarksClicked) },
onSettingsClicked = { homePresenter.dispatch(HomeEvent.SettingsClicked) },
onPostTypeChanged = { homePresenter.dispatch(HomeEvent.OnPostsTypeChanged(it)) }
)
},
content = { paddingValues ->
Box(modifier = Modifier.fillMaxSize()) {
HomeScreenContent(
paddingValues = paddingValues,
state = state,
Expand All @@ -189,63 +191,56 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif
homePresenter.dispatch(HomeEvent.TogglePostReadStatus(postId, postRead))
}
)
},
sheetContent = {
FeedsBottomSheet(
feedsPresenter = homePresenter.feedsPresenter,
bottomSheetSwipeTransition = bottomSheetSwipeTransition,
closeSheet = { coroutineScope.launch { bottomSheetState.collapse() } },
selectedFeedChanged = {
coroutineScope.launch {
listState.scrollToItem(0)
featuredPostsPagerState.scrollToPage(0)
}
}
)
},
snackbarHost = {
val snackbarModifier =
if (bottomSheetState.isExpanded) {
Modifier.padding(bottom = BOTTOM_SHEET_PEEK_HEIGHT)
.windowInsetsPadding(
WindowInsets.systemBars.only(
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
)
)
} else {
Modifier
}

SnackbarHost(hostState = it, modifier = snackbarModifier) { snackbarData ->
Snackbar(
modifier = Modifier.padding(12.dp),
content = {
Text(text = snackbarData.message, maxLines = 4, overflow = TextOverflow.Ellipsis)
},
action = null,
actionOnNewLine = false,
shape = SnackbarDefaults.shape,
backgroundColor = SnackbarDefaults.color,
contentColor = SnackbarDefaults.contentColor,
elevation = 0.dp
)
}
},
floatingActionButton = {
val showScrollToTop by remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } }

CompactFloatingActionButton(
label = LocalStrings.current.scrollToTop,
visible = showScrollToTop,
modifier =
Modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal))
.padding(end = 16.dp, bottom = 16.dp),
.padding(end = 16.dp, bottom = sheetPeekHeight + 16.dp),
) {
listState.animateScrollToItem(0)
}
},
)
}
}
},
sheetContent = {
FeedsBottomSheet(
feedsPresenter = homePresenter.feedsPresenter,
bottomSheetSwipeTransition = bottomSheetSwipeTransition,
closeSheet = { coroutineScope.launch { bottomSheetState.collapse() } },
selectedFeedChanged = {
coroutineScope.launch {
listState.scrollToItem(0)
featuredPostsPagerState.scrollToPage(0)
}
}
)
},
snackbarHost = {
val snackbarModifier =
if (bottomSheetState.isExpanded) {
Modifier.padding(bottom = sheetPeekHeight)
.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal))
} else {
Modifier
}

SnackbarHost(hostState = it, modifier = snackbarModifier) { snackbarData ->
Snackbar(
modifier = Modifier.padding(12.dp),
content = {
Text(text = snackbarData.message, maxLines = 4, overflow = TextOverflow.Ellipsis)
},
action = null,
actionOnNewLine = false,
shape = SnackbarDefaults.shape,
backgroundColor = SnackbarDefaults.color,
contentColor = SnackbarDefaults.contentColor,
elevation = 0.dp
)
}
},
)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,15 @@ class RssRepository(

fun posts(
selectedFeedId: String?,
featuredPostsIds: List<String>,
unreadOnly: Boolean? = null,
after: Instant = Instant.DISTANT_PAST
after: Instant = Instant.DISTANT_PAST,
): PagingSource<Int, PostWithMetadata> {
return QueryPagingSource(
countQuery =
postQueries.count(
sourceId = selectedFeedId,
featuredPostsLimit = NUMBER_OF_FEATURED_POSTS,
featuredPosts = featuredPostsIds,
unreadOnly = unreadOnly,
postsAfter = after,
),
Expand All @@ -213,7 +214,7 @@ class RssRepository(
queryProvider = { limit, offset ->
postQueries.posts(
sourceId = selectedFeedId,
featuredPostsLimit = NUMBER_OF_FEATURED_POSTS,
featuredPosts = featuredPostsIds,
unreadOnly = unreadOnly,
postsAfter = after,
limit = limit,
Expand Down
Binary file added shared/src/commonMain/sqldelight/databases/18.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE post(
);

CREATE INDEX post_source_id_index ON post(sourceId);
CREATE INDEX post_date_desc_index ON post (date DESC);

upsert:
INSERT INTO post(id, sourceId, title, description, rawContent, imageUrl, date, link, commentsLink)
Expand All @@ -34,21 +35,7 @@ WHERE
post.sourceId = :sourceId OR
feedGroup.id = :sourceId
) AND
-- Skip featured posts --
post.id NOT IN (
SELECT post.id FROM post
WHERE
(:unreadOnly IS NULL OR post.read != :unreadOnly) AND
(
:sourceId IS NULL OR
post.sourceId = :sourceId OR
feedGroup.id = :sourceId
) AND
post.imageUrl IS NOT NULL AND
post.date > :postsAfter
ORDER BY post.date DESC LIMIT :featuredPostsLimit
) AND
-- Skip featured posts --
post.id NOT IN :featuredPosts AND
post.date > :postsAfter
ORDER BY post.date DESC;

Expand Down Expand Up @@ -104,21 +91,7 @@ WHERE
post.sourceId = :sourceId OR
feedGroup.id = :sourceId
) AND
-- Skip featured posts --
post.id NOT IN (
SELECT post.id FROM post
WHERE
(:unreadOnly IS NULL OR post.read != :unreadOnly) AND
(
:sourceId IS NULL OR
post.sourceId = :sourceId OR
feedGroup.id = :sourceId
) AND
post.imageUrl IS NOT NULL AND
post.date > :postsAfter
ORDER BY post.date DESC LIMIT :featuredPostsLimit
) AND
-- Skip featured posts --
post.id NOT IN :featuredPosts AND
post.date > :postsAfter
ORDER BY post.date DESC
LIMIT :limit OFFSET :offset;
Expand Down
1 change: 1 addition & 0 deletions shared/src/commonMain/sqldelight/migrations/17.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX post_date_desc_index ON post (date DESC);

0 comments on commit 6295df3

Please sign in to comment.