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.block_number -> blockNumber()
|
||||||
R.id.delete -> askConfirmDelete()
|
R.id.delete -> askConfirmDelete()
|
||||||
R.id.manage_people -> managePeople()
|
R.id.manage_people -> managePeople()
|
||||||
|
R.id.mark_as_unread -> markAsUnread()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -392,6 +393,16 @@ class ThreadActivity : SimpleActivity() {
|
||||||
showSelectedContacts()
|
showSelectedContacts()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun markAsUnread() {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
conversationsDB.markUnread(threadId.toLong())
|
||||||
|
markThreadMessagesUnread(threadId)
|
||||||
|
runOnUiThread {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun getThreadItems(): ArrayList<ThreadItem> {
|
private fun getThreadItems(): ArrayList<ThreadItem> {
|
||||||
messages.sortBy { it.date }
|
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")
|
@SuppressLint("NewApi")
|
||||||
fun Context.getThreadId(address: String): Long {
|
fun Context.getThreadId(address: String): Long {
|
||||||
return if (isMarshmallowPlus()) {
|
return if (isMarshmallowPlus()) {
|
||||||
|
|
|
@ -17,6 +17,9 @@ interface ConversationsDao {
|
||||||
@Query("UPDATE conversations SET read = 1 WHERE thread_id = :threadId")
|
@Query("UPDATE conversations SET read = 1 WHERE thread_id = :threadId")
|
||||||
fun markRead(threadId: Long)
|
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")
|
@Query("DELETE FROM conversations WHERE id = :id")
|
||||||
fun delete(id: Long)
|
fun delete(id: Long)
|
||||||
|
|
||||||
|
|
|
@ -16,4 +16,8 @@
|
||||||
android:icon="@drawable/ic_block_vector"
|
android:icon="@drawable/ic_block_vector"
|
||||||
android:title="@string/block_number"
|
android:title="@string/block_number"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/mark_as_unread"
|
||||||
|
android:title="@string/mark_as_unread"
|
||||||
|
app:showAsAction="never" />
|
||||||
</menu>
|
</menu>
|
||||||
|
|
Loading…
Reference in New Issue