]> uap-core.de Git - rssreader.git/commitdiff
add menu items for marking feeds as read
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 13 Sep 2025 16:45:03 +0000 (18:45 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 13 Sep 2025 16:45:03 +0000 (18:45 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

index d831cd01d82b60f9eb77ea7780e71d3a604f1d4b..2ffa1256f3d258590d5b6a2ee316d94ac7f9b194 100644 (file)
@@ -26,19 +26,42 @@ object App : Application {
         initToolbar()
     }
 
+    fun syncAll() {
+        SyncJob({ Database.getAllFeeds()}).sync() {
+            window?.reload()
+        }
+    }
+
     fun initToolbar() {
         toolbarItem(name = "reload", icon = "view-refresh") { event ->
-            val window = event.windowData as MainWindow
-            SyncJob({ Database.getAllFeeds()}).sync() {
-                window.sourceList.invalidateCache()
-                window.sourceList.reloadStatus()
-                window.feedList.reloadCurrentFeed()
-            }
+            syncAll()
         }
 
         toolbarAppMenu {
             menuItem(label = "Update All") {
-
+                syncAll()
+            }
+            separator()
+            menuItem(label = "Mark Current Feed as Read") {
+                if(window?.feedList?.currentFeed != null) {
+                    window?.feedList?.currentFeed?.unreadItemsCount = 0
+                    window?.feedList?.currentFeed?.items?.forEach { item ->
+                        item.isRead = true
+                    }
+                    window?.feedList?.items?.update()
+                    window?.updateCurrentFeedState()
+                    GlobalScope.launch(Dispatchers.IO) {
+                        Database.updateFeedReadState(window?.feedList?.currentFeed!!, true)
+                    }
+                }
+            }
+            menuItem(label = "Mark All as Read") {
+                GlobalScope.launch(Dispatchers.IO) {
+                    Database.updateAllItems(true)
+                    GlobalScope.launch(ToolkitDispatcher) {
+                        window?.reload()
+                    }
+                }
             }
             separator()
             menuItem(label = "Settings") {
index ae30a011ef5a1ade77db8f1a33f410f73888c42b..98f7560e564750ecd34b7b6e287736c182ddf9a9 100644 (file)
@@ -404,6 +404,17 @@ object Database {
         }
     }
 
+    public fun updateAllItems(read: Boolean) {
+        dataSource.connection.use { conn ->
+            conn.prepareStatement("""
+                update items set is_read = ?
+            """.trimIndent()).use { stmt ->
+                stmt.setBoolean(1, read)
+                stmt.execute()
+            }
+        }
+    }
+
     public fun getUpdateWaitTime(defaultUpdateInterval: Int) : Int {
         var seconds = 0
         dataSource.connection.use { conn ->
index e1703c4b991ac19691998d15fcf2aa792ceb6ee6..d850051eea6bc7f995b0f235e2b01331e6a8dfe8 100644 (file)
@@ -24,6 +24,8 @@ class MainWindow() {
     val dateTodayFormatter = DateTimeFormatter.ofPattern(App.settings.dateFormatToday).withZone(ZoneId.systemDefault())
 
     var newFeedPrevGroup = 0
+    var currentSublistIndex = -1
+    var currentFeedIndex = -1
 
     init {
         window = sidebarWindow("RSS Reader") {
@@ -34,6 +36,8 @@ class MainWindow() {
                         varname = "feeds",
                         onActivate = { event ->
                             val evt = event.subListEventData
+                            currentSublistIndex = evt.sublistIndex
+                            currentFeedIndex = evt.rowIndex
                             try {
                                 val feed = sourceList.groups[evt.sublistIndex].feeds[evt.rowIndex]
                                 feed?.let {
@@ -42,7 +46,7 @@ class MainWindow() {
                                     // mode 1: mark all items as read when opening the feed
                                     // update the sourcelist to remove the unread counter badge from this feed
                                     if(feed.itemStateMode == 1) {
-                                        sourceList.groups[evt.sublistIndex].feeds.update(evt.rowIndex)
+                                        updateCurrentFeedState()
                                     }
                                 }
                             } catch (e: Exception) {
@@ -167,6 +171,18 @@ class MainWindow() {
         window.ui.attach(feedList)
     }
 
+    fun reload() {
+        sourceList.invalidateCache()
+        sourceList.reloadStatus()
+        feedList.reloadCurrentFeed()
+    }
+
+    fun updateCurrentFeedState() {
+        if(currentFeedIndex >= 0 && currentSublistIndex >= 0) {
+            sourceList.groups[currentFeedIndex].feeds.update(currentSublistIndex)
+        }
+    }
+
     private fun createFeedDialog() {
         var groups: UiList<FeedGroup>? = null
         var name: UiString? = null