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,17 +1103,16 @@ 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,
val draftUri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}") showErrors = true
contentResolver.delete(draftUri, null, null) ) { cursor ->
} val draftId = cursor.getLongValue(Sms._ID)
} val draftUri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}")
} catch (e: Exception) { contentResolver.delete(draftUri, null, null)
showErrorToast(e)
} }
} }