]> uap-core.de Git - rssreader.git/commitdiff
hide author/category labels if not needed
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 26 Sep 2025 16:40:38 +0000 (18:40 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 26 Sep 2025 16:40:38 +0000 (18:40 +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/UiWidget.java

index 770e5849ec1cf7adcaf13235166d13f58a49010b..e9bc48f71203e2034cad2de76251bbd1c4e219b2 100644 (file)
@@ -8,7 +8,9 @@ import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.IO
 import kotlinx.coroutines.launch
 
-class FeedList : Document() {
+class FeedList(window: MainWindow) : Document() {
+    val window = window
+
     val items = list<Item>("items")
     val feedName = string("feedname")
     val author = string("author")
@@ -74,9 +76,20 @@ class FeedList : Document() {
 
     fun selectItem(item: Item) {
         feedName.setString(item.feedName)
-        author.setString(item.author)
+        if(!item.author.isNullOrEmpty()) {
+            author.setString(item.author)
+            window.window.ui.setState(MainWindow.ITEM_HAS_AUTHOR)
+        } else {
+            window.window.ui.unsetState(MainWindow.ITEM_HAS_AUTHOR)
+        }
         link.set(item.link, item.link)
         category.setString(item.category ?: "")
+        if(!item.category.isNullOrEmpty()) {
+            category.setString(item.category)
+            window.window.ui.setState(MainWindow.ITEM_HAS_CATEGORY)
+        } else {
+            window.window.ui.unsetState(MainWindow.ITEM_HAS_CATEGORY)
+        }
 
         var mimeType: String? = null
         var content: String? = null
index e1c7d3468d4a7df0862cb436a57c549dfa701fdf..af98dee73bf11626eb2d5e6410fd3fb825f30ed3 100644 (file)
@@ -18,9 +18,14 @@ import java.time.ZoneId
 import java.time.format.DateTimeFormatter
 
 class MainWindow() {
+    companion object {
+        const val ITEM_HAS_AUTHOR = 1000
+        const val ITEM_HAS_CATEGORY = 1001
+    }
+
     val window : Toplevel
     val sourceList = FeedSourceList()
-    val feedList = FeedList()
+    val feedList = FeedList(this)
 
     val dateFormatter = DateTimeFormatter.ofPattern(App.settings.dateFormat).withZone(ZoneId.systemDefault())
     val dateTodayFormatter = DateTimeFormatter.ofPattern(App.settings.dateFormatToday).withZone(ZoneId.systemDefault())
@@ -146,16 +151,20 @@ class MainWindow() {
                                 llabel(varname = "feedname", hexpand = true)
                             }
                             row {
-                                rlabel("Author:", hfill = true)
-                                llabel(varname = "author")
+                                val w1 = rlabel("Author:", hfill = true)
+                                val w2 = llabel(varname = "author")
+                                w1.setVisibilityStates(ITEM_HAS_AUTHOR)
+                                w2.setVisibilityStates(ITEM_HAS_AUTHOR)
                             }
                             row {
                                 rlabel("Link:", hfill = true)
                                 linkbutton(varname = "link", styleClass = "ui-nopadding");
                             }
                             row {
-                                rlabel("Category: ", hfill = true)
-                                llabel(varname = "category")
+                                val w1 = rlabel("Category: ", hfill = true)
+                                val w2 = llabel(varname = "category")
+                                w1.setVisibilityStates(ITEM_HAS_CATEGORY)
+                                w2.setVisibilityStates(ITEM_HAS_CATEGORY)
                             }
 
                             row {
index f97385e15ecb7fb09e0c01f9b2ad2e45fae04bcc..e956280246c91eef5d7cb914179f4e84866cece3 100644 (file)
@@ -49,4 +49,15 @@ public class UiWidget {
             throw new RuntimeException(e);
         }
     }
+
+    public void setVisibilityStates(int... states) {
+        ToolkitFuncs ui = ToolkitFuncs.getInstance();
+        try (Arena arena = Arena.ofConfined()) {
+            MemorySegment statesArray = arena.allocate(ValueLayout.JAVA_INT, states.length);
+            MemorySegment.copy(states, 0, statesArray, ValueLayout.JAVA_INT, 0, states.length);
+            ui.set_widget_visibility_states.invoke(obj.getCtx(), widget, statesArray, states.length);
+        } catch (Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
 }