From 2cee1aadef402c7e3cd2f7c39c1347f5fbdc91c1 Mon Sep 17 00:00:00 2001 From: Thomas More Date: Wed, 3 Apr 2024 14:14:05 -0400 Subject: [PATCH] Refactor call log import code and tweak UI --- .../github/tmo1/sms_ie/ImportExportCallLog.kt | 74 ++++++++++--------- app/src/main/res/values/strings.xml | 5 +- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/github/tmo1/sms_ie/ImportExportCallLog.kt b/app/src/main/java/com/github/tmo1/sms_ie/ImportExportCallLog.kt index c95bbc4..fc712c1 100644 --- a/app/src/main/java/com/github/tmo1/sms_ie/ImportExportCallLog.kt +++ b/app/src/main/java/com/github/tmo1/sms_ie/ImportExportCallLog.kt @@ -131,6 +131,9 @@ suspend fun importCallLog( val callLogMetadata = ContentValues() try { jsonReader.beginArray() + setStatusText( + statusReportText, appContext.getString(R.string.importing_calls) + ) JSONReader@ while (jsonReader.hasNext()) { jsonReader.beginObject() callLogMetadata.clear() @@ -145,50 +148,49 @@ suspend fun importCallLog( } } jsonReader.endObject() - if (deduplication) { - val callDuplicatesCursor = appContext.contentResolver.query( - CallLog.Calls.CONTENT_URI, - arrayOf(CallLog.Calls._ID), - "${CallLog.Calls.NUMBER}=? AND ${CallLog.Calls.TYPE}=? AND ${CallLog.Calls.DATE}=?", - arrayOf( - callLogMetadata.getAsString(CallLog.Calls.NUMBER), - callLogMetadata.getAsString(CallLog.Calls.TYPE), - callLogMetadata.getAsString(CallLog.Calls.DATE) - - ), - null - ) - val isDuplicate = callDuplicatesCursor?.use { _ -> - if (callDuplicatesCursor.moveToFirst()) { - Log.d(LOG_TAG, "Duplicate call - skipping") - true - } else { - false - } - } - if (isDuplicate == true) { - continue@JSONReader - } - } - var insertUri: Uri? = null if (callLogMetadata.keySet() .contains(CallLog.Calls.NUMBER) && callLogMetadata.getAsString( CallLog.Calls.TYPE ) != "4" ) { - insertUri = appContext.contentResolver.insert( + if (deduplication) { + val callDuplicatesCursor = appContext.contentResolver.query( + CallLog.Calls.CONTENT_URI, + arrayOf(CallLog.Calls._ID), + "${CallLog.Calls.NUMBER}=? AND ${CallLog.Calls.TYPE}=? AND ${CallLog.Calls.DATE}=?", + arrayOf( + callLogMetadata.getAsString(CallLog.Calls.NUMBER), + callLogMetadata.getAsString(CallLog.Calls.TYPE), + callLogMetadata.getAsString(CallLog.Calls.DATE) + + ), + null + ) + val isDuplicate = callDuplicatesCursor?.use { _ -> + if (callDuplicatesCursor.moveToFirst()) { + Log.d(LOG_TAG, "Duplicate call - skipping") + true + } else { + false + } + } + if (isDuplicate == true) { + continue@JSONReader + } + } + val insertUri = appContext.contentResolver.insert( CallLog.Calls.CONTENT_URI, callLogMetadata ) - } - if (insertUri == null) { - Log.v(LOG_TAG, "Call log insert failed!") - } else { - callLogCount++ - setStatusText( - statusReportText, appContext.getString( - R.string.call_log_import_progress, callLogCount + if (insertUri == null) { + Log.v(LOG_TAG, "Call insert failed!") + } else { + callLogCount++ + setStatusText( + statusReportText, appContext.getString( + R.string.call_log_import_progress, callLogCount + ) ) - ) + } } } jsonReader.endArray() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 806eaed..80b68ce 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -89,12 +89,13 @@ About Export Contacts Import Contacts - Copying MMS binary data ... - Importing messages ... + Copying MMS binary data … + Importing messages … SMS Import / Export must be the default SMS app in order to import or wipe messages. Please read the README and make sure you understand the implications of doing this before proceeding. OK Default SMS App Importing messages is only possible on Android Marshmallow / 6.0 (API level 23) or later. Warning: This app is currently the default SMS app, which means that any incoming SMS or MMS messages will be lost! To avoid this, set a proper default SMS app. Set default SMS app + Importing calls …