From 84ed72f95dfdc2f104763146b970dab3df14e243 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Wed, 3 Sep 2025 18:48:19 +0200 Subject: [PATCH] implement read status mode 1: update all items when opening a feed --- .../kotlin/de/unixwork/rssreader/Database.kt | 26 ++++++++++++++----- .../de/unixwork/rssreader/FeedCollection.kt | 2 +- .../kotlin/de/unixwork/rssreader/FeedList.kt | 7 +++++ .../de/unixwork/rssreader/MainWindow.kt | 14 ++++++---- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt index 862cf73..d549b9b 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -54,7 +54,7 @@ object Database { pos INT default 0, name VARCHAR, update_interval INT, - auto_mark_read BOOLEAN DEFAULT FALSE + item_state_mode INT DEFAULT 0 ) """.trimIndent()) @@ -107,7 +107,7 @@ object Database { f.feedcollection_id, f.name as feed_name, f.update_interval, - f.auto_mark_read, + f.item_state_mode, c.unread_count from groups g left join feedcollections f on g.group_id = f.group_id @@ -123,7 +123,7 @@ object Database { val feedId = rs.getInt("feedcollection_id") val feedName = rs.getString("feed_name") val updateInterval = rs.getLong("update_interval") - val autoMarkRead = rs.getBoolean("auto_mark_read") + val itemStateMode = rs.getInt("item_state_mode") val unreadCount = rs.getInt("unread_count") if(currentGroup == null || currentGroup.id != groupId) { @@ -134,7 +134,7 @@ object Database { if(feedId != null && feedName != null) { val feed = FeedCollection(feedId, feedName) feed.updateInterval = updateInterval - feed.autoMarkRead = autoMarkRead + feed.itemStateMode = itemStateMode feed.unreadItemsCount = unreadCount currentGroup.feeds.add(feed) } @@ -172,17 +172,17 @@ object Database { password: String? = null, cert: String? = null, updateInterval: Long = 0, - autoMarkRead: Boolean = false) : FeedCollection + itemStateMode: Int = 0) : FeedCollection { var feedcollectionId = -1 val connection = dataSource.connection connection.prepareStatement(""" - insert into feedcollections (group_id, pos, name, update_interval, auto_mark_read) select ?, coalesce(max(pos), 0)+1, ?, ?, ? from groups + insert into feedcollections (group_id, pos, name, update_interval, item_state_mode) select ?, coalesce(max(pos), 0)+1, ?, ?, ? from groups """.trimIndent(), Statement.RETURN_GENERATED_KEYS).use { stmt -> stmt.setInt(1, parent.id) stmt.setString(2, name) stmt.setLong(3, updateInterval) - stmt.setBoolean(4, autoMarkRead) + stmt.setInt(4, itemStateMode) stmt.execute() stmt.generatedKeys.use { rs -> if(rs.next()) { @@ -317,4 +317,16 @@ object Database { } } } + + public fun updateFeedReadState(feedCollection: FeedCollection, read: Boolean) { + dataSource.connection.use { conn -> + conn.prepareStatement(""" + update items set is_read = ? where feed_id in (select feed_id from feedcollections where feedcollection_id = ?) + """.trimIndent()).use { stmt -> + stmt.setBoolean(1, read) + stmt.setInt(2, feedCollection.id) + stmt.execute() + } + } + } } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt index 5d8190b..538161f 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt @@ -6,7 +6,7 @@ class FeedCollection(id: Int, name: String) { val id = id val name = name var updateInterval: Long = 0 - var autoMarkRead = false + var itemStateMode = 0 var unreadItemsCount = 0 var items = mutableListOf() diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt index 4a5029a..ff8e1de 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt @@ -24,6 +24,13 @@ class FeedList : Document() { var showFeed: FeedCollection? = null fun loadFeed(feed: FeedCollection) { + if(feed.itemStateMode > 0 && feed.unreadItemsCount > 0) { + feed.unreadItemsCount = 0 + GlobalScope.launch(Dispatchers.IO) { + Database.updateFeedReadState(feed, true) + } + } + showFeed = feed if(!feed.itemsLoaded) { if(feed.itemsLoading) { diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt index 1eb007a..a1c4bda 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -36,6 +36,7 @@ class MainWindow { feed?.let { println("feed: ${feed.name}") feedList.loadFeed(feed) + sourceList.feeds.update() } } catch (e: Exception) { e.printStackTrace() @@ -45,7 +46,7 @@ class MainWindow { { elm: FeedCollection -> val item = SubListItem() item.label = elm.name - if(elm.unreadItemsCount > 0) { + if(elm.unreadItemsCount > 0 && elm.itemStateMode != 2) { item.badge = elm.unreadItemsCount.toString() } item @@ -85,7 +86,7 @@ class MainWindow { var ret = false // only highlight unread items if the feed(collection) is configured // to have individual read states - if(feedList.currentFeed?.autoMarkRead == false) { + if(feedList.currentFeed?.itemStateMode == 0) { // col == -1: style for the entire row // highlight unread items if(col == -1 && !elm.isRead) { @@ -173,8 +174,10 @@ class MainWindow { val feedName = name.toString() val urlStr = urls.toString() val uris = urlStr.split("\n").map { it.trim() }.filter { it.isNotBlank() } - val readStatus = readstatus?.selectedIndex - val automarkread = readStatus == 1 + var itemStateMode = readstatus?.selectedIndex ?: 0 + if(itemStateMode < 0 || itemStateMode > 2) { + itemStateMode = 0 + } println("groupSel: ${groups?.selectedIndex}, feedName: $feedName, urlStr: $urlStr") parent?.let { try { @@ -186,7 +189,7 @@ class MainWindow { password.toString(), cert.toString(), 0, // TODO - automarkread + itemStateMode ) parent.feeds.update() @@ -211,6 +214,7 @@ class MainWindow { readstatus.add("Mark items individually") readstatus.add("Mark entire feed when opened") + readstatus.add("Don't show number of unread items") // UI grid( -- 2.47.3