Fix dynamic field crash for service call widget (#954)

* Fix dynamic field crash

* Review comments
This commit is contained in:
Daniel Shokouhi 2020-09-19 11:23:20 -07:00 committed by GitHub
parent 9682b5d341
commit 54a0d83c03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package io.homeassistant.companion.android.widgets
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -10,7 +11,7 @@ import android.widget.MultiAutoCompleteTextView.CommaTokenizer
import androidx.recyclerview.widget.RecyclerView
import io.homeassistant.companion.android.common.data.integration.Entity
import io.homeassistant.companion.android.common.data.integration.Service
import java.lang.Exception
import kotlin.Exception
import kotlinx.android.synthetic.main.widget_button_configure_dynamic_field.view.*
class WidgetDynamicFieldAdapter(
@ -20,6 +21,7 @@ class WidgetDynamicFieldAdapter(
) : RecyclerView.Adapter<WidgetDynamicFieldAdapter.ViewHolder>() {
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
private val TAG = "WidgetField"
private val dropDownOnFocus = View.OnFocusChangeListener { view, hasFocus ->
if (hasFocus && view is AutoCompleteTextView) {
view.showDropDown()
@ -127,7 +129,11 @@ class WidgetDynamicFieldAdapter(
// Currently value can by Any? but will currently only be storing String?
// This may have to be changed later if multi-select gets implemented
if (serviceFieldList[position].value != null) {
try {
serviceFieldList[position].value as String
} catch (e: Exception) {
Log.d(TAG, "Unable to get service field list", e)
}
}
// Have the text view store its text for later recall