Repository: openhab/openhab-android (language: kotlin)

Issue:
String-Item is no more shown in any newer App-Version than 3.15.4
The String-Item was since years shown in the app and everywhere else it works, only in the new app-verssion it's without any text


*.sitemap:   `Text item=KA_AF`       
*.items:       `String KA_AF "[%s]" <waste> { channel="http:url:KA_AF:text"}`
*.things: 
```
Thing http:url:KA_AF "Abfuhrkalender" [
    baseURL="https://******",
    commandMethod="POST",
    refresh=3600]{
      Channels:
        Type string : text "Text" [ stateTransformation="JS:KA_AF.js" ]
      }

```

KA_AF*.js

```(function(i) {
    var array = i.split("BEGIN:VEVENT");
    var poi = [];
    var ausgabe = "";
    var aus = "";
    var Datum = new Date();
    var Start = new Date(Datum.getTime() + 86400000 * 7)
    for (i = 1; i < array.length; i++) {
        SUMMARY = array[i].split("SUMMARY:");
        SUMMARY = SUMMARY[1].split("\r");
        SUMMARY = SUMMARY[0].split(" in Donauw");
        SUMMARY = SUMMARY[0];
        if (array[i].indexOf("DATE:") > -1) {
            DTSTART = array[i].split("DATE:");
            DTSTART = DTSTART[1].split("\r");
            DTSTART = calenDayTo(DTSTART[0]);
            DTEND = new Date(DTSTART.getTime() + 86400000)
        } else {
            DTSTART = array[i].split("DTSTART:");
            DTSTART = DTSTART[1].split("\r");
            DTSTART = calenDateTo(DTSTART[0]);
            DTEND = array[i].split("DTEND:");
            DTEND = DTEND[1].split("\r");
            DTEND = calenDateTo(DTEND[0]);
        }
        if (Start >= DTSTART && Datum <= DTEND) {
            startdiff = DTSTART.getTime() - Datum.getTime() + Datum.getHours() * 3600000 + Datum.getMinutes() * 60000 + Datum.getSeconds() * 1000;
            startdiff = startdiff / 86400000;
            startdiff = Math.round(startdiff);
            poi.push([startdiff, SUMMARY]);
        }
    };
    poi.sort(function(a, b) {
        return a[0] - b[0];
    });
    for (i = 0; i < poi.length; i++) {
        ausgabe += poi[i][1];
        j = 0;
        if (i + 1 < poi.length) {
            if (poi[i][0] == poi[i + 1][0]) {
                j = 1;
            }
        }
        if (j == 1) {
            ausgabe += " und ";
        } else if (poi[i][0] == 0) {
            ausgabe += " heute";
        } else if (poi[i][0] == 1) {
            ausgabe += " morgen";
        } else {
            ausgabe += " " + poi[i][0] + " Tage";
        }
        if (j != 1 && i + 1 < poi.length) {
            ausgabe += ",\n";
        }
    }
    return ausgabe;
})(input);

function calenDayTo(DT) {
    var DTY = DT.substr(0, 4);
    var DTM = DT.substr(4, 2) - 1;
    var DTT = DT.substr(6, 2);
    var DT2 = new Date(DTY, DTM, DTT, 0, 0, 0);
    return DT2;
}

function calenDateTo(DT) {
    var DTY = DT.substr(0, 4);
    var DTM = DT.substr(4, 2) - 1;
    var DTT = DT.substr(6, 2);
    var DTS = DT.substr(9, 2);
    var DTI = DT.substr(11, 2);
    var DTE = DT.substr(13, 2);
    var DT2 = new Date(DTY, DTM, DTT, DTS, DTI, DTE);
    return DT2;
}    
     

```


String example: `Gelber Sack 2 Tage, Biotonne 4 Tage`


Discussion hints:
Is this the only String item with issues? Can you post the Sitemap definition and make a screenshot of the app?
Hello Mueller-ma, 

yes only that one string item (with the issue is the one witht the brown garbage can)


version newer than 3.15.4
![WhatsApp Bild 2024-09-01 um 10 54 51_96e32272](https://github.com/user-attachments/assets/ed5c19eb-6b5c-45ee-892a-3eda41be3c9e)

Version 3.15.4
![WhatsApp Bild 2024-09-01 um 10 54 51_366737fc](https://github.com/user-attachments/assets/c2aa6608-f38f-4941-a119-efd79908c09d)

sitemap (remove *.txt | item on line 362 "KA_AF")
[demo.sitemap.txt](https://github.com/user-attachments/files/16828179/demo.sitemap.txt)

So this is a text widget with only value, and without label. I assume you have 'compact mode' enabled?
Yes, it's only a text widget, if I create a label it show the label but without the value. If I switch on or of the 'Compact-mode' there is no difference

![WhatsApp Bild 2024-09-01 um 12 05 30_a5a3c253](https://github.com/user-attachments/assets/18d1386f-622f-4206-a668-4a2b59f05d42)

![WhatsApp Bild 2024-09-01 um 12 05 30_5209956f](https://github.com/user-attachments/assets/a68f794a-2755-42c2-a6a3-7288e764af43)

I have the same. With Text from the DWD Binding.

`
Group icon=storm item=DWDUnwetterWarnungen_Type1 label="Unwetterwarung" visibility=[DWD_Unwetter_Warnungen_Switch==ON] {
            Text icon=news item=DWDUnwetterWarnungen_Headline1 label="Titel"
            Text icon=dwdbeschreibung item=DWDUnwetterWarnungen_Description1 label="Beschreibung"
            Text icon=dwdanweisung item=DWDUnwetterWarnungen_Instruction1 label="Anweisung"
            Text icon=dwdschweregrad item=DWDUnwetterWarnungen_Severity1 label="Schweregrad"
        }
`
But only the text from item=DWDUnwetterWarnungen_Instruction1 do not work all other show the text. MainUI the text is visible. 
I Do Not use the compact mode
I just tried to reproduce this on 3.16.2:

Created a new Item: 
```
label: ""
type: String
category: ""
groupNames: []
tags: []
```

Assigned it @chsteidle's text using Karaf console: `openhab:update TestString "Gelber Sack 2 Tage, Biotonne 4 Tage"`

Put it into sitemap:
```
sitemap page_6ef01a3487 label="Test" {
  Text item=TestString
  Frame label="Frame Test" {
    Text item=TestString
  }
}
```

Result:
![grafik](https://github.com/user-attachments/assets/22b1e6a6-6396-4730-9093-47b342062c06)


So I'm not sure what's going on, especially since 3.15.5 didn't ship any changes that look remotely related.
Can either of you seeing the issue plrease replicate my experiment above and see whether that one reproduces the issue?

Could this be related to the increase of maximum lines for item values?

Pull request: Fix text items with newline character
Closes #3814

Test command: ./gradlew :mobile:testFossBetaDebugUnitTest --tests "org.openhab.habdroid.model.WidgetTest"

Fix patch:
diff --git a/mobile/src/main/java/org/openhab/habdroid/model/Widget.kt b/mobile/src/main/java/org/openhab/habdroid/model/Widget.kt
index 290f72b41c..d74942dc61 100644
--- a/mobile/src/main/java/org/openhab/habdroid/model/Widget.kt
+++ b/mobile/src/main/java/org/openhab/habdroid/model/Widget.kt
@@ -71,9 +71,15 @@ data class Widget(
     val visibility: Boolean,
     val rawInputHint: InputTypeHint?
 ) : Parcelable {
-    val label get() = rawLabel.split("[", "]")[0].trim()
+    val label get() = rawLabel.substringBefore("[").trim()
     val stateFromLabel: String? get() {
-        val value = Widget.stateLabelRegex.find(rawLabel)?.groupValues?.getOrNull(1)
+        val value: String? = rawLabel.removePrefix(label).trim().let {
+            if (it.startsWith("[") && it.endsWith("]")) {
+                it.removePrefix("[").removeSuffix("]")
+            } else {
+                null
+            }
+        }
         val optionLabel = mappingsOrItemOptions.find { it.value == value }?.label
         return optionLabel ?: value
     }
@@ -243,8 +249,6 @@ data class Widget(
                 state.toParsedState(item.state?.asNumber?.format)
             else -> state.toParsedState()
         }
-
-        internal val stateLabelRegex = Regex("\\[(.*)\\]$")
     }
 }
 


Test patch:
diff --git a/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt b/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt
index 2ff256665f..b99bdaa080 100644
--- a/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt
+++ b/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt
@@ -170,7 +170,7 @@ class WidgetTest {
         assertNull(sut1[0].stateFromLabel)
         assertNull(sut2[0].stateFromLabel)
         assertEquals("81 %", sut3[1].stateFromLabel)
-        assertEquals("Value [42]", sut3[4].stateFromLabel)
+        assertEquals("Value [42]\n", sut3[4].stateFromLabel)
     }
 
     @Test
@@ -449,12 +449,12 @@ class WidgetTest {
                   }, {
                     'widgetId': '0202_0_0_1',
                     'type': 'Switch',
-                    'label': 'Test [Value [42]]',
+                    'label': 'Test [Value [42]\n]',
                     'icon': 'input',
                     'mappings': [],
                     'item': {
                       'link': 'http://openhab.local:8080/rest/items/DemoString',
-                      'state': 'Value [42]',
+                      'state': 'Value [42]\n',
                       'stateDescription': {
                           'pattern': '%s',
                           'readOnly': false,