add a Mark as Unread menu item at the thread screen
This commit is contained in:
parent
21891ff677
commit
22b6040a86
|
@ -199,6 +199,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
R.id.block_number -> blockNumber()
|
||||
R.id.delete -> askConfirmDelete()
|
||||
R.id.manage_people -> managePeople()
|
||||
R.id.mark_as_unread -> markAsUnread()
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
|
@ -392,6 +393,16 @@ class ThreadActivity : SimpleActivity() {
|
|||
showSelectedContacts()
|
||||
}
|
||||
|
||||
private fun markAsUnread() {
|
||||
ensureBackgroundThread {
|
||||
conversationsDB.markUnread(threadId.toLong())
|
||||
markThreadMessagesUnread(threadId)
|
||||
runOnUiThread {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun getThreadItems(): ArrayList<ThreadItem> {
|
||||
messages.sortBy { it.date }
|
||||
|
|
|
@ -511,6 +511,18 @@ fun Context.markThreadMessagesRead(threadId: Int) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.markThreadMessagesUnread(threadId: Int) {
|
||||
arrayOf(Mms.CONTENT_URI, Sms.CONTENT_URI).forEach { uri ->
|
||||
val contentValues = ContentValues().apply {
|
||||
put(Sms.READ, 0)
|
||||
put(Sms.SEEN, 0)
|
||||
}
|
||||
val selection = "${Sms.THREAD_ID} = ?"
|
||||
val selectionArgs = arrayOf(threadId.toString())
|
||||
contentResolver.update(uri, contentValues, selection, selectionArgs)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun Context.getThreadId(address: String): Long {
|
||||
return if (isMarshmallowPlus()) {
|
||||
|
|
|
@ -17,6 +17,9 @@ interface ConversationsDao {
|
|||
@Query("UPDATE conversations SET read = 1 WHERE thread_id = :threadId")
|
||||
fun markRead(threadId: Long)
|
||||
|
||||
@Query("UPDATE conversations SET read = 0 WHERE thread_id = :threadId")
|
||||
fun markUnread(threadId: Long)
|
||||
|
||||
@Query("DELETE FROM conversations WHERE id = :id")
|
||||
fun delete(id: Long)
|
||||
|
||||
|
|
|
@ -16,4 +16,8 @@
|
|||
android:icon="@drawable/ic_block_vector"
|
||||
android:title="@string/block_number"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/mark_as_unread"
|
||||
android:title="@string/mark_as_unread"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
|
Loading…
Reference in New Issue