Skip to content

Commit 121d03d

Browse files
Use view tag instead of index to detect when to not display divider
1 parent 340e62f commit 121d03d

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadAdapter.kt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import androidx.recyclerview.widget.DiffUtil
3333
import androidx.recyclerview.widget.ListAdapter
3434
import androidx.recyclerview.widget.RecyclerView
3535
import androidx.recyclerview.widget.RecyclerView.*
36+
import androidx.viewbinding.ViewBinding
3637
import androidx.webkit.WebSettingsCompat
3738
import androidx.webkit.WebViewFeature
3839
import com.infomaniak.lib.core.utils.*
@@ -63,6 +64,7 @@ import kotlinx.coroutines.Dispatchers
6364
import kotlinx.coroutines.launch
6465
import java.util.*
6566
import com.google.android.material.R as RMaterial
67+
import com.infomaniak.lib.core.R as RCore
6668

6769
class ThreadAdapter(
6870
private val shouldLoadDistantResources: Boolean,
@@ -81,7 +83,7 @@ class ThreadAdapter(
8183
navigateToDownloadProgressDialog: (Int, Bundle) -> Unit,
8284
replyToCalendarEvent: (AttendanceState, Message) -> Unit,
8385
promptLink: (String, ContextMenuType) -> Unit,
84-
) : ListAdapter<Any, ViewHolder>(MessageDiffCallback()) {
86+
) : ListAdapter<Any, ThreadAdapterViewHolder>(MessageDiffCallback()) {
8587

8688
inline val items: MutableList<Any> get() = currentList
8789

@@ -146,7 +148,7 @@ class ThreadAdapter(
146148
}
147149
}.getOrDefault(super.getItemViewType(position))
148150

149-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
151+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ThreadAdapterViewHolder {
150152
val layoutInflater = LayoutInflater.from(parent.context)
151153
return if (viewType == R.layout.item_message) {
152154
MessageViewHolder(
@@ -160,7 +162,7 @@ class ThreadAdapter(
160162
}
161163
}
162164

163-
override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads: MutableList<Any>) = runCatchingRealm {
165+
override fun onBindViewHolder(holder: ThreadAdapterViewHolder, position: Int, payloads: MutableList<Any>) = runCatchingRealm {
164166

165167
val payload = payloads.firstOrNull()
166168
if (payload !is NotifyType) {
@@ -189,8 +191,17 @@ class ThreadAdapter(
189191
}
190192
}.getOrDefault(Unit)
191193

192-
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
194+
override fun onBindViewHolder(holder: ThreadAdapterViewHolder, position: Int) {
195+
193196
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+
194205
if (item is Message) {
195206
(holder as MessageViewHolder).bindMail(item, position)
196207
} else {
@@ -725,14 +736,18 @@ class ThreadAdapter(
725736

726737
data class SuperCollapsedBlock(val messagesUids: Set<String>)
727738

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)
729744

730-
class MessageViewHolder(
731-
val binding: ItemMessageBinding,
745+
private class MessageViewHolder(
746+
override val binding: ItemMessageBinding,
732747
private val shouldLoadDistantResources: Boolean,
733748
onContactClicked: ((contact: Recipient) -> Unit)?,
734749
onAttachmentClicked: ((attachment: Attachment) -> Unit)?,
735-
) : ViewHolder(binding.root) {
750+
) : ThreadAdapterViewHolder(binding) {
736751

737752
val fromAdapter = DetailedRecipientAdapter(onContactClicked)
738753
val toAdapter = DetailedRecipientAdapter(onContactClicked)

app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ class ThreadFragment : Fragment() {
305305

306306
twoPaneViewModel.currentThreadUid.distinctUntilChanged().observeNotNull(viewLifecycleOwner) { threadUid ->
307307

308+
resetMessagesCache()
308309
displayThreadView()
309310

310311
openThread(threadUid).observe(viewLifecycleOwner) { result ->

app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadViewModel.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class ThreadViewModel @Inject constructor(
8888
AccountUtils.currentMailboxId,
8989
).map { it.obj }.asLiveData(ioCoroutineContext)
9090

91+
fun resetMessagesCache() {
92+
cachedSplitBodies = mutableMapOf()
93+
superCollapsedBlock = null
94+
hasUserClickedTheSuperCollapsedBlock = false
95+
}
96+
9197
fun reassignThreadLive(threadUid: String) {
9298
threadLiveJob?.cancel()
9399
threadLiveJob = viewModelScope.launch(ioCoroutineContext) {
@@ -98,10 +104,6 @@ class ThreadViewModel @Inject constructor(
98104
fun reassignMessagesLive(threadUid: String) {
99105
messagesLiveJob?.cancel()
100106
messagesLiveJob = viewModelScope.launch(ioCoroutineContext) {
101-
102-
cachedSplitBodies = mutableMapOf()
103-
superCollapsedBlock = null
104-
105107
messageController.getSortedAndNotDeletedMessagesAsync(threadUid)
106108
?.map(::mapRealmMessagesResult)
107109
?.collect(messagesLive::postValue)

app/src/main/res/layout/item_message.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
xmlns:tools="http://schemas.android.com/tools"
2121
android:layout_width="match_parent"
2222
android:layout_height="wrap_content"
23-
android:orientation="vertical"
24-
android:tag="Mail">
23+
android:orientation="vertical">
2524

2625
<com.google.android.material.card.MaterialCardView
2726
android:id="@+id/messageHeader"

app/src/main/res/layout/item_super_collapsed_block.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
xmlns:tools="http://schemas.android.com/tools"
2121
android:layout_width="match_parent"
2222
android:layout_height="wrap_content"
23-
android:paddingVertical="@dimen/marginStandardSmall"
24-
android:tag="SuperCollapsedBlock">
23+
android:paddingVertical="@dimen/marginStandardSmall">
2524

2625
<View
2726
android:layout_width="match_parent"

0 commit comments

Comments
 (0)