@@ -33,6 +33,7 @@ import androidx.recyclerview.widget.DiffUtil
33
33
import androidx.recyclerview.widget.ListAdapter
34
34
import androidx.recyclerview.widget.RecyclerView
35
35
import androidx.recyclerview.widget.RecyclerView.*
36
+ import androidx.viewbinding.ViewBinding
36
37
import androidx.webkit.WebSettingsCompat
37
38
import androidx.webkit.WebViewFeature
38
39
import com.infomaniak.lib.core.utils.*
@@ -63,6 +64,7 @@ import kotlinx.coroutines.Dispatchers
63
64
import kotlinx.coroutines.launch
64
65
import java.util.*
65
66
import com.google.android.material.R as RMaterial
67
+ import com.infomaniak.lib.core.R as RCore
66
68
67
69
class ThreadAdapter (
68
70
private val shouldLoadDistantResources : Boolean ,
@@ -81,7 +83,7 @@ class ThreadAdapter(
81
83
navigateToDownloadProgressDialog : (Int , Bundle ) -> Unit ,
82
84
replyToCalendarEvent : (AttendanceState , Message ) -> Unit ,
83
85
promptLink : (String , ContextMenuType ) -> Unit ,
84
- ) : ListAdapter<Any, ViewHolder >(MessageDiffCallback ()) {
86
+ ) : ListAdapter<Any, ThreadAdapterViewHolder >(MessageDiffCallback ()) {
85
87
86
88
inline val items: MutableList <Any > get() = currentList
87
89
@@ -146,7 +148,7 @@ class ThreadAdapter(
146
148
}
147
149
}.getOrDefault(super .getItemViewType(position))
148
150
149
- override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): ViewHolder {
151
+ override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): ThreadAdapterViewHolder {
150
152
val layoutInflater = LayoutInflater .from(parent.context)
151
153
return if (viewType == R .layout.item_message) {
152
154
MessageViewHolder (
@@ -160,7 +162,7 @@ class ThreadAdapter(
160
162
}
161
163
}
162
164
163
- override fun onBindViewHolder (holder : ViewHolder , position : Int , payloads : MutableList <Any >) = runCatchingRealm {
165
+ override fun onBindViewHolder (holder : ThreadAdapterViewHolder , position : Int , payloads : MutableList <Any >) = runCatchingRealm {
164
166
165
167
val payload = payloads.firstOrNull()
166
168
if (payload !is NotifyType ) {
@@ -189,8 +191,17 @@ class ThreadAdapter(
189
191
}
190
192
}.getOrDefault(Unit )
191
193
192
- override fun onBindViewHolder (holder : ViewHolder , position : Int ) {
194
+ override fun onBindViewHolder (holder : ThreadAdapterViewHolder , position : Int ) {
195
+
193
196
val item = items[position]
197
+ val previousItem = if (position > 0 ) items[position - 1 ] else null
198
+
199
+ holder.binding.root.tag = if (item is SuperCollapsedBlock || previousItem is SuperCollapsedBlock ) {
200
+ holder.binding.context.getString(RCore .string.ignoreDivider)
201
+ } else {
202
+ null
203
+ }
204
+
194
205
if (item is Message ) {
195
206
(holder as MessageViewHolder ).bindMail(item, position)
196
207
} else {
@@ -725,14 +736,18 @@ class ThreadAdapter(
725
736
726
737
data class SuperCollapsedBlock (val messagesUids : Set <String >)
727
738
728
- class SuperCollapsedBlockViewHolder (val binding : ItemSuperCollapsedBlockBinding ) : ViewHolder(binding.root)
739
+ abstract class ThreadAdapterViewHolder (open val binding : ViewBinding ) : ViewHolder(binding.root)
740
+
741
+ private class SuperCollapsedBlockViewHolder (
742
+ override val binding : ItemSuperCollapsedBlockBinding ,
743
+ ) : ThreadAdapterViewHolder(binding)
729
744
730
- class MessageViewHolder (
731
- val binding : ItemMessageBinding ,
745
+ private class MessageViewHolder (
746
+ override val binding : ItemMessageBinding ,
732
747
private val shouldLoadDistantResources : Boolean ,
733
748
onContactClicked : ((contact: Recipient ) -> Unit )? ,
734
749
onAttachmentClicked : ((attachment: Attachment ) -> Unit )? ,
735
- ) : ViewHolder (binding.root ) {
750
+ ) : ThreadAdapterViewHolder (binding) {
736
751
737
752
val fromAdapter = DetailedRecipientAdapter (onContactClicked)
738
753
val toAdapter = DetailedRecipientAdapter (onContactClicked)
0 commit comments