Merge branch 'master' into feature/compress-images
This commit is contained in:
commit
07cd3372d8
|
@ -23,6 +23,8 @@ import com.simplemobiletools.commons.views.MyRecyclerView
|
|||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||
import com.simplemobiletools.smsmessenger.extensions.deleteConversation
|
||||
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesRead
|
||||
import com.simplemobiletools.smsmessenger.extensions.markThreadMessagesUnread
|
||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||
import kotlinx.android.synthetic.main.item_conversation.view.*
|
||||
|
@ -59,6 +61,8 @@ class ConversationsAdapter(
|
|||
R.id.cab_dial_number -> dialNumber()
|
||||
R.id.cab_copy_number -> copyNumberToClipboard()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
R.id.cab_mark_as_read -> markAsRead()
|
||||
R.id.cab_mark_as_unread -> markAsUnread()
|
||||
R.id.cab_select_all -> selectAll()
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +188,37 @@ class ConversationsAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
private fun markAsRead() {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val conversationsMarkedAsRead = conversations.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<Conversation>
|
||||
ensureBackgroundThread {
|
||||
conversationsMarkedAsRead.filter { conversation -> !conversation.read }.forEach {
|
||||
activity.markThreadMessagesRead(it.threadId)
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
refreshMessages()
|
||||
finishActMode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun markAsUnread() {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val conversationsMarkedAsUnread = conversations.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<Conversation>
|
||||
ensureBackgroundThread {
|
||||
conversationsMarkedAsUnread.filter { conversation -> conversation.read }.forEach {
|
||||
activity.markThreadMessagesUnread(it.threadId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addNumberToContact() {
|
||||
val conversation = getSelectedItems().firstOrNull() ?: return
|
||||
Intent().apply {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -776,3 +776,15 @@ fun Context.getMMSFileLimitText(size: Long) = getString(
|
|||
else -> R.string.mms_file_size_limit_none
|
||||
}
|
||||
)
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,14 @@
|
|||
android:id="@+id/cab_copy_number"
|
||||
android:title="@string/copy_number_to_clipboard"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_mark_as_read"
|
||||
android:title="@string/mark_as_read"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_mark_as_unread"
|
||||
android:title="@string/mark_as_unread"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/cab_select_all"
|
||||
android:title="@string/select_all"
|
||||
|
|
Loading…
Reference in New Issue