From: Olaf Wintermann Date: Thu, 6 Nov 2025 18:11:19 +0000 (+0100) Subject: implement sourcelist move up/down context menu items X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=e69cfd48c7c20958a006c2d911a2c598931e6dca;p=rssreader.git implement sourcelist move up/down context menu items --- 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 c6eab94..a1747e1 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -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 -> diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt index 7c7f239..ed18216 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt @@ -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 -> 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 32c821b..b0b7724 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -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") { diff --git a/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java b/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java index e5b714d..9f02868 100644 --- a/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java +++ b/ui-java/src/main/java/de/unixwork/ui/UiSourceList.java @@ -52,6 +52,10 @@ public class UiSourceList { } } + public SubList get(int index) { + return list.get(index); + } + public void update() { ListFuncs ui = ListFuncs.getInstance(); try {