mirror of
https://github.com/home-assistant/android
synced 2024-10-02 22:34:46 +00:00
Some fixes for empty entity lists in wear (#1789)
* Some fixes for empty entity lists in wear * Review comments
This commit is contained in:
parent
9f3f552155
commit
b8994b744d
|
@ -61,13 +61,22 @@ class HomeActivity : AppCompatActivity(), HomeView {
|
|||
|
||||
override fun showHomeList(scenes: List<Entity<Any>>, scripts: List<Entity<Any>>, lights: List<Entity<Any>>, covers: List<Entity<Any>>) {
|
||||
adapter.scenes.clear()
|
||||
adapter.scenes.addAll(scenes)
|
||||
adapter.scripts.clear()
|
||||
adapter.scripts.addAll(scripts)
|
||||
adapter.lights.clear()
|
||||
adapter.lights.addAll(lights)
|
||||
adapter.covers.clear()
|
||||
adapter.covers.addAll(covers)
|
||||
|
||||
if (scenes.isNotEmpty())
|
||||
adapter.scenes.addAll(scenes)
|
||||
|
||||
if (scripts.isNotEmpty())
|
||||
adapter.scripts.addAll(scripts)
|
||||
|
||||
if (lights.isNotEmpty())
|
||||
adapter.lights.addAll(lights)
|
||||
|
||||
if (covers.isNotEmpty())
|
||||
adapter.covers.addAll(covers)
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.homeassistant.companion.android.home
|
||||
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -30,6 +31,8 @@ class HomeListAdapter() : RecyclerView.Adapter<ViewHolder>() {
|
|||
private const val TYPE_BUTTON = 4
|
||||
|
||||
const val BUTTON_ID_LOGOUT: String = "logout"
|
||||
|
||||
private const val TAG = "HomeListAdapter"
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(
|
||||
|
@ -61,24 +64,28 @@ class HomeListAdapter() : RecyclerView.Adapter<ViewHolder>() {
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
if (holder is EntityButtonViewHolder) {
|
||||
if (position < scenes.size + 1) {
|
||||
holder.entity = scenes[position - 1]
|
||||
} else if (position > scenes.size + 1 + scripts.size + 1) {
|
||||
holder.entity = lights[position - 3 - scenes.size - scripts.size]
|
||||
} else
|
||||
holder.entity = scripts[position - 2 - scenes.size]
|
||||
} else if (holder is HeaderViewHolder) {
|
||||
when (position) {
|
||||
0 -> holder.headerTextView.setText(R.string.scenes)
|
||||
scenes.size + 1 -> holder.headerTextView.setText(R.string.scripts)
|
||||
scenes.size + scripts.size + 2 -> holder.headerTextView.setText(R.string.lights)
|
||||
else -> holder.headerTextView.setText(R.string.other)
|
||||
try {
|
||||
if (holder is EntityButtonViewHolder) {
|
||||
if (position < scenes.size + 1) {
|
||||
holder.entity = scenes[position - 1]
|
||||
} else if (position > scenes.size + 1 + scripts.size + 1) {
|
||||
holder.entity = lights[position - 3 - scenes.size - scripts.size]
|
||||
} else
|
||||
holder.entity = scripts[position - 2 - scenes.size]
|
||||
} else if (holder is HeaderViewHolder) {
|
||||
when (position) {
|
||||
0 -> holder.headerTextView.setText(R.string.scenes)
|
||||
scenes.size + 1 -> holder.headerTextView.setText(R.string.scripts)
|
||||
scenes.size + scripts.size + 2 -> holder.headerTextView.setText(R.string.lights)
|
||||
else -> holder.headerTextView.setText(R.string.other)
|
||||
}
|
||||
} else if (holder is ButtonViewHolder) {
|
||||
holder.txtName.setText(R.string.logout)
|
||||
holder.id = BUTTON_ID_LOGOUT
|
||||
holder.color = R.color.colorWarning
|
||||
}
|
||||
} else if (holder is ButtonViewHolder) {
|
||||
holder.txtName.setText(R.string.logout)
|
||||
holder.id = BUTTON_ID_LOGOUT
|
||||
holder.color = R.color.colorWarning
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Unable to add entities to list", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,6 @@ class HomePresenterImpl @Inject constructor(
|
|||
val lights = entities.sortedBy { it.entityId }.filter { it.entityId.split(".")[0] == "light" }
|
||||
val covers = entities.sortedBy { it.entityId }.filter { it.entityId.split(".")[0] == "cover" }
|
||||
view.showHomeList(scenes, scripts, lights, covers)
|
||||
Log.i(TAG, "Cover data: " + covers[0].attributes.toString())
|
||||
}
|
||||
|
||||
private fun resyncRegistration() {
|
||||
|
|
Loading…
Reference in a new issue