]> uap-core.de Git - rssreader.git/commitdiff
highlight unread items, update items when selected
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 Aug 2025 10:24:37 +0000 (12:24 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 Aug 2025 10:24:37 +0000 (12:24 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

index 543787dd6cb06f931cb9d13b2835a6786a0db7c0..171d6c721e4a9ca3fa868b50cc65176d54e0f25a 100644 (file)
@@ -295,4 +295,16 @@ object Database {
             }
         }
     }
+
+    public fun updateReadState(item: Item, read: Boolean) {
+        dataSource.connection.use { conn ->
+            conn.prepareStatement("""
+                update items set is_read = ? where item_id = ?
+            """.trimIndent()).use { stmt ->
+                stmt.setBoolean(1, read)
+                stmt.setInt(2, item.id)
+                stmt.execute()
+            }
+        }
+    }
 }
index 0ccde9cb70f1b6bc10c39677f566bf900c641195..77324bf5c0420fdfc60adc85191aba2db7d40950 100644 (file)
@@ -47,13 +47,14 @@ class FeedList : Document() {
 
         }
 
+        currentFeed = feed
+
         // Update item list
         items.clear()
         feed.items.forEach { item ->
             items.add(item)
         }
         items.update()
-        currentFeed = feed
     }
 
     fun reloadCurrentFeed() {
@@ -85,5 +86,14 @@ class FeedList : Document() {
         webview.loadContent(item.link, content, mimeType, "utf-8")
 
         tabview.setIntValue(1)
+
+        // Update read status
+        if(!item.isRead) {
+            item.isRead = true
+            GlobalScope.launch(Dispatchers.IO) {
+                Database.updateReadState(item, true)
+            }
+            items.update(items.selectedIndex)
+        }
     }
 }
\ No newline at end of file
index d27fabcd9ff2e996941b39dc465c0b4a31f17118..e619486c0b1d989ea889d7e273c5fabfb4da88a6 100644 (file)
@@ -68,12 +68,29 @@ class MainWindow {
                         varname = "items",
                         fill = true,
                         onSelection = { event ->
+                            if(event.set != 0) {
+                                // Don't handle set events: in some toolkit implementations, updating the
+                                // list triggers a onSelection event
+                                return@table
+                            }
                             feedList.items.selected?.let {
                                 feedList.selectItem(it)
                             }
                         },
                         getstyle = { elm, col, style ->
-                            false
+                            var ret = false
+                            // only highlight unread items if the feed(collection) is configured
+                            // to have individual read states
+                            if(feedList.currentFeed?.autoMarkRead == false) {
+                                println("yes")
+                                // col == -1: style for the entire row
+                                // highlight unread items
+                                if(col == -1 && !elm.isRead) {
+                                    style.isBold = true
+                                    ret = true
+                                }
+                            }
+                            ret
                         }
                         )
                     { elm, col ->