]> uap-core.de Git - rssreader.git/commitdiff
reload feed after sync
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 27 Aug 2025 17:31:26 +0000 (19:31 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 27 Aug 2025 17:31:26 +0000 (19:31 +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/FeedList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt

index a1c52bada07bd34ea2b4f42f48b3987969520bd1..9a68cba41dd5e1eb5d1f659a3dd2cefb65d19be8 100644 (file)
@@ -12,8 +12,12 @@ class App : Application {
     }
 
     fun initToolbar() {
-        toolbarItem(name = "reload", icon = "view-refresh") {
-            SyncJob().sync()
+        toolbarItem(name = "reload", icon = "view-refresh") { event ->
+            val window = event.windowData as MainWindow
+            SyncJob().sync() {
+                window.sourceList.invalidateCache()
+                window.feedList.reloadCurrentFeed()
+            }
         }
 
         addToolbarDefault("reload", ToolbarPosition.LEFT)
index 77125e9b2143d7c1daf15a31359ed4c40a7dfecf..fb9c3a30bd871f31cbb0d550e80fa7045cae9168 100644 (file)
@@ -249,28 +249,26 @@ object Database {
     }
 
     public fun addItems(items: Collection<Item>) {
-        GlobalScope.launch(Dispatchers.IO) {
-            dataSource.connection.use { conn ->
-                conn.prepareStatement("""
+        dataSource.connection.use { conn ->
+            conn.prepareStatement("""
                     insert into items (feed_id, title, link, description, author, pub_date, guid, contentText, contentHTML)
                     select ?, ?, ?, ?, ?, ?, ?, ?, ? 
                     where ? not in (select guid from items) 
                 """.trimIndent()).use { stmt ->
-                    items.forEach { item ->
-                        stmt.setInt(1, item.feedId)
-                        stmt.setString(2, item.title)
-                        stmt.setString(3, item.link)
-                        stmt.setString(4, item.description)
-                        stmt.setString(5, item.author)
-                        stmt.setTimestamp(6, item.pubDate?.let { java.sql.Timestamp.from(it.toInstant()) })
-                        stmt.setString(7, item.guid)
-                        stmt.setString(8, item.contentText)
-                        stmt.setString(9, item.contentHtml)
-                        stmt.setString(10, item.guid)
-                        stmt.addBatch()
-                    }
-                    stmt.executeBatch()
+                items.forEach { item ->
+                    stmt.setInt(1, item.feedId)
+                    stmt.setString(2, item.title)
+                    stmt.setString(3, item.link)
+                    stmt.setString(4, item.description)
+                    stmt.setString(5, item.author)
+                    stmt.setTimestamp(6, item.pubDate?.let { java.sql.Timestamp.from(it.toInstant()) })
+                    stmt.setString(7, item.guid)
+                    stmt.setString(8, item.contentText)
+                    stmt.setString(9, item.contentHtml)
+                    stmt.setString(10, item.guid)
+                    stmt.addBatch()
                 }
+                stmt.executeBatch()
             }
         }
     }
index af1644e3bf75287dfe3782518d61e381114971ca..211ab59a29f06274e2f2c3bc6743fd81501db8ca 100644 (file)
@@ -11,16 +11,23 @@ class FeedList : Document() {
     val link = UiLinkData(linkstr)
     val webview = webview("webview")
 
+    var currentFeed: FeedCollection? = null
+
     fun loadFeed(feed: FeedCollection) {
         items.clear()
         if(!feed.itemsLoaded) {
-            feed.items = Database.getItems(feed, 100)
+            feed.items = Database.getItems(feed, 10000)
             feed.itemsLoaded = true
         }
         feed.items.forEach { item ->
             items.add(item)
         }
         items.update()
+        currentFeed = feed
+    }
+
+    fun reloadCurrentFeed() {
+        currentFeed?.let { loadFeed(it) }
     }
 
     fun selectItem(item: Item) {
index e19d2918dd266690f2f6099f130a46a002d943f1..36c68d97aaa52f251549e2fc35c81b37372017a5 100644 (file)
@@ -18,4 +18,12 @@ class FeedSourceList : Document() {
             feeds.add(sublist)
         }
     }
+
+    fun invalidateCache() {
+        groups.forEach {
+            it.feeds.forEach { feed ->
+                feed.itemsLoaded = false
+            }
+        }
+    }
 }
\ No newline at end of file
index 83209e0b21ef29cbab5702ac3fdbbaab68debfee..fc7726faf9945b715a058e397dd449bd6d47aaa2 100644 (file)
@@ -99,6 +99,8 @@ class MainWindow {
 
         }
 
+        window.ui.windowData = this
+
         window.ui.attach(sourceList)
         window.ui.attach(feedList)
     }
index f4b5d597534de6d819647e28d5c02cd8b7b62edb..2281450d100d952ef6604ea5bf40a9a3bfe07f4a 100644 (file)
@@ -2,6 +2,7 @@ package de.unixwork.rssreader
 
 import com.rometools.rome.io.SyndFeedInput
 import com.rometools.rome.io.XmlReader
+import de.unixwork.ui.kotlin.ToolkitDispatcher
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.IO
@@ -15,12 +16,13 @@ import java.net.http.HttpResponse
 
 class SyncJob {
     val feeds: List<Feed>
+    var completionContext = ToolkitDispatcher
 
     init {
         feeds = Database.getAllFeeds()
     }
 
-    fun sync() {
+    fun sync(completion: () -> Unit = {}) {
         GlobalScope.launch(Dispatchers.IO) {
             val client = HttpClient.newBuilder().build()
             val jobs = feeds.map { feed ->
@@ -73,6 +75,10 @@ class SyncJob {
                 }
             }
             jobs.awaitAll()
+
+            GlobalScope.launch(completionContext) {
+                completion()
+            }
         }
     }
 }
\ No newline at end of file