@@ -118,6 +118,31 @@ class ThreadListAdapter @Inject constructor(
118
118
this .recyclerView = recyclerView
119
119
}
120
120
121
+ override fun getItemViewType (position : Int ): Int = runCatchingRealm {
122
+ val item = dataSet[position]
123
+ return when {
124
+ item is String -> DisplayType .DATE_SEPARATOR .layout
125
+ item is FolderRole -> DisplayType .FLUSH_FOLDER_BUTTON .layout
126
+ item is Unit -> DisplayType .LOAD_MORE_BUTTON .layout
127
+ displaySeeAllButton -> DisplayType .SEE_ALL_BUTTON .layout
128
+ else -> DisplayType .THREAD .layout
129
+ }
130
+ }.getOrDefault(super .getItemViewType(position))
131
+
132
+ override fun getItemId (position : Int ): Long = runCatchingRealm {
133
+ return when (val item = dataSet[position]) {
134
+ is Thread -> item.uid.hashCode().toLong()
135
+ is String -> item.hashCode().toLong()
136
+ else -> super .getItemId(position)
137
+ }
138
+ }.getOrDefault(super .getItemId(position))
139
+
140
+ fun getItemPosition (threadUid : String ): Int? {
141
+ return dataSet
142
+ .indexOfFirst { it is Thread && it.uid == threadUid }
143
+ .takeIf { position -> position != - 1 }
144
+ }
145
+
121
146
override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): ThreadListViewHolder {
122
147
val layoutInflater = LayoutInflater .from(parent.context)
123
148
val binding = when (viewType) {
@@ -132,13 +157,17 @@ class ThreadListAdapter @Inject constructor(
132
157
}
133
158
134
159
override fun onBindViewHolder (holder : ThreadListViewHolder , position : Int , payloads : MutableList <Any >) = runCatchingRealm {
160
+
135
161
val payload = payloads.firstOrNull()
162
+ if (payload !is NotificationType ) {
163
+ super .onBindViewHolder(holder, position, payloads)
164
+ return @runCatchingRealm
165
+ }
166
+
136
167
if (payload == NotificationType .SELECTED_STATE && holder.itemViewType == DisplayType .THREAD .layout) {
137
168
val binding = holder.binding as CardviewThreadItemBinding
138
169
val thread = dataSet[position] as Thread
139
170
binding.updateSelectedUi(thread)
140
- } else {
141
- super .onBindViewHolder(holder, position, payloads)
142
171
}
143
172
}.getOrDefault(Unit )
144
173
@@ -152,31 +181,6 @@ class ThreadListAdapter @Inject constructor(
152
181
}
153
182
}
154
183
155
- override fun getItemViewType (position : Int ): Int = runCatchingRealm {
156
- val item = dataSet[position]
157
- return when {
158
- item is String -> DisplayType .DATE_SEPARATOR .layout
159
- item is FolderRole -> DisplayType .FLUSH_FOLDER_BUTTON .layout
160
- item is Unit -> DisplayType .LOAD_MORE_BUTTON .layout
161
- displaySeeAllButton -> DisplayType .SEE_ALL_BUTTON .layout
162
- else -> DisplayType .THREAD .layout
163
- }
164
- }.getOrDefault(super .getItemViewType(position))
165
-
166
- override fun getItemId (position : Int ): Long = runCatchingRealm {
167
- return when (val item = dataSet[position]) {
168
- is Thread -> item.uid.hashCode().toLong()
169
- is String -> item.hashCode().toLong()
170
- else -> super .getItemId(position)
171
- }
172
- }.getOrDefault(super .getItemId(position))
173
-
174
- fun getItemPosition (threadUid : String ): Int? {
175
- return dataSet
176
- .indexOfFirst { it is Thread && it.uid == threadUid }
177
- .takeIf { position -> position != - 1 }
178
- }
179
-
180
184
private fun CardviewThreadItemBinding.displayThread (thread : Thread , position : Int ) {
181
185
182
186
refreshCachedSelectedPosition(thread.uid, position) // If item changed position, update cached position.
0 commit comments