]> uap-core.de Git - rssreader.git/commitdiff
update sourcelist when adding new feeds
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 18 Aug 2025 19:04:43 +0000 (21:04 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 18 Aug 2025 19:04:43 +0000 (21:04 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedGroup.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

index 0899d03bf068fd2d8fb7348eba4f481a1d08e209..8f10f42a15cfb589ce2407c116e6463f18a506c8 100644 (file)
@@ -1,5 +1,6 @@
 package de.unixwork.rssreader
 
+import de.unixwork.ui.Context
 import java.sql.Connection
 import java.sql.DriverManager
 import java.sql.Statement
@@ -79,7 +80,7 @@ object Database {
         }
     }
 
-    public fun getFeedTree() : List<FeedGroup> {
+    public fun getFeedTree(context: Context) : List<FeedGroup> {
         val groups = mutableListOf<FeedGroup>()
 
         connection.createStatement().use { stmt ->
@@ -102,7 +103,7 @@ object Database {
                 val feedName = rs.getString("feed_name")
 
                 if(currentGroup == null || currentGroup.id != groupId) {
-                    currentGroup = FeedGroup(groupId, groupName)
+                    currentGroup = FeedGroup(context, groupId, groupName)
                     groups.add(currentGroup)
                 }
 
@@ -117,7 +118,7 @@ object Database {
         return groups
     }
 
-    public fun newFeedGroup(name: String) : FeedGroup {
+    public fun newFeedGroup(context: Context, name: String) : FeedGroup {
         var groupId = 0
         connection.prepareStatement("""
             insert into groups (pos, name) select coalesce(max(pos), 0)+1, ? from groups
@@ -132,7 +133,7 @@ object Database {
                 }
             }
         }
-        return FeedGroup(groupId, name)
+        return FeedGroup(context, groupId, name)
     }
 
     public fun newFeeds(
@@ -141,7 +142,7 @@ object Database {
         uris: Collection<String>,
         user: String? = null,
         password: String? = null,
-        cert: String? = null)
+        cert: String? = null) : FeedCollection
     {
         var feedcollectionId = -1
         connection.prepareStatement("""
@@ -159,6 +160,8 @@ object Database {
             }
         }
 
+        var feedCol = FeedCollection(feedcollectionId, name)
+
         uris.forEach { uri ->
             connection.prepareStatement("""
                 insert into feeds (feedcollection_id, url, auth_user, auth_password, certpath) values
@@ -173,5 +176,8 @@ object Database {
                 stmt.execute()
             }
         }
+        parent.feeds.add(feedCol)
+        parent.feeds.update()
+        return feedCol
     }
 }
index 13762614d718c9159d5c0ceb068075106bc68f2d..81ea4ade75416e00e4c19d424d0c9f619271d87c 100644 (file)
@@ -2,8 +2,9 @@ package de.unixwork.rssreader
 
 import de.unixwork.ui.Document
 
-class FeedCollection(id: Int, name: String) : Document() {
+class FeedCollection(id: Int, name: String)  {
     val id = id
     val name = name
-    val items = list<Item>("items")
+    val items = mutableListOf<Item>()
+    var itemsLoaded = false
 }
\ No newline at end of file
index 7ed60629909d579840543b5e4603c0d20fef346d..f9294fb047b3a2cf7357b62766e12d0c68f8a211 100644 (file)
@@ -1,8 +1,9 @@
 package de.unixwork.rssreader
 
-class FeedGroup(id: Int, name: String) {
+import de.unixwork.ui.Context
+
+class FeedGroup(context: Context, id: Int, name: String) {
     val id = id
     val name: String = name
-
-    val feeds = mutableListOf<FeedCollection>()
+    val feeds = context.list<FeedCollection>()
 }
\ No newline at end of file
index 43fc90108f93a8616a21f7d69f74b4df2e00710b..1d21ba4559fc6f94e8ee4cf0c36982f727c02754 100644 (file)
@@ -10,7 +10,7 @@ class FeedSourceList : Document() {
     init {
         val db = Database
 
-        groups = db.getFeedTree()
+        groups = db.getFeedTree(this)
         groups.forEach {
             val sublist = SubList<FeedCollection>()
             sublist.header = it.name
index a827416dc7e2a0f669c19247e2b43afd66cba2fd..9686222b8483c73c18e237e730df1087277f2fdd 100644 (file)
@@ -73,7 +73,8 @@ class MainWindow {
                     val uris = urlStr.split("\n").map { it.trim() }.filter { it.isNotBlank() }
                     println("groupSel: ${groups?.selectedIndex}, feedName: $feedName, urlStr: $urlStr")
                     parent?.let {
-                        Database.newFeeds(it, feedName, uris, user.toString(), password.toString(), cert.toString())
+                        val feedCol = Database.newFeeds(it, feedName, uris, user.toString(), password.toString(), cert.toString())
+                        parent.feeds.add(feedCol)
                     }
                 }
                 ev.`object`.close()
@@ -144,7 +145,7 @@ class MainWindow {
                 if(ev.intValue == 1) {
                     val nameStr = name.toString()
                     if(!nameStr.isBlank()) {
-                        Database.newFeedGroup(nameStr)
+                        Database.newFeedGroup(sourceList,nameStr)
                     } else {
                         println("name is null or blank")
                         return@dialogWindow