Fixed contact order when accents are present + other fixes & improvements over contacts

This commit is contained in:
Sylvain Berfini 2020-07-01 10:40:11 +02:00
parent cfd11a40ec
commit a106da7cc5
8 changed files with 39 additions and 13 deletions

View file

@ -23,7 +23,7 @@ import androidx.lifecycle.ViewModel
import org.linphone.core.Address import org.linphone.core.Address
class ContactNumberOrAddressViewModel( class ContactNumberOrAddressViewModel(
val address: Address, val address: Address?,
val hasPresence: Boolean, val hasPresence: Boolean,
val displayedValue: String, val displayedValue: String,
val isSip: Boolean = true, val isSip: Boolean = true,
@ -33,10 +33,12 @@ class ContactNumberOrAddressViewModel(
val showInvite = !hasPresence && !isSip val showInvite = !hasPresence && !isSip
fun startCall() { fun startCall() {
address ?: return
listener.onCall(address) listener.onCall(address)
} }
fun startChat(secured: Boolean) { fun startChat(secured: Boolean) {
address ?: return
listener.onChat(address, secured) listener.onChat(address, secured)
} }

View file

@ -176,7 +176,7 @@ class ContactViewModel(private val c: Contact) : ErrorReportingViewModel(), Cont
val presenceModel = c.friend?.getPresenceModelForUriOrTel(number) val presenceModel = c.friend?.getPresenceModelForUriOrTel(number)
val hasPresence = presenceModel != null && presenceModel.basicStatus == PresenceBasicStatus.Open val hasPresence = presenceModel != null && presenceModel.basicStatus == PresenceBasicStatus.Open
val contactAddress = presenceModel?.contact ?: number val contactAddress = presenceModel?.contact ?: number
val address = coreContext.core.interpretUrl(contactAddress) ?: continue val address = coreContext.core.interpretUrl(contactAddress)
val isMe = coreContext.core.defaultProxyConfig?.identityAddress?.weakEqual(address) ?: false val isMe = coreContext.core.defaultProxyConfig?.identityAddress?.weakEqual(address) ?: false
val secureChatAllowed = !isMe && c.friend?.getPresenceModelForUriOrTel(number)?.hasCapability(FriendCapability.LimeX3Dh) ?: false val secureChatAllowed = !isMe && c.friend?.getPresenceModelForUriOrTel(number)?.hasCapability(FriendCapability.LimeX3Dh) ?: false
val noa = ContactNumberOrAddressViewModel(address, hasPresence, number, isSip = false, showSecureChat = secureChatAllowed, listener = listener) val noa = ContactNumberOrAddressViewModel(address, hasPresence, number, isSip = false, showSecureChat = secureChatAllowed, listener = listener)

View file

@ -24,6 +24,7 @@ import android.graphics.Bitmap
import android.net.Uri import android.net.Uri
import androidx.core.app.Person import androidx.core.app.Person
import androidx.core.graphics.drawable.IconCompat import androidx.core.graphics.drawable.IconCompat
import java.text.Collator
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R import org.linphone.R
import org.linphone.core.Address import org.linphone.core.Address
@ -76,7 +77,9 @@ open class Contact : Comparable<Contact> {
val otherOrg = other.organization ?: "" val otherOrg = other.organization ?: ""
return org.compareTo(otherOrg) return org.compareTo(otherOrg)
} }
return fn.compareTo(otherFn) val collator = Collator.getInstance()
collator.strength = Collator.NO_DECOMPOSITION
return collator.compare(fn, otherFn)
} }
@Synchronized @Synchronized

View file

@ -110,7 +110,7 @@ class NativeContact(val nativeId: String, private val lookupKey: String? = null)
Log.d("[Native Contact] Found phone number $data1 ($data4)") Log.d("[Native Contact] Found phone number $data1 ($data4)")
val number = data4 ?: data1 val number = data4 ?: data1
if (number != null && !phoneNumbers.contains(number)) phoneNumbers.add(number) if (number != null && number.isNotEmpty() && !phoneNumbers.contains(number)) phoneNumbers.add(number)
} }
linphoneMime, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> { linphoneMime, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
if (data1 == null) { if (data1 == null) {

View file

@ -130,7 +130,7 @@ class NativeContactEditor(
fun setOrganization(value: String): NativeContactEditor { fun setOrganization(value: String): NativeContactEditor {
val previousValue = contact.organization val previousValue = contact.organization
if (value == previousValue) { if (value == previousValue) {
Log.w("[Native Contact Editor] Organization hasn't changed") Log.d("[Native Contact Editor] Organization hasn't changed")
return this return this
} }
@ -170,8 +170,11 @@ class NativeContactEditor(
when { when {
phoneNumber.currentValue.isEmpty() -> { phoneNumber.currentValue.isEmpty() -> {
// New phone number to add // New phone number to add
val number = phoneNumber.newValue.value.orEmpty()
if (number.isNotEmpty()) {
addCount++ addCount++
addPhoneNumber(phoneNumber.newValue.value.orEmpty()) addPhoneNumber(number)
}
} }
phoneNumber.toRemove.value == true -> { phoneNumber.toRemove.value == true -> {
// Existing number to remove // Existing number to remove
@ -180,8 +183,11 @@ class NativeContactEditor(
} }
phoneNumber.currentValue != phoneNumber.newValue.value -> { phoneNumber.currentValue != phoneNumber.newValue.value -> {
// Existing number to update // Existing number to update
val number = phoneNumber.newValue.value.orEmpty()
if (number.isNotEmpty()) {
editCount++ editCount++
updatePhoneNumber(phoneNumber.currentValue, phoneNumber.newValue.value.orEmpty()) updatePhoneNumber(phoneNumber.currentValue, number)
}
} }
} }
} }
@ -199,10 +205,12 @@ class NativeContactEditor(
when { when {
sipAddress.currentValue.isEmpty() -> { sipAddress.currentValue.isEmpty() -> {
// New address to add // New address to add
addCount++
val address = sipAddress.newValue.value.orEmpty() val address = sipAddress.newValue.value.orEmpty()
if (address.isNotEmpty()) {
addCount++
addSipAddress(address) addSipAddress(address)
} }
}
sipAddress.toRemove.value == true -> { sipAddress.toRemove.value == true -> {
// Existing address to remove // Existing address to remove
removeCount++ removeCount++
@ -210,8 +218,11 @@ class NativeContactEditor(
} }
sipAddress.currentValue != sipAddress.newValue.value -> { sipAddress.currentValue != sipAddress.newValue.value -> {
// Existing address to update // Existing address to update
val address = sipAddress.newValue.value.orEmpty()
if (address.isNotEmpty()) {
editCount++ editCount++
updateLinphoneOrSipAddress(sipAddress.currentValue, sipAddress.newValue.value.orEmpty()) updateLinphoneOrSipAddress(sipAddress.currentValue, address)
}
} }
} }
} }

View file

@ -2,6 +2,8 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" <item android:state_pressed="true"
android:drawable="@drawable/round_orange_button_background_over" /> android:drawable="@drawable/round_orange_button_background_over" />
<item android:state_enabled="false"
android:drawable="@drawable/round_orange_button_background_disabled" />
<item <item
android:drawable="@drawable/round_orange_button_background_default" /> android:drawable="@drawable/round_orange_button_background_default" />
</selector> </selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/grey_color"/>
<size android:width="30dp" android:height="30dp"/>
</shape>

View file

@ -80,6 +80,7 @@
<ImageView <ImageView
android:onClick="@{() -> data.startCall()}" android:onClick="@{() -> data.startCall()}"
android:enabled="@{data.address != null}"
android:contentDescription="@string/content_description_start_call" android:contentDescription="@string/content_description_start_call"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
@ -89,6 +90,7 @@
<ImageView <ImageView
android:onClick="@{() -> data.startChat(false)}" android:onClick="@{() -> data.startChat(false)}"
android:enabled="@{data.address != null}"
android:contentDescription="@string/content_description_start_chat" android:contentDescription="@string/content_description_start_chat"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
@ -98,6 +100,7 @@
<RelativeLayout <RelativeLayout
android:visibility="@{data.showSecureChat ? View.VISIBLE : View.GONE}" android:visibility="@{data.showSecureChat ? View.VISIBLE : View.GONE}"
android:enabled="@{data.address != null}"
android:onClick="@{() -> data.startChat(true)}" android:onClick="@{() -> data.startChat(true)}"
android:layout_width="65dp" android:layout_width="65dp"
android:layout_height="60dp" android:layout_height="60dp"