mirror of
https://github.com/home-assistant/android
synced 2024-10-15 12:32:54 +00:00
Fix restoring custom fields in service button widget (#3813)
- When reading service data from the database, make sure to also add custom fields. - Fix RecyclerView not setting fields to empty when no value is present, potentially showing input from other recycled fields if the field doesn't have any value. - Fix adding a new custom field destroying any input currently held in the views by using a specific insertion method instead of all changed, which will reset the values.
This commit is contained in:
parent
fb71b9c788
commit
cad1bfa47e
|
@ -93,14 +93,18 @@ class ButtonWidgetConfigureActivity : BaseWidgetConfigureActivity() {
|
||||||
.setView(fieldKeyInput)
|
.setView(fieldKeyInput)
|
||||||
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
|
if (dynamicFields.any { it.field == binding.widgetTextConfigService.text.toString() }) return@setPositiveButton
|
||||||
|
|
||||||
|
val position = dynamicFields.size
|
||||||
dynamicFields.add(
|
dynamicFields.add(
|
||||||
|
position,
|
||||||
ServiceFieldBinder(
|
ServiceFieldBinder(
|
||||||
binding.widgetTextConfigService.text.toString(),
|
binding.widgetTextConfigService.text.toString(),
|
||||||
fieldKeyInput.text.toString()
|
fieldKeyInput.text.toString()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
dynamicFieldAdapter.notifyDataSetChanged()
|
dynamicFieldAdapter.notifyItemInserted(position)
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
@ -134,6 +138,7 @@ class ButtonWidgetConfigureActivity : BaseWidgetConfigureActivity() {
|
||||||
Log.d(TAG, "Fields applicable to this service: $fields")
|
Log.d(TAG, "Fields applicable to this service: $fields")
|
||||||
|
|
||||||
val existingServiceData = mutableMapOf<String, Any?>()
|
val existingServiceData = mutableMapOf<String, Any?>()
|
||||||
|
val addedFields = mutableListOf<String>()
|
||||||
buttonWidgetDao.get(appWidgetId)?.let { buttonWidget ->
|
buttonWidgetDao.get(appWidgetId)?.let { buttonWidget ->
|
||||||
if (
|
if (
|
||||||
buttonWidget.serverId != selectedServerId ||
|
buttonWidget.serverId != selectedServerId ||
|
||||||
|
@ -146,6 +151,7 @@ class ButtonWidgetConfigureActivity : BaseWidgetConfigureActivity() {
|
||||||
for (item in dbMap) {
|
for (item in dbMap) {
|
||||||
val value = item.value.toString().replace("[", "").replace("]", "") + if (item.key == "entity_id") ", " else ""
|
val value = item.value.toString().replace("[", "").replace("]", "") + if (item.key == "entity_id") ", " else ""
|
||||||
existingServiceData[item.key] = value.ifEmpty { null }
|
existingServiceData[item.key] = value.ifEmpty { null }
|
||||||
|
addedFields.add(item.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +171,10 @@ class ButtonWidgetConfigureActivity : BaseWidgetConfigureActivity() {
|
||||||
dynamicFields.add(ServiceFieldBinder(serviceText, fieldKey, existingServiceData[fieldKey]))
|
dynamicFields.add(ServiceFieldBinder(serviceText, fieldKey, existingServiceData[fieldKey]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addedFields.minus("entity_id").minus(fieldKeys).forEach { extraFieldKey ->
|
||||||
|
Log.d(TAG, "Creating a text input box for extra $extraFieldKey")
|
||||||
|
dynamicFields.add(ServiceFieldBinder(serviceText, extraFieldKey, existingServiceData[extraFieldKey]))
|
||||||
|
}
|
||||||
|
|
||||||
dynamicFieldAdapter.notifyDataSetChanged()
|
dynamicFieldAdapter.notifyDataSetChanged()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -148,6 +148,8 @@ class WidgetDynamicFieldAdapter(
|
||||||
// Set text to empty string to prevent a recycled, incorrect value
|
// Set text to empty string to prevent a recycled, incorrect value
|
||||||
autoCompleteTextView.setText("")
|
autoCompleteTextView.setText("")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
autoCompleteTextView.setText("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Have the text view store its text for later recall
|
// Have the text view store its text for later recall
|
||||||
|
|
Loading…
Reference in a new issue