Edit native contacts in native contact app

This commit is contained in:
Sylvain Berfini 2023-08-16 16:27:58 +02:00
parent 2ef56c0cbb
commit cc4bc0c3b0
3 changed files with 44 additions and 0 deletions

View file

@ -22,7 +22,10 @@ package org.linphone.ui.main.contacts.fragment
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.ContactsContract
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -120,6 +123,22 @@ class ContactFragment : GenericFragment() {
dialog.show()
}
}
viewModel.openNativeContactEditor.observe(viewLifecycleOwner) {
it.consume { uri ->
val editIntent = Intent(Intent.ACTION_EDIT).apply {
setDataAndType(Uri.parse(uri), ContactsContract.Contacts.CONTENT_ITEM_TYPE)
putExtra("finishActivityOnSaveCompleted", true)
}
startActivity(editIntent)
}
}
viewModel.openLinphoneContactEditor.observe(viewLifecycleOwner) {
it.consume {
// TODO
}
}
}
private fun copyNumberOrAddressToClipboard(value: String, isSip: Boolean) {

View file

@ -56,6 +56,14 @@ class ContactViewModel : ViewModel() {
MutableLiveData<Event<Boolean>>()
}
val openNativeContactEditor: MutableLiveData<Event<String>> by lazy {
MutableLiveData<Event<String>>()
}
val openLinphoneContactEditor: MutableLiveData<Event<String>> by lazy {
MutableLiveData<Event<String>>()
}
val listener = object : ContactNumberOrAddressClickListener {
override fun onClicked(address: Address?) {
// UI thread
@ -130,14 +138,27 @@ class ContactViewModel : ViewModel() {
}
fun toggleNumbersAndAddressesVisibility() {
// UI thread
showNumbersAndAddresses.value = showNumbersAndAddresses.value == false
}
fun toggleDevicesTrustVisibility() {
// UI thread
showDevicesTrust.value = showDevicesTrust.value == false
}
fun editContact() {
// UI thread
val uri = contact.value?.friend?.nativeUri
if (uri != null) {
openNativeContactEditor.value = Event(uri)
} else {
openLinphoneContactEditor.value = Event(contact.value?.id.orEmpty())
}
}
fun startAudioCall() {
// UI thread
val numbersAndAddresses = sipAddressesAndPhoneNumbers.value.orEmpty()
if (numbersAndAddresses.size == 1) {
val address = numbersAndAddresses.first().address
@ -154,6 +175,7 @@ class ContactViewModel : ViewModel() {
}
fun startVideoCall() {
// UI thread
val numbersAndAddresses = sipAddressesAndPhoneNumbers.value.orEmpty()
if (numbersAndAddresses.size == 1) {
val address = numbersAndAddresses.first().address
@ -170,6 +192,7 @@ class ContactViewModel : ViewModel() {
}
fun sendMessage() {
// UI thread
if (sipAddressesAndPhoneNumbers.value.orEmpty().size == 1) {
// TODO
} else {

View file

@ -35,6 +35,7 @@
app:layout_constraintBottom_toBottomOf="@id/edit"/>
<ImageView
android:onClick="@{() -> viewModel.editContact()}"
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="35dp"
@ -436,6 +437,7 @@
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{() -> viewModel.editContact()}"
style="@style/context_menu_action_label_style"
android:id="@+id/action_edit"
android:layout_width="0dp"