Skip to content

Commit

Permalink
Refactor call log import code and tweak UI
Browse files Browse the repository at this point in the history
  • Loading branch information
tmo1 committed Apr 3, 2024
1 parent bb94c00 commit 2cee1aa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
74 changes: 38 additions & 36 deletions app/src/main/java/com/github/tmo1/sms_ie/ImportExportCallLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@
<string name="about">About</string>
<string name="export_contacts">Export Contacts</string>
<string name="import_contacts">Import Contacts</string>
<string name="copying_mms_binary_data">Copying MMS binary data ...</string>
<string name="importing_messages">Importing messages ...</string>
<string name="copying_mms_binary_data">Copying MMS binary data </string>
<string name="importing_messages">Importing messages </string>
<string name="become_default_sms_app_warning">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.</string>
<string name="okay">OK</string>
<string name="default_sms_app_dialog_title">Default SMS App</string>
<string name="message_import_api_23_requirement">Importing messages is only possible on Android Marshmallow / 6.0 (API level 23) or later.</string>
<string name="default_sms_app_warning"><b>Warning</b>: 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.</string>
<string name="set_default_sms_app">Set default SMS app</string>
<string name="importing_calls">Importing calls …</string>
</resources>

0 comments on commit 2cee1aa

Please sign in to comment.