From 4582bc5289d4d7fa1a0302d0593cf01d4f60b126 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sat, 30 Sep 2023 02:21:49 +0530 Subject: [PATCH] Properly clear messages from database --- .../smsmessenger/activities/MainActivity.kt | 6 +++--- .../smsmessenger/activities/ThreadActivity.kt | 5 +++-- .../simplemobiletools/smsmessenger/extensions/Context.kt | 7 +++++-- .../simplemobiletools/smsmessenger/helpers/Constants.kt | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt index 5cb95884..5c8303be 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt @@ -64,7 +64,9 @@ class MainActivity : SimpleActivity() { handleAppPasswordProtection { wasProtectionHandled = it if (it) { - loadMessages() + clearAllMessagesIfNeeded { + loadMessages() + } } else { finish() } @@ -74,8 +76,6 @@ class MainActivity : SimpleActivity() { if (checkAppSideloading()) { return } - - clearAllMessagesIfNeeded() } override fun onResume() { diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index 4f3a90b0..71505fee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -136,7 +136,6 @@ class ThreadActivity : SimpleActivity() { return } - clearAllMessagesIfNeeded() threadId = intent.getLongExtra(THREAD_ID, 0L) intent.getStringExtra(THREAD_TITLE)?.let { binding.threadToolbar.title = it @@ -152,7 +151,9 @@ class ThreadActivity : SimpleActivity() { handleAppPasswordProtection { wasProtectionHandled = it if (it) { - loadConversation() + clearAllMessagesIfNeeded { + loadConversation() + } } else { finish() } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index 3902bcd6..39ff6210 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -989,12 +989,15 @@ fun Context.getFileSizeFromUri(uri: Uri): Long { // fix a glitch at enabling Release version minifying from 5.12.3 // reset messages in 5.14.3 again, as PhoneNumber is no longer minified // reset messages in 5.19.1 again, as SimpleContact is no longer minified -fun Context.clearAllMessagesIfNeeded() { +fun Context.clearAllMessagesIfNeeded(callback: () -> Unit) { if (!config.wasDbCleared) { ensureBackgroundThread { messagesDB.deleteAll() + config.wasDbCleared = true + callback() } - config.wasDbCleared = true + } else { + callback() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt index a32d6883..0127ac34 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt @@ -34,7 +34,7 @@ const val XML_MIME_TYPE = "text/xml" const val TXT_MIME_TYPE = "text/plain" const val IMPORT_SMS = "import_sms" const val IMPORT_MMS = "import_mms" -const val WAS_DB_CLEARED = "was_db_cleared_3" +const val WAS_DB_CLEARED = "was_db_cleared_4" const val EXTRA_VCARD_URI = "vcard" const val SCHEDULED_MESSAGE_ID = "scheduled_message_id" const val SOFT_KEYBOARD_HEIGHT = "soft_keyboard_height"