mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-01-25 13:38:59 +01:00
Fixed updating last message after deleting (#167)
This commit is contained in:
parent
72833f6f16
commit
44c540b961
@ -30,8 +30,10 @@ import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
||||
import com.simplemobiletools.smsmessenger.dialogs.SelectTextDialog
|
||||
import com.simplemobiletools.smsmessenger.extensions.deleteMessage
|
||||
import com.simplemobiletools.smsmessenger.extensions.updateLastConversationMessage
|
||||
import com.simplemobiletools.smsmessenger.helpers.*
|
||||
import com.simplemobiletools.smsmessenger.models.*
|
||||
import kotlinx.android.synthetic.main.item_attachment_image.view.*
|
||||
@ -181,10 +183,12 @@ class ThreadAdapter(
|
||||
|
||||
val messagesToRemove = getSelectedItems()
|
||||
val positions = getSelectedItemPositions()
|
||||
val threadId = (messagesToRemove[0] as Message).threadId
|
||||
messagesToRemove.forEach {
|
||||
activity.deleteMessage((it as Message).id, it.isMMS)
|
||||
}
|
||||
messages.removeAll(messagesToRemove)
|
||||
activity.updateLastConversationMessage(threadId)
|
||||
|
||||
activity.runOnUiThread {
|
||||
if (messages.filter { it is Message }.isEmpty()) {
|
||||
|
@ -764,3 +764,15 @@ fun Context.getLockScreenVisibilityText(type: Int) = getString(
|
||||
else -> R.string.nothing
|
||||
}
|
||||
)
|
||||
|
||||
fun Context.updateLastConversationMessage(threadId: Long) {
|
||||
val uri = Threads.CONTENT_URI
|
||||
val selection = "${Threads._ID} = ?"
|
||||
val selectionArgs = arrayOf(threadId.toString())
|
||||
try {
|
||||
contentResolver.delete(uri, selection, selectionArgs)
|
||||
val newConversation = getConversations(threadId)[0]
|
||||
conversationsDB.insertOrUpdate(newConversation)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user