avoid fetching conversation drafts during scrolling

This commit is contained in:
tibbi 2021-10-18 18:58:56 +02:00
parent 83eb9a886d
commit bb59c84b77
4 changed files with 29 additions and 7 deletions

View File

@ -56,7 +56,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:3c6e3cd0fd'
implementation 'com.github.SimpleMobileTools:Simple-Commons:87b6e92b97'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.klinkerapps:android-smsmms:5.2.6'
implementation 'com.github.tibbi:IndicatorFastScroll:c3de1d040a'

View File

@ -92,6 +92,7 @@ class MainActivity : SimpleActivity() {
(conversations_list.adapter as? ConversationsAdapter)?.updateFontSize()
}
(conversations_list.adapter as? ConversationsAdapter)?.updateDrafts()
updateTextColors(main_coordinator)
no_conversations_placeholder_2.setTextColor(getAdjustedPrimaryColor())
no_conversations_placeholder_2.underlineText()

View File

@ -30,9 +30,11 @@ class ConversationsAdapter(
itemClick: (Any) -> Unit
) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
private var fontSize = activity.getTextSize()
private var drafts = HashMap<Long, String?>()
init {
setupDragListener(true)
fetchDrafts(drafts)
}
override fun getActionMenuId() = R.menu.cab_conversations
@ -94,6 +96,13 @@ class ConversationsAdapter(
override fun getItemCount() = conversations.size
override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isDestroyed && !activity.isFinishing) {
Glide.with(activity).clear(holder.itemView.conversation_image)
}
}
private fun askConfirmBlock() {
val numbers = getSelectedItems().distinctBy { it.phoneNumber }.map { it.phoneNumber }
val numbersString = TextUtils.join(", ", numbers)
@ -255,10 +264,13 @@ class ConversationsAdapter(
menu.findItem(R.id.cab_unpin_conversation).isVisible = selectedConversations.any { pinnedConversations.contains(it.threadId.toString()) }
}
override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isDestroyed && !activity.isFinishing) {
Glide.with(activity).clear(holder.itemView.conversation_image)
private fun fetchDrafts(drafts: HashMap<Long, String?>) {
drafts.clear()
conversations.forEach { conversation ->
val draft = activity.getSmsDraft(conversation.threadId)
if (draft != null) {
drafts[conversation.threadId] = draft
}
}
}
@ -277,9 +289,18 @@ class ConversationsAdapter(
}
}
fun updateDrafts() {
val newDrafts = HashMap<Long, String?>()
fetchDrafts(newDrafts)
if (drafts.hashCode() != newDrafts.hashCode()) {
drafts = newDrafts
notifyDataSetChanged()
}
}
private fun setupView(view: View, conversation: Conversation) {
view.apply {
val smsDraft = context.getSmsDraft(conversation.threadId)
val smsDraft = drafts[conversation.threadId]
draft_indicator.beVisibleIf(smsDraft != null)
draft_indicator.setTextColor(adjustedPrimaryColor)

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip