]> uap-core.de Git - rssreader.git/commitdiff
add star toggle button
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 4 Oct 2025 12:06:19 +0000 (14:06 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 4 Oct 2025 12:06:19 +0000 (14:06 +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
ui-java/src/main/java/de/unixwork/ui/Toolbar.java
ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Menu.kt

index 9b84c2406b597e974242f3c6d3b738d7046d58de..11bbf6a800dbc7a1c2955d81e5c0d6b5a05119be 100644 (file)
@@ -9,6 +9,7 @@ import de.unixwork.ui.kotlin.ToolkitDispatcher
 import de.unixwork.ui.kotlin.toolbarItem
 import de.unixwork.ui.kotlin.addToolbarDefault
 import de.unixwork.ui.kotlin.toolbarAppMenu
+import de.unixwork.ui.kotlin.toolbarToggleItem
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.IO
@@ -41,11 +42,23 @@ object App : Application {
         }
     }
 
+    fun setBookmark(starred: Boolean) {
+        window?.feedList?.currentItem?.let {
+            GlobalScope.launch(Dispatchers.IO) {
+                Database.setBookmark(it, starred)
+            }
+        }
+    }
+
     fun initToolbar() {
         toolbarItem(name = "reloadFeed", icon = "view-refresh") { event ->
             syncCurrent()
         }
 
+        toolbarToggleItem(name = "starred", icon = "starred", varname = "starred") { event ->
+            setBookmark(event.intValue == 1)
+        }
+
         toolbarAppMenu {
             menuItem(label = "Update All") {
                 syncAll()
@@ -85,6 +98,7 @@ object App : Application {
         }
 
         addToolbarDefault("reloadFeed", ToolbarPosition.LEFT)
+        addToolbarDefault("starred", ToolbarPosition.RIGHTPANEL_LEFT)
     }
 
     override fun startup() {
index ddf4f409701783ccfb8e72c33443ae9ac8053698..5099931f31be5dc2c7b0704d0a441608153d6d1f 100644 (file)
@@ -490,4 +490,17 @@ object Database {
             }
         }
     }
+
+    public fun setBookmark(item: Item, bookmark: Boolean) {
+        dataSource.connection.use { conn ->
+            conn.prepareStatement("""
+                update items set is_bookmarked = ? where item_id = ?
+            """.trimIndent()).use { stmt ->
+                stmt.setBoolean(1, bookmark)
+                stmt.setInt(2, item.id)
+                stmt.execute()
+                item.isBookmark = bookmark
+            }
+        }
+    }
 }
index e9bc48f71203e2034cad2de76251bbd1c4e219b2..a0430b3f9be428a66a25d8d6f2b7c5d84ce0e47c 100644 (file)
@@ -19,9 +19,11 @@ class FeedList(window: MainWindow) : Document() {
     val category = string("category")
     val webview = webview("webview")
     val tabview = integer("tabview")
+    val starred = integer("starred")
 
     // Feed that is currently shown
     var currentFeed: FeedCollection? = null
+    var currentItem: Item? = null
     // Currently requested feed
     var showFeed: FeedCollection? = null
 
@@ -75,6 +77,8 @@ class FeedList(window: MainWindow) : Document() {
     }
 
     fun selectItem(item: Item) {
+        currentItem = item
+
         feedName.setString(item.feedName)
         if(!item.author.isNullOrEmpty()) {
             author.setString(item.author)
@@ -107,6 +111,12 @@ class FeedList(window: MainWindow) : Document() {
             mimeType = "text/plain"
         }
 
+        if(item.isBookmark) {
+            starred.setIntValue(1)
+        } else {
+            starred.setIntValue(0)
+        }
+
         webview.loadContent(item.link, content, mimeType, "utf-8")
 
         tabview.setIntValue(1)
index 936ddcf8e95aea121097e1fb0610e51ead6d1cd0..d8cd930211947ccc3012c179e086ca0c34831fec 100644 (file)
@@ -42,6 +42,40 @@ public class Toolbar {
         }
     }
 
+    public static void toggleItem(String name, String label, String icon, String varname, EventHandler onChange) {
+        MenuFuncs ui = MenuFuncs.getInstance();
+        ArgFuncs a = ArgFuncs.getInstance();
+        Toolkit toolkit = Toolkit.getInstance();
+        Arena arena = toolkit.getStaticArena();
+        try {
+            MemorySegment args = (MemorySegment) a.toolbar_toggleitem_args_new.invoke();
+            if(label != null) {
+                MemorySegment cstr = arena.allocateFrom(label);
+                a.toolbar_toggleitem_args_set_label.invoke(args, cstr);
+            }
+            if(icon != null) {
+                MemorySegment cstr = arena.allocateFrom(icon);
+                a.toolbar_toggleitem_args_set_icon.invoke(args, cstr);
+            }
+            if(varname != null) {
+                MemorySegment cstr = arena.allocateFrom(varname);
+                a.toolbar_toggleitem_args_set_varname.invoke(args, cstr);
+            }
+            if(onChange != null) {
+                EventWrapper event = new EventWrapper(onChange);
+
+                // set toolkit args
+                a.toolbar_toggleitem_args_set_onchange.invoke(args, event.getCallback());
+                a.toolbar_toggleitem_args_set_onchangedata.invoke(args, event.getUserData());
+            }
+            MemorySegment itemName = arena.allocateFrom(name);
+            ui.toolbar_toggleitem_create.invoke(itemName, args);
+            a.toolbar_toggleitem_args_free.invoke(args);
+        } catch (Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     public static void menu(String name, String label, String icon, Menu menu) {
         MenuFuncs ui = MenuFuncs.getInstance();
         ArgFuncs a = ArgFuncs.getInstance();
index c03fc4c88d837a47eb59ee16d1aa4eab223240b6..62a58ceb6a36e25cfcac9304ea6bd615e25e0c71 100644 (file)
@@ -49,6 +49,11 @@ fun toolbarItem(name: String, label: String? = null, icon: String? = null, stock
     }
 }
 
+fun toolbarToggleItem(name: String, label: String? = null, icon: String? = null, stockId: String? = null, varname: String? = null, onChange: EventHandler? = null) {
+    // TODO: stockId
+    Toolbar.toggleItem(name, label, icon, varname, onChange)
+}
+
 fun toolbarMenu(name: String?, label: String? = null, icon: String? = null, stockId: String? = null, block: MenuBuilder.() -> Unit) {
     // TODO: stockId
     Toolbar.menu(name, label, icon, menuBuilder(block))