mirror of
https://github.com/home-assistant/android
synced 2024-10-07 00:29:32 +00:00
Remove error message on null template (#2735)
* Remove error message on null template - Null is a valid value for a template so the app should reflect that instead of suggesting there is an error, which may cause users to start looking in the wrong place. * Log.e instead of Log.i
This commit is contained in:
parent
7f1677a2dd
commit
9fc98e464e
|
@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateMapOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.lifecycle.AndroidViewModel
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.google.android.gms.wearable.CapabilityClient
|
import com.google.android.gms.wearable.CapabilityClient
|
||||||
|
@ -112,12 +113,13 @@ class SettingsWearViewModel @Inject constructor(
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
templateTileContentRendered.value =
|
templateTileContentRendered.value =
|
||||||
integrationUseCase.renderTemplate(template, mapOf()) ?: getApplication<Application>().getString(
|
integrationUseCase.renderTemplate(template, mapOf()).toString()
|
||||||
commonR.string.template_error
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Exception while rendering template", e)
|
||||||
|
// JsonMappingException suggests that template is not a String (= error)
|
||||||
templateTileContentRendered.value = getApplication<Application>().getString(
|
templateTileContentRendered.value = getApplication<Application>().getString(
|
||||||
commonR.string.template_render_error
|
if (e.cause is JsonMappingException) commonR.string.template_error
|
||||||
|
else commonR.string.template_render_error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,17 +91,12 @@ class TemplateWidget : BaseWidgetProvider() {
|
||||||
// Content
|
// Content
|
||||||
var renderedTemplate: String? = templateWidgetDao.get(appWidgetId)?.lastUpdate ?: "Loading"
|
var renderedTemplate: String? = templateWidgetDao.get(appWidgetId)?.lastUpdate ?: "Loading"
|
||||||
try {
|
try {
|
||||||
renderedTemplate = integrationUseCase.renderTemplate(widget.template, mapOf())
|
renderedTemplate = integrationUseCase.renderTemplate(widget.template, mapOf()).toString()
|
||||||
if (renderedTemplate != null) {
|
|
||||||
templateWidgetDao.updateTemplateWidgetLastUpdate(
|
templateWidgetDao.updateTemplateWidgetLastUpdate(
|
||||||
appWidgetId,
|
appWidgetId,
|
||||||
renderedTemplate
|
renderedTemplate
|
||||||
)
|
)
|
||||||
setViewVisibility(R.id.widgetTemplateError, View.GONE)
|
setViewVisibility(R.id.widgetTemplateError, View.GONE)
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Template returned null: ${widget.template}")
|
|
||||||
setViewVisibility(R.id.widgetTemplateError, View.VISIBLE)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Unable to render template: ${widget.template}", e)
|
Log.e(TAG, "Unable to render template: ${widget.template}", e)
|
||||||
setViewVisibility(R.id.widgetTemplateError, View.VISIBLE)
|
setViewVisibility(R.id.widgetTemplateError, View.VISIBLE)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Html.fromHtml
|
import android.text.Html.fromHtml
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
|
@ -16,6 +17,7 @@ import androidx.core.graphics.toColorInt
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.widget.doAfterTextChanged
|
import androidx.core.widget.doAfterTextChanged
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import io.homeassistant.companion.android.common.data.integration.IntegrationRepository
|
import io.homeassistant.companion.android.common.data.integration.IntegrationRepository
|
||||||
|
@ -213,10 +215,15 @@ class TemplateWidgetConfigureActivity : BaseWidgetConfigureActivity() {
|
||||||
var enabled: Boolean
|
var enabled: Boolean
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
templateText = integrationUseCase.renderTemplate(template, mapOf()) ?: getString(commonR.string.template_error)
|
templateText = integrationUseCase.renderTemplate(template, mapOf()).toString()
|
||||||
enabled = true
|
enabled = true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
templateText = getString(commonR.string.template_render_error)
|
Log.e(TAG, "Exception while rendering template", e)
|
||||||
|
// JsonMappingException suggests that template is not a String (= error)
|
||||||
|
templateText = getString(
|
||||||
|
if (e.cause is JsonMappingException) commonR.string.template_error
|
||||||
|
else commonR.string.template_render_error
|
||||||
|
)
|
||||||
enabled = false
|
enabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.text.style.ForegroundColorSpan
|
||||||
import android.text.style.RelativeSizeSpan
|
import android.text.style.RelativeSizeSpan
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
import android.text.style.UnderlineSpan
|
import android.text.style.UnderlineSpan
|
||||||
|
import android.util.Log
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY
|
import androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY
|
||||||
import androidx.core.text.HtmlCompat.fromHtml
|
import androidx.core.text.HtmlCompat.fromHtml
|
||||||
|
@ -32,6 +33,7 @@ import androidx.wear.tiles.TileBuilders.Tile
|
||||||
import androidx.wear.tiles.TileService
|
import androidx.wear.tiles.TileService
|
||||||
import androidx.wear.tiles.TimelineBuilders.Timeline
|
import androidx.wear.tiles.TimelineBuilders.Timeline
|
||||||
import androidx.wear.tiles.TimelineBuilders.TimelineEntry
|
import androidx.wear.tiles.TimelineBuilders.TimelineEntry
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException
|
||||||
import com.google.common.util.concurrent.ListenableFuture
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import io.homeassistant.companion.android.R
|
import io.homeassistant.companion.android.R
|
||||||
|
@ -69,11 +71,12 @@ class TemplateTile : TileService() {
|
||||||
|
|
||||||
val template = integrationUseCase.getTemplateTileContent()
|
val template = integrationUseCase.getTemplateTileContent()
|
||||||
val renderedText = try {
|
val renderedText = try {
|
||||||
integrationUseCase.renderTemplate(template, mapOf()) ?: getString(
|
integrationUseCase.renderTemplate(template, mapOf()).toString()
|
||||||
commonR.string.template_error
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
getString(commonR.string.template_render_error)
|
Log.e("TemplateTile", "Exception while rendering template", e)
|
||||||
|
// JsonMappingException suggests that template is not a String (= error)
|
||||||
|
if (e.cause is JsonMappingException) getString(commonR.string.template_error)
|
||||||
|
else getString(commonR.string.template_render_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
Tile.Builder()
|
Tile.Builder()
|
||||||
|
|
Loading…
Reference in a new issue