diff --git a/app/src/main/java/org/linphone/contacts/ContactLoader.kt b/app/src/main/java/org/linphone/contacts/ContactLoader.kt index c7078ae85..48fb2d744 100644 --- a/app/src/main/java/org/linphone/contacts/ContactLoader.kt +++ b/app/src/main/java/org/linphone/contacts/ContactLoader.kt @@ -314,83 +314,16 @@ class ContactLoader : LoaderManager.LoaderCallbacks { } Log.i("$TAG Friends added") } else { + val friendsArray = friends.values.toTypedArray() Log.i( "$TAG Friend list [$NATIVE_ADDRESS_BOOK_FRIEND_LIST] found, synchronizing existing friends with new ones" ) - for (localFriend in friendsList.friends) { - val newlyFetchedFriend = friends[localFriend.refKey] - if (newlyFetchedFriend != null) { - friends.remove(localFriend.refKey) - localFriend.nativeUri = - newlyFetchedFriend.nativeUri // Native URI isn't stored in linphone database, needs to be updated - if (newlyFetchedFriend.dumpVcard() == localFriend.dumpVcard()) continue - - localFriend.edit() - // Update basic fields that may have changed - localFriend.name = newlyFetchedFriend.name - localFriend.organization = newlyFetchedFriend.organization - localFriend.jobTitle = newlyFetchedFriend.jobTitle - localFriend.photo = newlyFetchedFriend.photo - - // Clear local friend phone numbers & add all newly fetched one ones - var atLeastAPhoneNumberWasRemoved = false - for (phoneNumber in localFriend.phoneNumbersWithLabel) { - val found = newlyFetchedFriend.phoneNumbers.find { - it == phoneNumber.phoneNumber - } - if (found == null) { - atLeastAPhoneNumberWasRemoved = true - } - localFriend.removePhoneNumberWithLabel(phoneNumber) - } - for (phoneNumber in newlyFetchedFriend.phoneNumbersWithLabel) { - localFriend.addPhoneNumberWithLabel(phoneNumber) - } - - // If at least a phone number was removed, remove all SIP address from local friend before adding all from newly fetched one. - // If none was removed, simply add SIP addresses from fetched contact that aren't already in the local friend. - if (atLeastAPhoneNumberWasRemoved) { - Log.w( - "$TAG At least a phone number was removed from native contact [${localFriend.name}], clearing all SIP addresses from local friend before adding back the ones that still exists" - ) - for (sipAddress in localFriend.addresses) { - localFriend.removeAddress(sipAddress) - } - } - - // Adding only newly added SIP address(es) in native contact if any - for (sipAddress in newlyFetchedFriend.addresses) { - localFriend.addAddress(sipAddress) - } - localFriend.done() - } else { - Log.i( - "$TAG Friend [${localFriend.name}] with ref key [${localFriend.refKey}] not found in newly fetched batch, removing it" - ) - friendsList.removeFriend(localFriend) - } + val changes = friendsList.synchronizeFriendsWith(friendsArray) + if (changes) { + Log.i("$TAG Locally stored friends synchronized with native address book") + } else { + Log.i("$TAG No changes detected between native address book and local friends storage") } - - // Check for newly created friends since last sync - val localFriends = friendsList.friends - for ((key, newFriend) in friends.entries) { - val found = localFriends.find { - it.refKey == key - } - if (found == null) { - if (newFriend.refKey == null) { - Log.w( - "$TAG Found friend [${newFriend.name}] with no refKey, using ID [$key]" - ) - newFriend.refKey = key - } - Log.i( - "$TAG Friend [${newFriend.name}] with ref key [${newFriend.refKey}] not found in currently stored list, adding it" - ) - friendsList.addLocalFriend(newFriend) - } - } - Log.i("$TAG Friends synchronized") } friends.clear() diff --git a/app/src/main/java/org/linphone/ui/main/help/viewmodel/HelpViewModel.kt b/app/src/main/java/org/linphone/ui/main/help/viewmodel/HelpViewModel.kt index 68f9453c7..9c4d050ed 100644 --- a/app/src/main/java/org/linphone/ui/main/help/viewmodel/HelpViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/help/viewmodel/HelpViewModel.kt @@ -29,7 +29,6 @@ import org.linphone.BuildConfig import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.R -import org.linphone.contacts.ContactLoader.Companion.NATIVE_ADDRESS_BOOK_FRIEND_LIST import org.linphone.core.Core import org.linphone.core.CoreListenerStub import org.linphone.core.VersionUpdateCheckResult @@ -251,20 +250,4 @@ class HelpViewModel } } } - - @UiThread - fun clearNativeFriendsDatabase() { - coreContext.postOnCoreThread { core -> - val list = core.getFriendListByName(NATIVE_ADDRESS_BOOK_FRIEND_LIST) - if (list != null) { - val friends = list.friends - Log.i("$TAG Friend list to remove found with [${friends.size}] friends") - for (friend in friends) { - list.removeFriend(friend) - } - core.removeFriendList(list) - Log.i("$TAG Friend list [$NATIVE_ADDRESS_BOOK_FRIEND_LIST] removed") - } - } - } } diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt index ee04deee2..4d3e84efc 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt @@ -29,6 +29,7 @@ import androidx.lifecycle.MutableLiveData import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.R +import org.linphone.contacts.ContactLoader.Companion.NATIVE_ADDRESS_BOOK_FRIEND_LIST import org.linphone.core.AudioDevice import org.linphone.core.Conference import org.linphone.core.Core @@ -1181,4 +1182,21 @@ class SettingsViewModel corePreferences.pushNotificationCompatibleDomains = newList } } + + @UiThread + fun clearNativeFriendsDatabase() { + coreContext.postOnCoreThread { core -> + val list = core.getFriendListByName(NATIVE_ADDRESS_BOOK_FRIEND_LIST) + if (list != null) { + val friends = list.friends + Log.i("$TAG Friend list to remove found with [${friends.size}] friends") + for (friend in friends) { + list.removeFriend(friend) + } + core.removeFriendList(list) + Log.i("$TAG Friend list [$NATIVE_ADDRESS_BOOK_FRIEND_LIST] removed") + } + showGreenToast(R.string.settings_developer_cleared_native_friends_in_database_toast, R.drawable.trash_simple) + } + } } diff --git a/app/src/main/res/layout/help_debug_fragment.xml b/app/src/main/res/layout/help_debug_fragment.xml index 2d1f60a0d..72354a705 100644 --- a/app/src/main/res/layout/help_debug_fragment.xml +++ b/app/src/main/res/layout/help_debug_fragment.xml @@ -295,27 +295,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/firebase_project_subtitle"/> - - diff --git a/app/src/main/res/layout/settings_developer_fragment.xml b/app/src/main/res/layout/settings_developer_fragment.xml index b5b148522..1b3b3271a 100644 --- a/app/src/main/res/layout/settings_developer_fragment.xml +++ b/app/src/main/res/layout/settings_developer_fragment.xml @@ -270,6 +270,39 @@ app:layout_constraintStart_toStartOf="@id/push_compatible_domains_list_label" app:layout_constraintEnd_toEndOf="parent"/> + + + + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2add14319..d0d21864d 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -186,7 +186,6 @@ Les journaux ont été nettoyés Échec à l\'envoi des journaux Afficher la configuration - Supprimer les contacts natifs importés Paramètres @@ -318,6 +317,9 @@ Paramètres développeurs déjà activés Activer l\'indicateur des volumes d\'enregistrement et de lecture Liste des domaines qui supportent les notifications poussées (séparés par des virgules) + Supprimer les contacts natifs importés + Ils seront synchronisés à nouveau au prochain démarrage de l\'application sauf si vous retirez la permission de lire les contacts + Contacts importés supprimés Mon compte diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 904b2d6c7..f658a6f8f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -228,7 +228,6 @@ Debug logs have been cleaned Failed to upload debug logs Show configuration - Clear imported contacts from native address book Settings @@ -360,6 +359,9 @@ Developer settings already enabled Enable record/playback volume vu meters while in call List of push notifications compatible domains (comma separated) + Clear imported contacts from native address book + They will be imported again the next time the app starts unless you remove the contacts permission + Imported contacts have been deleted Manage account