]> uap-core.de Git - rssreader.git/commitdiff
add additional buttons for opening items in the external default browser or internal...
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 12 Oct 2025 07:28:08 +0000 (09:28 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 12 Oct 2025 07:28:08 +0000 (09:28 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
ui-java/src/main/java/de/unixwork/ui/ToggleBuilder.java
ui-java/src/main/java/de/unixwork/ui/UiInteger.java

index a0430b3f9be428a66a25d8d6f2b7c5d84ce0e47c..7efa2936a19955ded485dd093fd8867c4f8461b4 100644 (file)
@@ -7,6 +7,9 @@ import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.IO
 import kotlinx.coroutines.launch
+import java.awt.Desktop
+import java.net.URI
+import java.net.URISyntaxException
 
 class FeedList(window: MainWindow) : Document() {
     val window = window
@@ -15,11 +18,14 @@ class FeedList(window: MainWindow) : Document() {
     val feedName = string("feedname")
     val author = string("author")
     val linkstr = string("link")
+    val linkstr2 = string("link2")
     val link = UiLinkData(linkstr)
+    val link2 = UiLinkData(linkstr2)
     val category = string("category")
     val webview = webview("webview")
     val tabview = integer("tabview")
     val starred = integer("starred")
+    val preview = integer("preview")
 
     // Feed that is currently shown
     var currentFeed: FeedCollection? = null
@@ -87,6 +93,7 @@ class FeedList(window: MainWindow) : Document() {
             window.window.ui.unsetState(MainWindow.ITEM_HAS_AUTHOR)
         }
         link.set(item.link, item.link)
+        link2.set("Browser", item.link)
         category.setString(item.category ?: "")
         if(!item.category.isNullOrEmpty()) {
             category.setString(item.category)
@@ -131,4 +138,30 @@ class FeedList(window: MainWindow) : Document() {
             items.update(items.selectedIndex)
         }
     }
+
+    fun togglePreview() {
+        currentItem?.let { item ->
+            if(preview.intValue() == 0) {
+                // TODO: codedup with selectItem, can we fix this?
+                var mimeType: String? = null
+                var content: String? = null
+                if(item.contentHtml != null) {
+                    content = item.contentHtml
+                    mimeType = "text/html"
+                } else if(item.contentText != null) {
+                    content = item.contentText
+                    mimeType = "text/plain"
+                } else if(item.description != null) {
+                    content = item.description
+                    mimeType = "text/html"
+                } else {
+                    content = ""
+                    mimeType = "text/plain"
+                }
+                webview.loadContent(item.link, content, mimeType, "utf-8")
+            } else {
+                webview.loadUrl(item.link)
+            }
+        }
+    }
 }
\ No newline at end of file
index eb607d04fec4b6d4c84ef2cd58cb7e195823dfe6..152788b4d630f6de852be9f77cd64f410cf8459b 100644 (file)
@@ -1,6 +1,7 @@
 package de.unixwork.rssreader
 
 import de.unixwork.ui.ColumnType
+import de.unixwork.ui.LinkButtonType
 import de.unixwork.ui.SubListItem
 import de.unixwork.ui.TabViewType
 import de.unixwork.ui.TableModel
@@ -159,16 +160,24 @@ class MainWindow() {
                                 w1.setVisibilityStates(ITEM_HAS_AUTHOR)
                                 w2.setVisibilityStates(ITEM_HAS_AUTHOR)
                             }
-                            row {
-                                rlabel("Link:", hfill = true)
-                                linkbutton(varname = "link", styleClass = "ui-nopadding");
-                            }
                             row {
                                 val w1 = rlabel("Category: ", hfill = true)
                                 val w2 = llabel(varname = "category")
                                 w1.setVisibilityStates(ITEM_HAS_CATEGORY)
                                 w2.setVisibilityStates(ITEM_HAS_CATEGORY)
                             }
+                            row {
+                                rlabel("Link:", hfill = true)
+                                linkbutton(varname = "link", styleClass = "ui-nopadding");
+                            }
+                            row {
+                                hbox(spacing = 4, colspan = 2) {
+                                    linkbutton(label = "Browser", varname = "link2", type = LinkButtonType.BUTTON)
+                                    togglebutton (label = "Preview", tooltip = "Open article in the internal webview", varname = "preview") {
+                                        feedList.togglePreview()
+                                    }
+                                }
+                            }
 
                             row {
                                 webview(varname = "webview", hfill = true, vfill = true, hexpand = true, vexpand = true, colspan = 2)
index 8d0bb1c6ef3ebda9df199873e0c84b61da0de029..2c2324d7c4153035b50afb2e92127a36b830f33d 100644 (file)
@@ -230,7 +230,11 @@ public class ToggleBuilder extends AbstractWidgetBuilder {
         }
         
         if(onChange != null) {
-            // TODO
+            EventWrapper event = new EventWrapper(obj, onChange);
+
+            // set toolkit args
+            ui.toggle_args_set_onchange.invoke(args, event.getCallback());
+            ui.toggle_args_set_onchangedata.invoke(args, event.getUserData());
         }
 
         return args;
index c6d5a843cf569cecc43aeee94d438c59f6991c0a..ab688f8fe19c8235660635625e1d41b300c4ec1a 100644 (file)
@@ -21,17 +21,16 @@ public class UiInteger {
         }
     }
 
-    public int intValue() {
+    public long longValue() {
         ToolkitFuncs ui = ToolkitFuncs.getInstance();
         try {
-            Integer value = (Integer) ui.int_get.invoke(valuePtr);
-            return value.intValue();
+            return (long)ui.int_get.invoke(valuePtr);
         } catch (Throwable e) {
             throw new RuntimeException(e);
         }
     }
 
-    public void setIntValue(int value) {
+    public void setLongValue(long value) {
         ToolkitFuncs ui = ToolkitFuncs.getInstance();
         try (Arena arena = Arena.ofConfined()) {
             ui.int_set.invoke(valuePtr, value);
@@ -39,4 +38,12 @@ public class UiInteger {
             throw new RuntimeException(e);
         }
     }
+
+    public int intValue() {
+        return (int) longValue();
+    }
+
+    public void setIntValue(int value) {
+        setLongValue(value);
+    }
 }