Persist group expand status
This commit is contained in:
@@ -143,7 +143,6 @@ class GroupsFragment : Fragment(), CommandClientHandler {
|
|||||||
private class Adapter : RecyclerView.Adapter<GroupView>() {
|
private class Adapter : RecyclerView.Adapter<GroupView>() {
|
||||||
|
|
||||||
lateinit var groups: List<OutboundGroup>
|
lateinit var groups: List<OutboundGroup>
|
||||||
private val expandStatus: MutableMap<String, Boolean> = mutableMapOf()
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GroupView {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GroupView {
|
||||||
return GroupView(
|
return GroupView(
|
||||||
ViewDashboardGroupBinding.inflate(
|
ViewDashboardGroupBinding.inflate(
|
||||||
@@ -151,7 +150,6 @@ class GroupsFragment : Fragment(), CommandClientHandler {
|
|||||||
parent,
|
parent,
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
expandStatus
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,10 +165,7 @@ class GroupsFragment : Fragment(), CommandClientHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class GroupView(
|
private class GroupView(val binding: ViewDashboardGroupBinding) :
|
||||||
val binding: ViewDashboardGroupBinding,
|
|
||||||
val expandStatus: MutableMap<String, Boolean>
|
|
||||||
) :
|
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
lateinit var group: OutboundGroup
|
lateinit var group: OutboundGroup
|
||||||
@@ -204,12 +199,17 @@ class GroupsFragment : Fragment(), CommandClientHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateExpand(isExpand: Boolean? = null) {
|
private fun updateExpand(isExpand: Boolean? = null) {
|
||||||
val newExpandStatus: Boolean
|
val newExpandStatus = isExpand ?: group.isExpand
|
||||||
if (isExpand == null) {
|
if (isExpand != null) {
|
||||||
newExpandStatus = expandStatus[group.tag] ?: group.selectable
|
GlobalScope.launch {
|
||||||
} else {
|
runCatching {
|
||||||
expandStatus[group.tag] = isExpand
|
Libbox.newStandaloneCommandClient().setGroupExpand(group.tag, isExpand)
|
||||||
newExpandStatus = isExpand
|
}.onFailure {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
binding.root.context.errorDialogBuilder(it).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
binding.itemList.isVisible = newExpandStatus
|
binding.itemList.isVisible = newExpandStatus
|
||||||
binding.itemText.isVisible = !newExpandStatus
|
binding.itemText.isVisible = !newExpandStatus
|
||||||
|
|||||||
Reference in New Issue
Block a user