Use queryCursor extension for deleting drafts

This commit is contained in:
Naveen Singh 2024-12-27 16:38:55 +05:30
parent 757d849875
commit be553f0b10
No known key found for this signature in database
GPG key ID: AF5D43C216778C0B

View file

@ -1103,19 +1103,18 @@ fun Context.deleteSmsDraft(threadId: Long) {
val projection = arrayOf(Sms._ID) val projection = arrayOf(Sms._ID)
val selection = "${Sms.THREAD_ID} = ?" val selection = "${Sms.THREAD_ID} = ?"
val selectionArgs = arrayOf(threadId.toString()) val selectionArgs = arrayOf(threadId.toString())
try { queryCursor(
val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null) uri = uri,
cursor?.use { projection = projection,
while (cursor.moveToNext()) { selection = selection,
val draftId = cursor.getLong(0) selectionArgs = selectionArgs,
showErrors = true
) { cursor ->
val draftId = cursor.getLongValue(Sms._ID)
val draftUri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}") val draftUri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}")
contentResolver.delete(draftUri, null, null) contentResolver.delete(draftUri, null, null)
} }
} }
} catch (e: Exception) {
showErrorToast(e)
}
}
fun Context.updateLastConversationMessage(threadId: Long) { fun Context.updateLastConversationMessage(threadId: Long) {
// update the date and the snippet of the thread, by triggering the // update the date and the snippet of the thread, by triggering the