diff --git a/app/build.gradle b/app/build.gradle index e84d1d98..7f66d5a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt index 2a66fa41..a2f00db7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt index 5332f2b5..b7b8ca89 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt @@ -30,9 +30,11 @@ class ConversationsAdapter( itemClick: (Any) -> Unit ) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { private var fontSize = activity.getTextSize() + private var drafts = HashMap() 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) { + 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() + 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) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0521dba2..fd9a16ef 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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