Reworked audio devices list in call

This commit is contained in:
Sylvain Berfini 2023-11-24 12:09:04 +01:00
parent 55d67e92d3
commit fd3f85f2b7
10 changed files with 167 additions and 30 deletions

View file

@ -19,14 +19,14 @@
*/
package org.linphone.ui.call.model
import androidx.annotation.WorkerThread
import org.linphone.core.AudioDevice
data class AudioDeviceModel(
data class AudioDeviceModel @WorkerThread constructor(
val audioDevice: AudioDevice,
val name: String,
val isSpeaker: Boolean,
val isHeadset: Boolean,
val isBluetooth: Boolean,
val type: AudioDevice.Type,
val isCurrentlySelected: Boolean,
private val onAudioDeviceSelected: (() -> Unit)? = null
) {
var dismissDialog: (() -> Unit)? = null

View file

@ -482,18 +482,50 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
// Only list output audio devices
if (!device.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) continue
val isSpeaker = device.type == AudioDevice.Type.Speaker
val isHeadset = device.type == AudioDevice.Type.Headset || device.type == AudioDevice.Type.Headphones
val isBluetooth = device.type == AudioDevice.Type.Bluetooth
val model = AudioDeviceModel(device, device.id, isSpeaker, isHeadset, isBluetooth) {
val name = when (device.type) {
AudioDevice.Type.Earpiece -> {
AppUtils.getString(R.string.call_audio_device_type_earpiece)
}
AudioDevice.Type.Speaker -> {
AppUtils.getString(R.string.call_audio_device_type_speaker)
}
AudioDevice.Type.Headset -> {
AppUtils.getString(R.string.call_audio_device_type_headset)
}
AudioDevice.Type.Headphones -> {
AppUtils.getString(R.string.call_audio_device_type_headphones)
}
AudioDevice.Type.Bluetooth -> {
AppUtils.getFormattedString(
R.string.call_audio_device_type_bluetooth,
device.deviceName
)
}
AudioDevice.Type.HearingAid -> {
AppUtils.getFormattedString(
R.string.call_audio_device_type_hearing_aid,
device.deviceName
)
}
else -> device.deviceName
}
val currentDevice = currentCall.outputAudioDevice
val isCurrentlyInUse = device.type == currentDevice?.type && device.deviceName == currentDevice?.deviceName
val model = AudioDeviceModel(device, name, device.type, isCurrentlyInUse) {
// onSelected
coreContext.postOnCoreThread {
Log.i("$TAG Selected audio device with ID [${device.id}]")
if (::currentCall.isInitialized) {
when {
isHeadset -> AudioUtils.routeAudioToHeadset(currentCall)
isBluetooth -> AudioUtils.routeAudioToBluetooth(currentCall)
isSpeaker -> AudioUtils.routeAudioToSpeaker(currentCall)
when (device.type) {
AudioDevice.Type.Headset, AudioDevice.Type.Headphones -> AudioUtils.routeAudioToHeadset(
currentCall
)
AudioDevice.Type.Bluetooth, AudioDevice.Type.HearingAid -> AudioUtils.routeAudioToBluetooth(
currentCall
)
AudioDevice.Type.Speaker -> AudioUtils.routeAudioToSpeaker(
currentCall
)
else -> AudioUtils.routeAudioToEarpiece(currentCall)
}
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M216,48H40A16,16 0,0 0,24 64V192a16,16 0,0 0,16 16H216a16,16 0,0 0,16 -16V64A16,16 0,0 0,216 48ZM40,64H216v56H144a16,16 0,0 0,-16 16v56H40ZM216,192H144V136h72v56Z"
android:fillColor="#4e6074"/>
</vector>

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="rectangle">
<corners android:topRightRadius="15dp" android:topLeftRadius="15dp" />
<solid android:color="@color/gray_600"/>
</shape>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M104,40L56,40A16,16 0,0 0,40 56v48a16,16 0,0 0,16 16h48a16,16 0,0 0,16 -16L120,56A16,16 0,0 0,104 40ZM104,104L56,104L56,56h48v48ZM200,40L152,40a16,16 0,0 0,-16 16v48a16,16 0,0 0,16 16h48a16,16 0,0 0,16 -16L216,56A16,16 0,0 0,200 40ZM200,104L152,104L152,56h48v48ZM104,136L56,136a16,16 0,0 0,-16 16v48a16,16 0,0 0,16 16h48a16,16 0,0 0,16 -16L120,152A16,16 0,0 0,104 136ZM104,200L56,200L56,152h48v48ZM200,136L152,136a16,16 0,0 0,-16 16v48a16,16 0,0 0,16 16h48a16,16 0,0 0,16 -16L216,152A16,16 0,0 0,200 136ZM200,200L152,200L152,152h48v48Z"
android:fillColor="#4e6074"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M56,96v64a8,8 0,0 1,-16 0L40,96a8,8 0,0 1,16 0ZM88,24a8,8 0,0 0,-8 8L80,224a8,8 0,0 0,16 0L96,32A8,8 0,0 0,88 24ZM128,56a8,8 0,0 0,-8 8L120,192a8,8 0,0 0,16 0L136,64A8,8 0,0 0,128 56ZM168,88a8,8 0,0 0,-8 8v64a8,8 0,0 0,16 0L176,96A8,8 0,0 0,168 88ZM208,72a8,8 0,0 0,-8 8v96a8,8 0,0 0,16 0L216,80A8,8 0,0 0,208 72Z"
android:fillColor="#4e6074"/>
</vector>

View file

@ -4,30 +4,27 @@
<data>
<import type="android.view.View" />
<import type="org.linphone.core.AudioDevice.Type" />
<variable
name="model"
type="org.linphone.ui.call.model.AudioDeviceModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
<com.google.android.material.radiobutton.MaterialRadioButton
style="@style/context_menu_action_label_style"
android:onClick="@{() -> model.onClicked()}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black">
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@{model.name, default=`Speaker`}"
android:textColor="@color/white"
android:layout_marginBottom="1dp"
android:drawableStart="@{model.isHeadset ? @drawable/headset : model.isBluetooth ? @drawable/bluetooth : model.isSpeaker ? @drawable/speaker_high : @drawable/ear, default=@drawable/speaker_high}"
android:drawableTint="@color/gray_main2_300"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.name, default=`Speaker`}"
android:textColor="@color/white"
android:gravity="center_vertical"
android:layout_marginBottom="1dp"
android:drawableEnd="@{model.type == Type.Speaker ? @drawable/speaker_high : model.type == Type.Bluetooth || model.type == Type.HearingAid ? @drawable/bluetooth : model.type == Type.Headphones || model.type == Type.Headset ? @drawable/headset : @drawable/ear, default=@drawable/speaker_high}"
android:drawableTint="@color/white"
android:checked="@{model.isCurrentlySelected}"
app:useMaterialThemeColors="false"
app:buttonTint="@color/white"/>
</layout>

View file

@ -12,7 +12,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/gray_500"
android:background="@drawable/shape_squircle_gray_600_top_background"
entries="@{devices}"
layout="@{@layout/call_audio_device_list_cell}">

View file

@ -0,0 +1,65 @@
<?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" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/shape_squircle_gray_600_top_background">
<com.google.android.material.radiobutton.MaterialRadioButton
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/conference_layout_grid"
android:textColor="@color/white"
android:gravity="center_vertical"
android:layout_marginBottom="1dp"
android:drawableEnd="@drawable/squares_four"
android:drawableTint="@color/white"
android:checked="true"
app:useMaterialThemeColors="false"
app:buttonTint="@color/white"/>
<com.google.android.material.radiobutton.MaterialRadioButton
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/conference_layout_active_speaker"
android:textColor="@color/white"
android:gravity="center_vertical"
android:layout_marginBottom="1dp"
android:drawableEnd="@drawable/picture_in_picture"
android:drawableTint="@color/white"
android:checked="false"
app:useMaterialThemeColors="false"
app:buttonTint="@color/white"/>
<com.google.android.material.radiobutton.MaterialRadioButton
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/conference_layout_audio_only"
android:textColor="@color/white"
android:gravity="center_vertical"
android:layout_marginBottom="1dp"
android:drawableEnd="@drawable/waveform"
android:drawableTint="@color/white"
android:checked="false"
app:useMaterialThemeColors="false"
app:buttonTint="@color/white"/>
</LinearLayout>
</layout>

View file

@ -489,12 +489,23 @@
<string name="calls_count_label">%s calls</string>
<string name="calls_paused_count_label">%s paused calls</string>
<string name="call_audio_device_type_earpiece">Earpiece</string>
<string name="call_audio_device_type_speaker">Speaker</string>
<string name="call_audio_device_type_bluetooth">Bluetooth (%s)</string>
<string name="call_audio_device_type_hearing_aid">Hearing aid (%s)</string>
<string name="call_audio_device_type_headset">Headset</string>
<string name="call_audio_device_type_headphones">Headphones</string>
<string name="conference_share_link_title">Share invitation</string>
<string name="conference_call_empty">Waiting for other participants…</string>
<string name="conference_action_screen_sharing">Screen share</string>
<string name="conference_action_show_participants">Participants</string>
<string name="conference_participants_list_title">%s participants</string>
<string name="conference_layout_grid">Mosaic</string>
<string name="conference_layout_active_speaker">Speaker</string>
<string name="conference_layout_audio_only">Audio only</string>
<string name="connection_error_for_non_default_account">Account connection error</string>
<string name="network_not_reachable">You aren\'t connected to internet</string>