]> uap-core.de Git - rssreader.git/commitdiff
simplify code that determines an items content string and mimetype
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 13 Oct 2025 09:03:35 +0000 (11:03 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 13 Oct 2025 09:03:35 +0000 (11:03 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Content.kt [new file with mode: 0644]
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Item.kt

diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Content.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Content.kt
new file mode 100644 (file)
index 0000000..5503e2f
--- /dev/null
@@ -0,0 +1,3 @@
+package de.unixwork.rssreader
+
+data class Content(val text: String, val type: String)
index a3256454193141afdc6e61a98f36b02cc5e33d19..fa898880a321ff93bc4738ec0bc6a6f9f38e40c5 100644 (file)
@@ -102,29 +102,13 @@ class FeedList(window: MainWindow) : Document() {
             window.window.ui.unsetState(MainWindow.ITEM_HAS_CATEGORY)
         }
 
-        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"
-        }
-
         if(item.isBookmark) {
             starred.setIntValue(1)
         } else {
             starred.setIntValue(0)
         }
-
-        webview.loadContent(item.link, content, mimeType, "utf-8")
+        val content = item.getContent()
+        webview.loadContent(item.link, content.text, content.type, "utf-8")
 
         tabview.setIntValue(1)
         preview.setIntValue(0) // reset preview toggle button
@@ -143,23 +127,8 @@ class FeedList(window: MainWindow) : Document() {
     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")
+                val content = item.getContent()
+                webview.loadContent(item.link, content.text, content.type, "utf-8")
             } else {
                 webview.loadUrl(item.link)
             }
index 15e90edb3b52b5c2b36b172db9b03965473f3358..e4d42280f668b5b0dc8382c888b340c02d36e426 100644 (file)
@@ -21,4 +21,17 @@ class Item(id: Int) {
 
     var feedName: String? = null
     var feedUrl: String? = null
+
+    fun getContent(): Content {
+        contentHtml?.let {
+            return Content(it, "text/html")
+        }
+        contentText?.let {
+            return Content(it, "text/plain")
+        }
+        description?.let {
+            return Content(it, "text/html")
+        }
+        return Content("", "text/plain")
+    }
 }
\ No newline at end of file