@@ -18,7 +18,6 @@ import androidx.recyclerview.widget.SimpleItemAnimator
1818import com.google.android.material.textfield.MaterialAutoCompleteTextView
1919import io.nekohasekai.libbox.Libbox
2020import io.nekohasekai.libbox.OutboundGroup
21- import io.nekohasekai.libbox.OutboundGroupItem
2221import io.nekohasekai.sfa.R
2322import io.nekohasekai.sfa.constant.Status
2423import io.nekohasekai.sfa.databinding.FragmentDashboardGroupsBinding
@@ -99,18 +98,18 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
9998 val adapter = adapter ? : return
10099 activity?.runOnUiThread {
101100 updateDisplayed(newGroups.isNotEmpty())
102- adapter.setGroups(newGroups)
101+ adapter.setGroups(newGroups.map(:: Group ) )
103102 }
104103 }
105104
106105 private class Adapter : RecyclerView .Adapter <GroupView >() {
107106
108- private lateinit var groups: MutableList <OutboundGroup >
107+ private lateinit var groups: MutableList <Group >
109108
110109 @SuppressLint(" NotifyDataSetChanged" )
111- fun setGroups (newGroups : MutableList < OutboundGroup >) {
110+ fun setGroups (newGroups : List < Group >) {
112111 if (! ::groups.isInitialized || groups.size != newGroups.size) {
113- groups = newGroups
112+ groups = newGroups.toMutableList()
114113 notifyDataSetChanged()
115114 } else {
116115 newGroups.forEachIndexed { index, group ->
@@ -119,7 +118,6 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
119118 notifyItemChanged(index)
120119 }
121120 }
122-
123121 }
124122 }
125123
@@ -148,14 +146,14 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
148146 private class GroupView (val binding : ViewDashboardGroupBinding ) :
149147 RecyclerView .ViewHolder (binding.root) {
150148
151- private lateinit var group: OutboundGroup
152- private lateinit var items: MutableList < OutboundGroupItem >
149+ private lateinit var group: Group
150+ private lateinit var items: List < GroupItem >
153151 private lateinit var adapter: ItemAdapter
154152 private lateinit var textWatcher: TextWatcher
155153
156154 @OptIn(DelicateCoroutinesApi ::class )
157155 @SuppressLint(" NotifyDataSetChanged" )
158- fun bind (group : OutboundGroup ) {
156+ fun bind (group : Group ) {
159157 this .group = group
160158 binding.groupName.text = group.tag
161159 binding.groupType.text = Libbox .proxyDisplayType(group.type)
@@ -170,13 +168,9 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
170168 }
171169 }
172170 }
173- items = mutableListOf ()
174- val itemIterator = group.items
175- while (itemIterator.hasNext()) {
176- items.add(itemIterator.next())
177- }
171+ items = group.items
178172 if (! ::adapter.isInitialized) {
179- adapter = ItemAdapter (this , group, items)
173+ adapter = ItemAdapter (this , group, items.toMutableList() )
180174 binding.itemList.adapter = adapter
181175 (binding.itemList.itemAnimator as SimpleItemAnimator ).supportsChangeAnimations =
182176 false
@@ -231,7 +225,7 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
231225 }
232226 }
233227
234- fun updateSelected (group : OutboundGroup , itemTag : String ) {
228+ fun updateSelected (group : Group , itemTag : String ) {
235229 val oldSelected = items.indexOfFirst { it.tag == group.selected }
236230 group.selected = itemTag
237231 if (oldSelected != - 1 ) {
@@ -242,15 +236,15 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
242236
243237 private class ItemAdapter (
244238 val groupView : GroupView ,
245- var group : OutboundGroup ,
246- private var items : MutableList <OutboundGroupItem > = mutableListOf()
239+ var group : Group ,
240+ private var items : MutableList <GroupItem > = mutableListOf()
247241 ) :
248242 RecyclerView .Adapter <ItemGroupView >() {
249243
250244 @SuppressLint(" NotifyDataSetChanged" )
251- fun setItems (newItems : MutableList < OutboundGroupItem >) {
245+ fun setItems (newItems : List < GroupItem >) {
252246 if (items.size != newItems.size) {
253- items = newItems
247+ items = newItems.toMutableList()
254248 notifyDataSetChanged()
255249 } else {
256250 newItems.forEachIndexed { index, item ->
@@ -285,7 +279,7 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
285279 RecyclerView .ViewHolder (binding.root) {
286280
287281 @OptIn(DelicateCoroutinesApi ::class )
288- fun bind (groupView : GroupView , group : OutboundGroup , item : OutboundGroupItem ) {
282+ fun bind (groupView : GroupView , group : Group , item : GroupItem ) {
289283 if (group.selectable) {
290284 binding.itemCard.setOnClickListener {
291285 binding.selectedView.isVisible = true
0 commit comments