From: Olaf Wintermann Date: Sun, 31 Aug 2025 10:24:37 +0000 (+0200) Subject: highlight unread items, update items when selected X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=a51f887b1269b574a03dc71d42c3bd137415bd5d;p=rssreader.git highlight unread items, update items when selected --- 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 543787d..171d6c7 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -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() + } + } + } } 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 0ccde9c..77324bf 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt @@ -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 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 d27fabc..e619486 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -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 ->