Merge pull request #656 from kcotugno/fix-json-import-partial-export
Fix import for partial exports
This commit is contained in:
commit
816d15b999
1 changed files with 32 additions and 32 deletions
|
|
@ -1,12 +1,16 @@
|
||||||
package com.simplemobiletools.smsmessenger.helpers
|
package com.simplemobiletools.smsmessenger.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.util.JsonToken
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.smsmessenger.extensions.*
|
import com.simplemobiletools.smsmessenger.extensions.config
|
||||||
import com.simplemobiletools.smsmessenger.helpers.MessagesImporter.ImportResult.*
|
import com.simplemobiletools.smsmessenger.helpers.MessagesImporter.ImportResult.IMPORT_FAIL
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.MessagesImporter.ImportResult.IMPORT_NOTHING_NEW
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.MessagesImporter.ImportResult.IMPORT_OK
|
||||||
|
import com.simplemobiletools.smsmessenger.helpers.MessagesImporter.ImportResult.IMPORT_PARTIAL
|
||||||
import com.simplemobiletools.smsmessenger.models.MmsBackup
|
import com.simplemobiletools.smsmessenger.models.MmsBackup
|
||||||
import com.simplemobiletools.smsmessenger.models.SmsBackup
|
import com.simplemobiletools.smsmessenger.models.SmsBackup
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
@ -40,43 +44,39 @@ class MessagesImporter(private val context: Context) {
|
||||||
while (jsonReader.hasNext()) {
|
while (jsonReader.hasNext()) {
|
||||||
jsonReader.beginObject()
|
jsonReader.beginObject()
|
||||||
while (jsonReader.hasNext()) {
|
while (jsonReader.hasNext()) {
|
||||||
if (jsonReader.nextName().equals("sms")) {
|
val nextToken = jsonReader.peek()
|
||||||
if (config.importSms) {
|
if (nextToken.ordinal == JsonToken.NAME.ordinal) {
|
||||||
jsonReader.beginArray()
|
val msgType = jsonReader.nextName()
|
||||||
while (jsonReader.hasNext()) {
|
|
||||||
try {
|
if ((!msgType.equals("sms") && !msgType.equals("mms")) ||
|
||||||
|
(msgType.equals("sms") && !config.importSms) ||
|
||||||
|
(msgType.equals("mms") && !config.importMms)
|
||||||
|
) {
|
||||||
|
jsonReader.skipValue()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonReader.beginArray()
|
||||||
|
while (jsonReader.hasNext()) {
|
||||||
|
try {
|
||||||
|
if (msgType.equals("sms")) {
|
||||||
val message = gson.fromJson<SmsBackup>(jsonReader, smsMessageType)
|
val message = gson.fromJson<SmsBackup>(jsonReader, smsMessageType)
|
||||||
messageWriter.writeSmsMessage(message)
|
messageWriter.writeSmsMessage(message)
|
||||||
messagesImported++
|
} else {
|
||||||
} catch (e: Exception) {
|
|
||||||
context.showErrorToast(e)
|
|
||||||
messagesFailed++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsonReader.endArray()
|
|
||||||
} else {
|
|
||||||
jsonReader.skipValue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jsonReader.nextName().equals("mms")) {
|
|
||||||
if (config.importMms) {
|
|
||||||
jsonReader.beginArray()
|
|
||||||
|
|
||||||
while (jsonReader.hasNext()) {
|
|
||||||
try {
|
|
||||||
val message = gson.fromJson<MmsBackup>(jsonReader, mmsMessageType)
|
val message = gson.fromJson<MmsBackup>(jsonReader, mmsMessageType)
|
||||||
messageWriter.writeMmsMessage(message)
|
messageWriter.writeMmsMessage(message)
|
||||||
messagesImported++
|
|
||||||
} catch (e: Exception) {
|
|
||||||
context.showErrorToast(e)
|
|
||||||
messagesFailed++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
messagesImported++
|
||||||
|
} catch (e: Exception) {
|
||||||
|
context.showErrorToast(e)
|
||||||
|
messagesFailed++
|
||||||
|
|
||||||
}
|
}
|
||||||
jsonReader.endArray()
|
|
||||||
} else {
|
|
||||||
jsonReader.skipValue()
|
|
||||||
}
|
}
|
||||||
|
jsonReader.endArray()
|
||||||
|
} else {
|
||||||
|
jsonReader.skipValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue