@@ -65,6 +65,7 @@ class CollectionAdapter(
6565 private var editStationStreamsEnabled: Boolean = PreferencesHelper .loadEditStreamUrisEnabled()
6666 private var expandedStationUuid: String = PreferencesHelper .loadStationListStreamUuid()
6767 private var expandedStationPosition: Int = - 1
68+ private var isExpandedForEdit: Boolean = false
6869
6970
7071 /* Listener Interface */
@@ -117,29 +118,31 @@ class CollectionAdapter(
117118
118119 /* Implement the method to handle item move */
119120 fun onItemMove (fromPosition : Int , toPosition : Int ) {
120- val stationList = collection.stations
121- val stationCount = stationList.size
121+ if (! isExpandedForEdit) {
122+ val stationList = collection.stations
123+ val stationCount = stationList.size
122124
123- if (fromPosition !in 0 until stationCount || toPosition !in 0 until stationCount) {
124- return
125- }
125+ if (fromPosition !in 0 until stationCount || toPosition !in 0 until stationCount) {
126+ return
127+ }
126128
127- val fromStation = stationList[fromPosition]
128- val toStation = stationList[toPosition]
129+ val fromStation = stationList[fromPosition]
130+ val toStation = stationList[toPosition]
129131
130- if (fromStation.starred != toStation.starred) {
131- // Prevent moving a starred item into non-starred area or vice versa
132- return
133- }
132+ if (fromStation.starred != toStation.starred) {
133+ // Prevent moving a starred item into non-starred area or vice versa
134+ return
135+ }
134136
135- // Move within the same group (either starred or non-starred)
136- Collections .swap(stationList, fromPosition, toPosition)
137+ // Move within the same group (either starred or non-starred)
138+ Collections .swap(stationList, fromPosition, toPosition)
137139
138- // Update the value of expandedStationPosition if necessary
139- expandedStationPosition = if (fromPosition == expandedStationPosition) toPosition else expandedStationPosition
140+ // Update the value of expandedStationPosition if necessary
141+ expandedStationPosition = if (fromPosition == expandedStationPosition) toPosition else expandedStationPosition
140142
141- // Notify the adapter about the item move
142- notifyItemMoved(fromPosition, toPosition)
143+ // Notify the adapter about the item move
144+ notifyItemMoved(fromPosition, toPosition)
145+ }
143146 }
144147
145148
@@ -297,13 +300,15 @@ class CollectionAdapter(
297300 when (stationUuid) {
298301 // CASE: this station's edit view is already expanded
299302 expandedStationUuid -> {
303+ isExpandedForEdit = false
300304 // reset currently expanded info (both uuid and position)
301305 saveStationListExpandedState()
302306 // update station view
303307 notifyItemChanged(position)
304308 }
305309 // CASE: this station's edit view is not yet expanded
306310 else -> {
311+ isExpandedForEdit = true
307312 // remember previously expanded position
308313 val previousExpandedStationPosition: Int = expandedStationPosition
309314 // if station was expanded - collapse it
0 commit comments