From be553f0b102b943f78ad5ac7b2076c24b3c8b48d Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Fri, 27 Dec 2024 16:38:55 +0530 Subject: [PATCH] Use `queryCursor` extension for deleting drafts --- .../fossify/messages/extensions/Context.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt b/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt index a768cea1..27ce85e1 100644 --- a/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt +++ b/app/src/main/kotlin/org/fossify/messages/extensions/Context.kt @@ -1103,17 +1103,16 @@ 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) - val draftUri = Uri.withAppendedPath(Sms.CONTENT_URI, "/${draftId}") - contentResolver.delete(draftUri, null, null) - } - } - } catch (e: Exception) { - showErrorToast(e) + 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) } }