]> uap-core.de Git - rssreader.git/commitdiff
implement sourcelist move up/down context menu items
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 6 Nov 2025 18:11:19 +0000 (19:11 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 6 Nov 2025 18:11:19 +0000 (19:11 +0100)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
ui-java/src/main/java/de/unixwork/ui/UiSourceList.java

index c6eab9464381b574393691d1ebc74db61caa4098..a1747e1f366acd65cac5f2c535da1bd01d21a5f9 100644 (file)
@@ -164,6 +164,26 @@ object Database {
         return groups
     }
 
+    public fun swapFeedCollectionPos(feed1: FeedCollection, feed2: FeedCollection) {
+        val sql = """
+        update feedcollections set
+        pos = case
+                when feedcollection_id = ?1 then (SELECT pos from feedcollections where feedcollection_id = ?2)
+                when feedcollection_id = ?2 then (SELECT pos from feedcollections where feedcollection_id = ?1)
+                else pos
+              end
+        where feedcollection_id in (?1, ?2)
+        """.trimIndent()
+
+        dataSource.connection.use { conn ->
+            conn.prepareStatement(sql).use { stmt ->
+                stmt.setInt(1, feed1.id)
+                stmt.setInt(2, feed2.id)
+                stmt.execute()
+            }
+        }
+    }
+
     public fun newFeedGroup(context: Context, name: String) : FeedGroup {
         var groupId = 0
         dataSource.connection.use { conn ->
index 7c7f23936c880abcc487163a48ec0d18778de9d7..ed1821681952557931ec0a2523108c27e20f5975 100644 (file)
@@ -31,6 +31,28 @@ class FeedSourceList : Document() {
         groups.add(group)
     }
 
+    fun swapFeedCollections(group: Int, feed1: Int, feed2: Int) {
+        if(group < 0 || group >= groups.size) {
+            return
+        }
+        val gr = groups[group]
+        if(feed1 < 0 || feed1 >= gr.feeds.size) {
+            return
+        }
+        if(feed2 < 0 || feed2 >= gr.feeds.size) {
+            return
+        }
+
+        // swap feeds in the lists and in the database
+        val f1 = gr.feeds[feed1]
+        val f2 = gr.feeds[feed2]
+        gr.feeds[feed1] = f2
+        gr.feeds[feed2] = f1
+        gr.feeds.update()
+
+        Database.swapFeedCollectionPos(f1, f2)
+    }
+
     fun invalidateCache() {
         groups.forEach {
             it.feeds.forEach { feed ->
index 32c821bffa7cc4d82039631d2422a85bbc49d8f4..b0b77245fb6680e21e457886f7859d9e62abd71c 100644 (file)
@@ -76,11 +76,14 @@ class MainWindow() {
             contextMenuReset()
         }
         separator()
-        menuItem("Move Up") {
-
+        menuItem("Move Up") { event ->
+            val evt = event.subListEventData
+            sourceList.swapFeedCollections(evt.sublistIndex, evt.rowIndex, evt.rowIndex-1)
             contextMenuReset()
         }
-        menuItem("Move Down") {
+        menuItem("Move Down") { event ->
+            val evt = event.subListEventData
+            sourceList.swapFeedCollections(evt.sublistIndex, evt.rowIndex, evt.rowIndex+1)
             contextMenuReset()
         }
         menuItem("Delete") {
index e5b714d7a1bd7bf87776ca150548fa7373f56e32..9f0286898066a70dfc902660dd1058d43cf9a358 100644 (file)
@@ -52,6 +52,10 @@ public class UiSourceList {
         }
     }
 
+    public SubList get(int index) {
+        return list.get(index);
+    }
+
     public void update() {
         ListFuncs ui = ListFuncs.getInstance();
         try {