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,18 +1103,17 @@ fun Context.deleteSmsDraft(threadId: Long) {
val projection = arrayOf(Sms._ID)
val selection = "${Sms.THREAD_ID} = ?"
val selectionArgs = arrayOf(threadId.toString())
try {
val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
cursor?.use {
while (cursor.moveToNext()) {
val draftId = cursor.getLong(0)
queryCursor(
uri = uri,
projection = projection,
selection = selection,
selectionArgs = selectionArgs,
showErrors = true
) { cursor ->
val draftId = cursor.getLongValue(Sms._ID)
val draftUri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}")
contentResolver.delete(draftUri, null, null)
}
}
} catch (e: Exception) {
showErrorToast(e)
}
}
fun Context.updateLastConversationMessage(threadId: Long) {