Skip to content

Commit

Permalink
feat: show unread count in title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Jacobs committed Jun 9, 2024
1 parent 1ec4a64 commit feace1b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
47 changes: 25 additions & 22 deletions app/src/main/java/com/nononsenseapps/feeder/archmodel/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -416,44 +416,46 @@ class Repository(override val di: DI) : DIAware {
fun getScreenTitleForFeedOrTag(
feedId: Long,
tag: String,
) = flow {
emit(
ScreenTitle(
title =
when {
feedId > ID_UNSET -> feedStore.getDisplayTitle(feedId)
tag.isNotBlank() -> tag
else -> null
},
type =
when (feedId) {
ID_UNSET -> FeedType.TAG
ID_ALL_FEEDS -> FeedType.ALL_FEEDS
ID_SAVED_ARTICLES -> FeedType.SAVED_ARTICLES
else -> FeedType.FEED
},
),
) = getUnreadCount(feedId).mapLatest { unreadCount ->
ScreenTitle(
title =
when {
feedId > ID_UNSET -> feedStore.getDisplayTitle(feedId)
tag.isNotBlank() -> tag
else -> null
},
type =
when (feedId) {
ID_UNSET -> FeedType.TAG
ID_ALL_FEEDS -> FeedType.ALL_FEEDS
ID_SAVED_ARTICLES -> FeedType.SAVED_ARTICLES
else -> FeedType.FEED
},
unreadCount = unreadCount,
)
}

@OptIn(ExperimentalCoroutinesApi::class)
fun getScreenTitleForCurrentFeedOrTag(): Flow<ScreenTitle> =
currentFeedAndTag.mapLatest { (feedId, tag) ->
ScreenTitle(
title =
currentFeedAndTag.flatMapLatest { (feedId, tag) ->
getUnreadCount(feedId).mapLatest { unreadCount ->
ScreenTitle(
title =
when {
feedId > ID_UNSET -> feedStore.getDisplayTitle(feedId)
tag.isNotBlank() -> tag
else -> null
},
type =
type =
when (feedId) {
ID_UNSET -> FeedType.TAG
ID_ALL_FEEDS -> FeedType.ALL_FEEDS
ID_SAVED_ARTICLES -> FeedType.SAVED_ARTICLES
else -> FeedType.FEED
},
)
unreadCount = unreadCount,
)
}
}

suspend fun deleteFeeds(feedIds: List<Long>) {
Expand Down Expand Up @@ -834,6 +836,7 @@ private data class FeedListArgs(
data class ScreenTitle(
val title: String?,
val type: FeedType,
val unreadCount: Int,
)

enum class FeedType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,12 @@ fun FeedScreen(
},
text = {},
modifier =
Modifier
.height(0.dp)
.safeSemantics {
contentDescription = closeMenuText
role = Role.Button
},
Modifier
.height(0.dp)
.safeSemantics {
contentDescription = closeMenuText
role = Role.Button
},
)
}
}
Expand Down Expand Up @@ -996,10 +996,9 @@ fun FeedScreen(
scrollBehavior = scrollBehavior,
title =
when (viewState.feedScreenTitle.type) {
FeedType.FEED -> viewState.feedScreenTitle.title
FeedType.TAG -> viewState.feedScreenTitle.title
FeedType.FEED, FeedType.TAG -> "${viewState.feedScreenTitle.title} ${stringResource(id = R.string.title_unread_count, viewState.feedScreenTitle.unreadCount)}"
FeedType.SAVED_ARTICLES -> stringResource(id = R.string.saved_articles)
FeedType.ALL_FEEDS -> stringResource(id = R.string.all_feeds)
FeedType.ALL_FEEDS -> "${stringResource(id = R.string.all_feeds)} ${stringResource(id = R.string.title_unread_count, viewState.feedScreenTitle.unreadCount)}"
} ?: "",
navigationIcon = {
IconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class FeedArticleViewModel(
.stateIn(
viewModelScope,
SharingStarted.Eagerly,
ScreenTitle("", FeedType.ALL_FEEDS),
ScreenTitle("", FeedType.ALL_FEEDS, 0),
)

private val visibleFeeds: StateFlow<List<FeedTitle>> =
Expand Down Expand Up @@ -702,7 +702,7 @@ data class FeedArticleScreenViewState(
override val currentTheme: ThemeOptions = ThemeOptions.SYSTEM,
override val currentlySyncing: Boolean = false,
// Defaults to empty string to avoid rendering until loading complete
override val feedScreenTitle: ScreenTitle = ScreenTitle("", FeedType.FEED),
override val feedScreenTitle: ScreenTitle = ScreenTitle("", FeedType.FEED, 0),
override val visibleFeeds: List<FeedTitle> = emptyList(),
override val feedItemStyle: FeedItemStyle = FeedItemStyle.CARD,
override val expandedTags: Set<String> = emptySet(),
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@
<string name="close_menu">Close menu</string>
<string name="skip_duplicate_articles">Skip duplicate articles</string>
<string name="skip_duplicate_articles_desc">Articles with links or titles identical to existing articles are ignored</string>
<string name="touch_to_play_audio">Touch to play audio</string>
<string name="touch_to_play_audio">Touch to play audio</string>
<string name="title_unread_count" translatable="false">(%1$d)</string>
</resources>

0 comments on commit feace1b

Please sign in to comment.