diff --git a/app/src/main/java/org/linphone/ui/contacts/fragment/ContactFragment.kt b/app/src/main/java/org/linphone/ui/contacts/fragment/ContactFragment.kt index 70fd7558e..eba32aaa7 100644 --- a/app/src/main/java/org/linphone/ui/contacts/fragment/ContactFragment.kt +++ b/app/src/main/java/org/linphone/ui/contacts/fragment/ContactFragment.kt @@ -29,8 +29,10 @@ import androidx.navigation.fragment.navArgs import androidx.transition.ChangeBounds import org.linphone.core.tools.Log import org.linphone.databinding.ContactFragmentBinding +import org.linphone.ui.contacts.model.NumberOrAddressPickerDialogModel import org.linphone.ui.contacts.viewmodel.ContactViewModel import org.linphone.ui.fragment.GenericFragment +import org.linphone.utils.DialogUtils import org.linphone.utils.Event class ContactFragment : GenericFragment() { @@ -83,7 +85,7 @@ class ContactFragment : GenericFragment() { sharedViewModel.openSlidingPaneEvent.value = Event(true) } - viewModel.showLongPressMenuForNumberOrAddress.observe(viewLifecycleOwner) { + viewModel.showLongPressMenuForNumberOrAddressEvent.observe(viewLifecycleOwner) { it.consume { model -> val modalBottomSheet = ContactNumberOrAddressMenuDialogFragment() { model.selected.value = false @@ -94,5 +96,20 @@ class ContactFragment : GenericFragment() { ) } } + + viewModel.showNumberOrAddressPickerDialogEvent.observe(viewLifecycleOwner) { + it.consume { + val model = NumberOrAddressPickerDialogModel(viewModel) + val dialog = DialogUtils.getNumberOrAddressPickerDialog(requireActivity(), model) + + model.dismissEvent.observe(viewLifecycleOwner) { + it.consume { + dialog.dismiss() + } + } + + dialog.show() + } + } } } diff --git a/app/src/main/java/org/linphone/ui/contacts/model/NumberOrAddressPickerDialogModel.kt b/app/src/main/java/org/linphone/ui/contacts/model/NumberOrAddressPickerDialogModel.kt new file mode 100644 index 000000000..c5f747d5b --- /dev/null +++ b/app/src/main/java/org/linphone/ui/contacts/model/NumberOrAddressPickerDialogModel.kt @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010-2023 Belledonne Communications SARL. + * + * This file is part of linphone-android + * (see https://www.linphone.org). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.linphone.ui.contacts.model + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import org.linphone.ui.contacts.viewmodel.ContactViewModel +import org.linphone.utils.Event + +class NumberOrAddressPickerDialogModel(viewModel: ContactViewModel) : ViewModel() { + val sipAddressesAndPhoneNumbers = MutableLiveData>() + + val dismissEvent = MutableLiveData>() + + init { + sipAddressesAndPhoneNumbers.value = viewModel.sipAddressesAndPhoneNumbers.value + } + + fun dismiss() { + dismissEvent.value = Event(true) + } +} diff --git a/app/src/main/java/org/linphone/ui/contacts/viewmodel/ContactViewModel.kt b/app/src/main/java/org/linphone/ui/contacts/viewmodel/ContactViewModel.kt index 129711614..ad6e5428b 100644 --- a/app/src/main/java/org/linphone/ui/contacts/viewmodel/ContactViewModel.kt +++ b/app/src/main/java/org/linphone/ui/contacts/viewmodel/ContactViewModel.kt @@ -48,10 +48,14 @@ class ContactViewModel : ViewModel() { val contactFoundEvent = MutableLiveData>() - val showLongPressMenuForNumberOrAddress: MutableLiveData> by lazy { + val showLongPressMenuForNumberOrAddressEvent: MutableLiveData> by lazy { MutableLiveData>() } + val showNumberOrAddressPickerDialogEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + val listener = object : ContactNumberOrAddressClickListener { override fun onCall(address: Address) { // UI thread @@ -67,7 +71,7 @@ class ContactViewModel : ViewModel() { override fun onLongPress(model: ContactNumberOrAddressModel) { // UI thread - showLongPressMenuForNumberOrAddress.value = Event(model) + showLongPressMenuForNumberOrAddressEvent.value = Event(model) } } @@ -131,4 +135,28 @@ class ContactViewModel : ViewModel() { fun toggleDevicesTrustVisibility() { showDevicesTrust.value = showDevicesTrust.value == false } + + fun startAudioCall() { + if (sipAddressesAndPhoneNumbers.value.orEmpty().size == 1) { + // TODO + } else { + showNumberOrAddressPickerDialogEvent.value = Event(true) + } + } + + fun startVideoCall() { + if (sipAddressesAndPhoneNumbers.value.orEmpty().size == 1) { + // TODO + } else { + showNumberOrAddressPickerDialogEvent.value = Event(true) + } + } + + fun sendMessage() { + if (sipAddressesAndPhoneNumbers.value.orEmpty().size == 1) { + // TODO + } else { + showNumberOrAddressPickerDialogEvent.value = Event(true) + } + } } diff --git a/app/src/main/java/org/linphone/utils/DialogUtils.kt b/app/src/main/java/org/linphone/utils/DialogUtils.kt new file mode 100644 index 000000000..997623a8c --- /dev/null +++ b/app/src/main/java/org/linphone/utils/DialogUtils.kt @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010-2020 Belledonne Communications SARL. + * + * This file is part of linphone-android + * (see https://www.linphone.org). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.linphone.utils + +import android.app.Dialog +import android.content.Context +import android.graphics.drawable.ColorDrawable +import android.graphics.drawable.Drawable +import android.view.LayoutInflater +import android.view.Window +import android.view.WindowManager +import androidx.core.content.ContextCompat +import androidx.databinding.DataBindingUtil +import org.linphone.R +import org.linphone.databinding.DialogPickNumberOrAddressBinding +import org.linphone.ui.contacts.model.NumberOrAddressPickerDialogModel + +class DialogUtils { + companion object { + fun getNumberOrAddressPickerDialog( + context: Context, + viewModel: NumberOrAddressPickerDialogModel + ): Dialog { + val dialog = Dialog(context) + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) + + val binding: DialogPickNumberOrAddressBinding = DataBindingUtil.inflate( + LayoutInflater.from(context), + R.layout.dialog_pick_number_or_address, + null, + false + ) + binding.viewModel = viewModel + dialog.setContentView(binding.root) + + val d: Drawable = ColorDrawable( + ContextCompat.getColor(dialog.context, R.color.dialog_background) + ) + d.alpha = 100 + dialog.window + ?.setLayout( + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.MATCH_PARENT + ) + dialog.window?.setBackgroundDrawable(d) + return dialog + } + } +} diff --git a/app/src/main/res/drawable/shape_dialog_background.xml b/app/src/main/res/drawable/shape_dialog_background.xml new file mode 100644 index 000000000..706ef93e2 --- /dev/null +++ b/app/src/main/res/drawable/shape_dialog_background.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_orange_shadow.xml b/app/src/main/res/drawable/shape_orange_shadow.xml new file mode 100644 index 000000000..823494dba --- /dev/null +++ b/app/src/main/res/drawable/shape_orange_shadow.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/contact_fragment.xml b/app/src/main/res/layout/contact_fragment.xml index 46895dcd9..21852aafe 100644 --- a/app/src/main/res/layout/contact_fragment.xml +++ b/app/src/main/res/layout/contact_fragment.xml @@ -123,6 +123,7 @@ app:layout_constraintTop_toBottomOf="@id/name" /> + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_pick_number_or_address.xml b/app/src/main/res/layout/dialog_pick_number_or_address.xml new file mode 100644 index 000000000..b9241e262 --- /dev/null +++ b/app/src/main/res/layout/dialog_pick_number_or_address.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 27c114e6d..085bb692e 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -11,6 +11,7 @@ #F4F4F7 #4AA8FF #FFEACB + #22334D #6C7A87 #F9F9F9