Skip to content

Commit

Permalink
Format screensaver item as html (#3853)
Browse files Browse the repository at this point in the history
Replace newline characters with `<br>` to keep the previous behavior.

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma authored Jan 31, 2025
1 parent 2eebfad commit 2f90b72
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mobile/src/main/java/org/openhab/habdroid/ui/DayDream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package org.openhab.habdroid.ui
import android.animation.ObjectAnimator
import android.content.res.Configuration
import android.graphics.Rect
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.service.dreams.DreamService
import android.text.Html
import android.text.format.DateFormat
import android.util.Log
import android.view.View
Expand Down Expand Up @@ -92,21 +94,29 @@ class DayDream : DreamService(), CoroutineScope {
val connection = ConnectionFactory.primaryUsableConnection?.connection ?: return

moveText()
textView.text = try {
val initialText = try {
ItemClient.loadItem(connection, item)?.state?.asString.orEmpty()
} catch (e: HttpClient.HttpException) {
getString(R.string.screensaver_error_loading_item, item)
}
moveTextIfRequired()
setText(initialText)

ItemClient.listenForItemChange(this, connection, item) { _, payload ->
val state = payload.getString("value")
Log.d(TAG, "Got state by event: $state")
textView.text = state
moveTextIfRequired()
setText(state)
}
}

private fun setText(text: String) {
textView.text = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(text.replace("\n", "<br>"), Html.FROM_HTML_MODE_COMPACT)
} else {
text
}
moveTextIfRequired()
}

private fun moveText() {
moveTextJob?.cancel()
wrapper.fadeOut()
Expand Down

0 comments on commit 2f90b72

Please sign in to comment.