From: Olaf Wintermann Date: Sat, 13 Sep 2025 16:45:03 +0000 (+0200) Subject: add menu items for marking feeds as read X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=bc179ae1a92b60fb89bfa0dae4ac4fa000f5b28f;p=rssreader.git add menu items for marking feeds as read --- diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt index d831cd0..2ffa125 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt @@ -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") { 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 ae30a01..98f7560 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -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 -> 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 e1703c4..d850051 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -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? = null var name: UiString? = null