Hide switch camera button if less than 2 cameras

This commit is contained in:
Sylvain Berfini 2020-04-24 16:12:22 +02:00
parent e53db5491a
commit 8e330ce664
8 changed files with 16 additions and 5 deletions

View file

@ -41,7 +41,7 @@ class QrCodeViewModel : ViewModel() {
init {
coreContext.core.addListener(listener)
showSwitchCamera.value = coreContext.core.videoDevicesList.size > 1
showSwitchCamera.value = coreContext.showSwitchCameraButton()
}
override fun onCleared() {

View file

@ -44,6 +44,8 @@ class ControlsViewModel : ViewModel() {
val isVideoUpdateInProgress = MutableLiveData<Boolean>()
val showSwitchCamera = MutableLiveData<Boolean>()
val isPauseEnabled = MutableLiveData<Boolean>()
val isRecording = MutableLiveData<Boolean>()
@ -129,6 +131,7 @@ class ControlsViewModel : ViewModel() {
isRecording.value = currentCall?.isRecording
isVideoUpdateInProgress.value = false
showSwitchCamera.value = coreContext.showSwitchCameraButton()
updateUI()
}

View file

@ -35,6 +35,8 @@ class DialerViewModel : ViewModel() {
val showPreview = MutableLiveData<Boolean>()
val showSwitchCamera = MutableLiveData<Boolean>()
val onKeyClick: NumpadDigitListener = object : NumpadDigitListener {
override fun handleClick(key: Char) {
enteredUri.value += key.toString()
@ -73,6 +75,8 @@ class DialerViewModel : ViewModel() {
enteredUri.value = ""
atLeastOneCall.value = coreContext.core.callsNb > 0
transferVisibility.value = false
showSwitchCamera.value = coreContext.showSwitchCameraButton()
}
override fun onCleared() {

View file

@ -363,6 +363,10 @@ class CoreContext(val context: Context, coreConfig: Config) {
call.update(null)
}
fun showSwitchCameraButton(): Boolean {
return core.videoDevicesList.orEmpty().size > 2 // Count StaticImage camera
}
fun createCallOverlay() {
if (!corePreferences.showCallOverlay || callOverlay != null) {
return

View file

@ -116,7 +116,7 @@
<ImageView
android:onClick="@{() -> controlsViewModel.switchCamera()}"
android:enabled="@{!viewModel.callPausedByRemote}"
android:visibility="@{controlsViewModel.isVideoEnabled ? View.VISIBLE : View.GONE, default=gone}"
android:visibility="@{controlsViewModel.isVideoEnabled &amp;&amp; controlsViewModel.showSwitchCamera ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_switch_camera"
android:layout_width="50dp"
android:layout_height="50dp"

View file

@ -63,7 +63,7 @@
<ImageView
android:onClick="@{() -> viewModel.switchCamera()}"
android:visibility="@{viewModel.showPreview ? View.VISIBLE : View.GONE, default=gone}"
android:visibility="@{viewModel.showPreview &amp;&amp; viewModel.showSwitchCamera ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_switch_camera"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"

View file

@ -60,7 +60,7 @@
<ImageView
android:onClick="@{() -> viewModel.switchCamera()}"
android:visibility="@{viewModel.showPreview ? View.VISIBLE : View.GONE, default=gone}"
android:visibility="@{viewModel.showPreview &amp;&amp; viewModel.showSwitchCamera ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_switch_camera"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"

View file

@ -208,7 +208,7 @@
<ImageView
android:onClick="@{() -> controlsViewModel.switchCamera()}"
android:enabled="@{!viewModel.callPausedByRemote}"
android:visibility="@{controlsViewModel.isVideoEnabled ? View.VISIBLE : View.GONE, default=gone}"
android:visibility="@{controlsViewModel.isVideoEnabled &amp;&amp; controlsViewModel.showSwitchCamera ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_switch_camera"
android:layout_width="50dp"
android:layout_height="50dp"