]> uap-core.de Git - rssreader.git/commitdiff
implement read status mode 1: update all items when opening a feed
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 3 Sep 2025 16:48:19 +0000 (18:48 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 3 Sep 2025 16:48:19 +0000 (18:48 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

index 862cf734eebfc00a51ed3f5396329117599e81ce..d549b9bb5d8456c47fb318e633a74854411852a5 100644 (file)
@@ -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()
+            }
+        }
+    }
 }
index 5d8190b478736c0341d69a13cb6a9dcb110fccf6..538161f4695b01b6d42dd08e12a5d9aba3fb3053 100644 (file)
@@ -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<Item>()
index 4a5029ab1c9074af528bc8f6e453d724eafdc7bc..ff8e1de838628cb55340a58278c9e5010fdb4896 100644 (file)
@@ -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) {
index 1eb007a59b769f845b5bec74be228b7a41cf04fb..a1c4bdae5baa76871244f150c7d73d717b0ec77e 100644 (file)
@@ -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(