diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Converters.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Converters.kt index 61250623..ee8aa14c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Converters.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Converters.kt @@ -4,16 +4,14 @@ import androidx.room.TypeConverter import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.models.PhoneNumber -import com.simplemobiletools.contacts.pro.models.Address -import com.simplemobiletools.contacts.pro.models.Email -import com.simplemobiletools.contacts.pro.models.Event -import com.simplemobiletools.contacts.pro.models.IM +import com.simplemobiletools.contacts.pro.models.* class Converters { private val gson = Gson() private val longType = object : TypeToken>() {}.type private val stringType = object : TypeToken>() {}.type private val numberType = object : TypeToken>() {}.type + private val numberConverterType = object : TypeToken>() {}.type private val emailType = object : TypeToken>() {}.type private val addressType = object : TypeToken>() {}.type private val eventType = object : TypeToken>() {}.type @@ -31,8 +29,23 @@ class Converters { @TypeConverter fun longListToJson(list: ArrayList) = gson.toJson(list) + // some hacky converting is needed since PhoneNumber model has been added to proguard rules, but obfuscated json was stored in database + // convert [{"a":"678910","b":2,"c":"","d":"678910","e":false}] to PhoneNumber(value=678910, type=2, label=, normalizedNumber=678910, isPrimary=false) @TypeConverter - fun jsonToPhoneNumberList(value: String) = gson.fromJson>(value, numberType) + fun jsonToPhoneNumberList(value: String): ArrayList { + val numbers = gson.fromJson>(value, numberType) + return if (numbers.any { it.value == null }) { + val phoneNumbers = ArrayList() + val numberConverters = gson.fromJson>(value, numberConverterType) + numberConverters.forEach { converter -> + val phoneNumber = PhoneNumber(converter.a, converter.b, converter.c, converter.d, converter.e) + phoneNumbers.add(phoneNumber) + } + phoneNumbers + } else { + numbers + } + } @TypeConverter fun phoneNumberListToJson(list: ArrayList) = gson.toJson(list) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/PhoneNumberConverter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/PhoneNumberConverter.kt new file mode 100644 index 00000000..d2072389 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/PhoneNumberConverter.kt @@ -0,0 +1,4 @@ +package com.simplemobiletools.contacts.pro.models + +// need for hacky parsing of no longer minified PhoneNumber model in Converters.kt +data class PhoneNumberConverter(var a: String, var b: Int, var c: String, var d: String, var e: Boolean = false)