mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added number/address picker dialog
This commit is contained in:
parent
af75f4c3a3
commit
f365a43f7b
10 changed files with 310 additions and 3 deletions
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<ArrayList<ContactNumberOrAddressModel>>()
|
||||
|
||||
val dismissEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
init {
|
||||
sipAddressesAndPhoneNumbers.value = viewModel.sipAddressesAndPhoneNumbers.value
|
||||
}
|
||||
|
||||
fun dismiss() {
|
||||
dismissEvent.value = Event(true)
|
||||
}
|
||||
}
|
||||
|
|
@ -48,10 +48,14 @@ class ContactViewModel : ViewModel() {
|
|||
|
||||
val contactFoundEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
val showLongPressMenuForNumberOrAddress: MutableLiveData<Event<ContactNumberOrAddressModel>> by lazy {
|
||||
val showLongPressMenuForNumberOrAddressEvent: MutableLiveData<Event<ContactNumberOrAddressModel>> by lazy {
|
||||
MutableLiveData<Event<ContactNumberOrAddressModel>>()
|
||||
}
|
||||
|
||||
val showNumberOrAddressPickerDialogEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
66
app/src/main/java/org/linphone/utils/DialogUtils.kt
Normal file
66
app/src/main/java/org/linphone/utils/DialogUtils.kt
Normal file
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
5
app/src/main/res/drawable/shape_dialog_background.xml
Normal file
5
app/src/main/res/drawable/shape_dialog_background.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<corners android:radius="15dp" />
|
||||
<solid android:color="@color/white"/>
|
||||
</shape>
|
||||
5
app/src/main/res/drawable/shape_orange_shadow.xml
Normal file
5
app/src/main/res/drawable/shape_orange_shadow.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<corners android:radius="15dp" />
|
||||
<solid android:color="@color/primary_color"/>
|
||||
</shape>
|
||||
|
|
@ -123,6 +123,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/name" />
|
||||
|
||||
<ImageView
|
||||
android:onClick="@{() -> viewModel.startAudioCall()}"
|
||||
android:id="@+id/call"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
|
|
@ -136,6 +137,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/status" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:onClick="@{() -> viewModel.startAudioCall()}"
|
||||
android:id="@+id/call_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -148,6 +150,7 @@
|
|||
app:layout_constraintEnd_toEndOf="@id/call"/>
|
||||
|
||||
<ImageView
|
||||
android:onClick="@{() -> viewModel.sendMessage()}"
|
||||
android:id="@+id/chat"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
|
|
@ -161,6 +164,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/status" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:onClick="@{() -> viewModel.sendMessage()}"
|
||||
android:id="@+id/chat_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -173,6 +177,7 @@
|
|||
app:layout_constraintEnd_toEndOf="@id/chat"/>
|
||||
|
||||
<ImageView
|
||||
android:onClick="@{() -> viewModel.startVideoCall()}"
|
||||
android:id="@+id/video_call"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
|
|
@ -186,6 +191,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/status" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:onClick="@{() -> viewModel.startVideoCall()}"
|
||||
android:id="@+id/video_call_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
62
app/src/main/res/layout/dialog_number_address_list_cell.xml
Normal file
62
app/src/main/res/layout/dialog_number_address_list_cell.xml
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
<import type="android.graphics.Typeface" />
|
||||
<variable
|
||||
name="model"
|
||||
type="org.linphone.ui.contacts.model.ContactNumberOrAddressModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onLongClick="@{() -> model.onLongPress()}"
|
||||
android:selected="@{model.selected}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/cell_background">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/header"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="@{model.sip ? `SIP address` : `Phone (` + model.label + `)`, default=`Phone (Home)`}"
|
||||
android:textColor="@color/gray_9"
|
||||
android:textStyle="bold"
|
||||
android:textSize="14sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/number_or_address"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="@{model.displayedValue, default=`sip:johndoe@sip.linphone.org`}"
|
||||
android:textColor="@color/gray_9"
|
||||
android:textSize="14sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/header"/>
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@color/blue_outgoing_message"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/number_or_address"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
||||
78
app/src/main/res/layout/dialog_pick_number_or_address.xml
Normal file
78
app/src/main/res/layout/dialog_pick_number_or_address.xml
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
<import type="android.graphics.Typeface" />
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.contacts.model.NumberOrAddressPickerDialogModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:src="@drawable/shape_orange_shadow"
|
||||
app:layout_constraintBottom_toBottomOf="@id/numbers_and_addresses"
|
||||
app:layout_constraintEnd_toEndOf="@id/dialog_background"
|
||||
app:layout_constraintStart_toStartOf="@id/dialog_background"
|
||||
app:layout_constraintTop_toTopOf="@id/dialog_background" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:src="@drawable/shape_dialog_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/numbers_and_addresses"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/title" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:paddingTop="25dp"
|
||||
android:text="Which canal do you choose?"
|
||||
android:textColor="@color/gray_9"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
app:layout_constraintBottom_toTopOf="@id/numbers_and_addresses"
|
||||
app:layout_constraintStart_toStartOf="@id/dialog_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/dialog_background"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/numbers_and_addresses"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="20dp"
|
||||
app:entries="@{viewModel.sipAddressesAndPhoneNumbers}"
|
||||
app:layout="@{@layout/dialog_number_address_list_cell}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@id/dialog_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/dialog_background"
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
<color name="gray_incoming_message">#F4F4F7</color>
|
||||
<color name="trusted_blue">#4AA8FF</color>
|
||||
<color name="warning_orange_background">#FFEACB</color>
|
||||
<color name="dialog_background">#22334D</color>
|
||||
|
||||
<color name="gray_1">#6C7A87</color>
|
||||
<color name="gray_2">#F9F9F9</color>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue