mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Reworked a bit & improved video call take snapshot process
This commit is contained in:
parent
163e2adfde
commit
6d2ae8007a
7 changed files with 30 additions and 39 deletions
|
|
@ -129,15 +129,6 @@ class CallActivity : ProximitySensorActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
callsViewModel.askWriteExternalStoragePermissionEvent.observe(
|
||||
this
|
||||
) {
|
||||
it.consume {
|
||||
Log.i("[Call Activity] Asking for WRITE_EXTERNAL_STORAGE permission to take snapshot")
|
||||
requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
|
||||
}
|
||||
}
|
||||
|
||||
callsViewModel.currentCallData.observe(
|
||||
this
|
||||
) { callData ->
|
||||
|
|
@ -302,13 +293,12 @@ class CallActivity : ProximitySensorActivity() {
|
|||
Compatibility.BLUETOOTH_CONNECT -> if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i("[Call Activity] BLUETOOTH_CONNECT permission has been granted")
|
||||
}
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE -> if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i("[Call Activity] WRITE_EXTERNAL_STORAGE permission has been granted, taking snapshot")
|
||||
controlsViewModel.takeSnapshot()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (requestCode == 1) {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i("[Call Activity] WRITE_EXTERNAL_STORAGE permission has been granted, taking snapshot")
|
||||
callsViewModel.takeSnapshot()
|
||||
}
|
||||
}
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
package org.linphone.activities.voip.data
|
||||
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import java.util.*
|
||||
|
|
@ -30,6 +31,7 @@ import org.linphone.compatibility.Compatibility
|
|||
import org.linphone.contact.GenericContactData
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
|
||||
open class CallData(val call: Call) : GenericContactData(call.remoteAddress) {
|
||||
|
|
@ -94,11 +96,13 @@ open class CallData(val call: Call) : GenericContactData(call.remoteAddress) {
|
|||
content.filePath = filePath
|
||||
content.type = "image"
|
||||
content.subtype = "jpeg"
|
||||
content.name = filePath.substring(filePath.indexOf("/") + 1)
|
||||
content.name = filePath.substring(filePath.lastIndexOf("/") + 1)
|
||||
|
||||
scope.launch {
|
||||
if (Compatibility.addImageToMediaStore(coreContext.context, content)) {
|
||||
Log.i("[Call] Adding snapshot ${content.name} to Media Store terminated")
|
||||
Log.i("[Call] Added snapshot ${content.name} to Media Store")
|
||||
val message = String.format(AppUtils.getString(R.string.call_screenshot_taken), content.name)
|
||||
Toast.makeText(coreContext.context, message, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
Log.e("[Call] Something went wrong while copying file to Media Store...")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import org.linphone.core.*
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.FileUtils
|
||||
import org.linphone.utils.PermissionHelper
|
||||
|
||||
class CallsViewModel : ViewModel() {
|
||||
|
|
@ -48,10 +47,6 @@ class CallsViewModel : ViewModel() {
|
|||
|
||||
val isMuteMicrophoneEnabled = MutableLiveData<Boolean>()
|
||||
|
||||
val askWriteExternalStoragePermissionEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val callConnectedEvent: MutableLiveData<Event<Call>> by lazy {
|
||||
MutableLiveData<Event<Call>>()
|
||||
}
|
||||
|
|
@ -196,20 +191,6 @@ class CallsViewModel : ViewModel() {
|
|||
conference?.addParticipants(core.calls)
|
||||
}
|
||||
|
||||
fun takeSnapshot() {
|
||||
if (!PermissionHelper.get().hasWriteExternalStoragePermission()) {
|
||||
askWriteExternalStoragePermissionEvent.value = Event(true)
|
||||
} else {
|
||||
if (currentCallData.value?.call?.currentParams?.isVideoEnabled == true) {
|
||||
val fileName = System.currentTimeMillis().toString() + ".jpeg"
|
||||
Log.i("[Calls] Snapshot will be save under $fileName")
|
||||
currentCallData.value?.call?.takeVideoSnapshot(FileUtils.getFileStoragePath(fileName).absolutePath)
|
||||
} else {
|
||||
Log.e("[Calls] Current call doesn't have video, can't take snapshot")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initCallList() {
|
||||
val calls = arrayListOf<CallData>()
|
||||
|
||||
|
|
|
|||
|
|
@ -31,10 +31,8 @@ import org.linphone.LinphoneApplication.Companion.corePreferences
|
|||
import org.linphone.R
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.AudioRouteUtils
|
||||
import org.linphone.utils.*
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.PermissionHelper
|
||||
|
||||
class ControlsViewModel : ViewModel() {
|
||||
val isSpeakerSelected = MutableLiveData<Boolean>()
|
||||
|
|
@ -327,6 +325,22 @@ class ControlsViewModel : ViewModel() {
|
|||
coreContext.switchCamera()
|
||||
}
|
||||
|
||||
fun takeSnapshot() {
|
||||
if (!PermissionHelper.get().hasWriteExternalStoragePermission()) {
|
||||
askPermissionEvent.value = Event(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
} else {
|
||||
val currentCall = coreContext.core.currentCall
|
||||
if (currentCall != null && currentCall.currentParams.isVideoEnabled) {
|
||||
val fileName = System.currentTimeMillis().toString() + ".jpeg"
|
||||
val fullPath = FileUtils.getFileStoragePath(fileName).absolutePath
|
||||
Log.i("[Call Controls] Snapshot will be save under $fullPath")
|
||||
currentCall.takeVideoSnapshot(fullPath)
|
||||
} else {
|
||||
Log.e("[Call Controls] Current call doesn't have video, can't take snapshot")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun showExtraButtons() {
|
||||
extraButtonsMenuAnimator.start()
|
||||
showExtras.value = true
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@
|
|||
android:layout_margin="10dp"
|
||||
android:background="@drawable/button_toggle_background"
|
||||
android:contentDescription="@string/content_description_take_screenshot"
|
||||
android:onClick="@{() -> callsViewModel.takeSnapshot()}"
|
||||
android:onClick="@{() -> controlsViewModel.takeSnapshot()}"
|
||||
android:enabled="@{!callsViewModel.currentCallData.isPaused && !callsViewModel.currentCallData.isRemotelyPaused}"
|
||||
android:src="@drawable/icon_call_screenshot"
|
||||
android:visibility="@{!controlsViewModel.showTakeSnapshotButton || controlsViewModel.fullScreenMode || controlsViewModel.pipMode ? View.GONE : View.VISIBLE}"
|
||||
|
|
|
|||
|
|
@ -755,4 +755,5 @@
|
|||
<string name="conference_scheduled_cancelled_by_me">Vous avez annulé la conférence</string>
|
||||
<string name="conference_schedule_send_updated_invite_chat">Envoyer la mise à jour par &appName;</string>
|
||||
<string name="conference_schedule_send_updated_invite_email">Envoyer la mise à jour par courriel</string>
|
||||
<string name="call_screenshot_taken">Capture sauvegardée : %s</string>
|
||||
</resources>
|
||||
|
|
@ -351,6 +351,7 @@
|
|||
<string name="call_remotely_paused_title">Call has been paused by remote.</string>
|
||||
<string name="call_locally_paused_title">You have paused the call.</string>
|
||||
<string name="call_locally_paused_subtitle">Click on play button to resume it.</string>
|
||||
<string name="call_screenshot_taken">Snapshot taken: %s</string>
|
||||
|
||||
<!-- Call stats -->
|
||||
<string name="call_stats_audio">Audio</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue