diff options
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/data')
| -rw-r--r-- | app/src/main/java/org/terst/feedreader/data/Daos.kt | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/app/src/main/java/org/terst/feedreader/data/Daos.kt b/app/src/main/java/org/terst/feedreader/data/Daos.kt index d089885..22f1d22 100644 --- a/app/src/main/java/org/terst/feedreader/data/Daos.kt +++ b/app/src/main/java/org/terst/feedreader/data/Daos.kt @@ -61,10 +61,34 @@ private const val ARTICLE_LIST_FROM = "articles LEFT JOIN feeds ON articles.feed @Dao interface ArticleDao { - // Unread-first, newest-first -- the default "what's new" view across every feed. - @Query("SELECT $ARTICLE_LIST_COLUMNS FROM $ARTICLE_LIST_FROM WHERE articles.isRead = 0 ORDER BY articles.publishedAt DESC") - fun observeUnread(): Flow<List<ArticleListItem>> - + // The default "what's new" view -- clamped to the last RECENT_WINDOW_MS (see + // MainActivity) so a backlog of hundreds of older unread items doesn't bury + // what's actually new. Undated articles (publishedAt failed to parse) are kept + // here rather than silently dropped from both views. + @Query( + "SELECT $ARTICLE_LIST_COLUMNS FROM $ARTICLE_LIST_FROM " + + "WHERE articles.isRead = 0 AND (articles.publishedAt IS NULL OR articles.publishedAt >= :cutoff) " + + "ORDER BY articles.publishedAt DESC" + ) + fun observeUnread(cutoff: Long): Flow<List<ArticleListItem>> + + // The rest of the unread backlog, older than the cutoff -- its own view rather + // than mixed into the main one. + @Query( + "SELECT $ARTICLE_LIST_COLUMNS FROM $ARTICLE_LIST_FROM " + + "WHERE articles.isRead = 0 AND articles.publishedAt IS NOT NULL AND articles.publishedAt < :cutoff " + + "ORDER BY articles.publishedAt DESC" + ) + fun observeOlderUnread(cutoff: Long): Flow<List<ArticleListItem>> + + @Query("SELECT COUNT(*) FROM articles WHERE isRead = 0 AND (publishedAt IS NULL OR publishedAt >= :cutoff)") + fun observeUnreadCount(cutoff: Long): Flow<Int> + + @Query("SELECT COUNT(*) FROM articles WHERE isRead = 0 AND publishedAt IS NOT NULL AND publishedAt < :cutoff") + fun observeOlderUnreadCount(cutoff: Long): Flow<Int> + + // Per-feed unread badge counts in the feed list -- deliberately NOT time-clamped, + // so a feed's number reflects its whole backlog regardless of the Unread/Older split. @Query("SELECT feedId, COUNT(*) as count FROM articles WHERE isRead = 0 AND feedId IS NOT NULL GROUP BY feedId") fun observeUnreadCounts(): Flow<List<FeedUnreadCount>> @@ -89,6 +113,11 @@ interface ArticleDao { @Query("UPDATE articles SET isRead = :read WHERE id = :id") suspend fun setRead(id: String, read: Boolean) + // Explicit bulk action ("mark read from here") -- batched per confirmed tap, + // never called implicitly (e.g. by scrolling). + @Query("UPDATE articles SET isRead = 1 WHERE id IN (:ids)") + suspend fun markReadBatch(ids: List<String>) + @Query("UPDATE articles SET isRead = 1 WHERE feedId = :feedId") suspend fun markAllReadForFeed(feedId: String) |
