@@ -4,7 +4,11 @@ import androidx.room.TypeConverter
44import com.google.gson.Gson
55import com.google.gson.reflect.TypeToken
66import org.fossify.commons.models.PhoneNumber
7- import org.fossify.commons.models.contacts.*
7+ import org.fossify.commons.models.contacts.Address
8+ import org.fossify.commons.models.contacts.Email
9+ import org.fossify.commons.models.contacts.Event
10+ import org.fossify.commons.models.contacts.IM
11+ import org.fossify.commons.models.contacts.PhoneNumberConverter
812
913class Converters {
1014 private val gson = Gson ()
@@ -36,9 +40,11 @@ class Converters {
3640 val numbers = gson.fromJson<ArrayList <PhoneNumber >>(value, numberType)
3741 return if (numbers.any { it.value == null }) {
3842 val phoneNumbers = ArrayList <PhoneNumber >()
39- val numberConverters = gson.fromJson<ArrayList <PhoneNumberConverter >>(value, numberConverterType)
43+ val numberConverters =
44+ gson.fromJson<ArrayList <PhoneNumberConverter >>(value, numberConverterType)
4045 numberConverters.forEach { converter ->
41- val phoneNumber = PhoneNumber (converter.a, converter.b, converter.c, converter.d, converter.e)
46+ val phoneNumber =
47+ PhoneNumber (converter.a, converter.b, converter.c, converter.d, converter.e)
4248 phoneNumbers.add(phoneNumber)
4349 }
4450 phoneNumbers
@@ -57,7 +63,25 @@ class Converters {
5763 fun emailListToJson (list : ArrayList <Email >): String = gson.toJson(list)
5864
5965 @TypeConverter
60- fun jsonToAddressList (value : String ): ArrayList <Address > = gson.fromJson(value, addressType)
66+ fun jsonToAddressList (value : String ): ArrayList <Address > {
67+ val addresses = gson.fromJson<ArrayList <Address >>(value, addressType)
68+ // This is a workaround for https://github.com/FossifyOrg/Contacts/issues/281
69+ return addresses.map {
70+ @Suppress(" USELESS_ELVIS" )
71+ it.copy(
72+ value = it.value,
73+ type = it.type,
74+ label = it.label,
75+ country = it.country ? : " " ,
76+ region = it.region ? : " " ,
77+ city = it.city ? : " " ,
78+ postcode = it.postcode ? : " " ,
79+ pobox = it.pobox ? : " " ,
80+ street = it.street ? : " " ,
81+ neighborhood = it.neighborhood ? : " "
82+ )
83+ }.toMutableList() as ArrayList <Address >
84+ }
6185
6286 @TypeConverter
6387 fun addressListToJson (list : ArrayList <Address >): String = gson.toJson(list)
0 commit comments