Allow to export received files to Android's media store if auto download is enabled
This commit is contained in:
parent
d5508b6ffe
commit
8b417fe436
3 changed files with 43 additions and 18 deletions
|
@ -25,16 +25,13 @@ import android.text.util.Linkify
|
||||||
import androidx.core.text.util.LinkifyCompat
|
import androidx.core.text.util.LinkifyCompat
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.contact.GenericContactData
|
import org.linphone.contact.GenericContactData
|
||||||
import org.linphone.core.ChatMessage
|
import org.linphone.core.ChatMessage
|
||||||
import org.linphone.core.ChatMessageListenerStub
|
import org.linphone.core.ChatMessageListenerStub
|
||||||
import org.linphone.core.Content
|
import org.linphone.core.Content
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.mediastream.Version
|
|
||||||
import org.linphone.utils.AppUtils
|
import org.linphone.utils.AppUtils
|
||||||
import org.linphone.utils.PermissionHelper
|
|
||||||
import org.linphone.utils.TimestampUtils
|
import org.linphone.utils.TimestampUtils
|
||||||
|
|
||||||
class ChatMessageData(
|
class ChatMessageData(
|
||||||
|
@ -75,17 +72,7 @@ class ChatMessageData(
|
||||||
Log.i("[Chat Message] File transfer done")
|
Log.i("[Chat Message] File transfer done")
|
||||||
updateContentsList()
|
updateContentsList()
|
||||||
|
|
||||||
if (!message.isEphemeral && !corePreferences.vfsEnabled && corePreferences.makePublicMediaFilesDownloaded) {
|
coreContext.exportFilesInMessageToMediaStore(message)
|
||||||
if (Version.sdkAboveOrEqual(Version.API29_ANDROID_10) || PermissionHelper.get().hasWriteExternalStorage()) {
|
|
||||||
for (content in message.contents) {
|
|
||||||
if (content.isFile && content.filePath != null && content.userData == null) {
|
|
||||||
addContentToMediaStore(content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.e("[Chat Message] Can't make file public, app doesn't have WRITE_EXTERNAL_STORAGE permission")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,10 +59,8 @@ import org.linphone.contact.ContactsManager
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.mediastream.Version
|
import org.linphone.mediastream.Version
|
||||||
import org.linphone.notifications.NotificationsManager
|
import org.linphone.notifications.NotificationsManager
|
||||||
import org.linphone.utils.AppUtils
|
import org.linphone.utils.*
|
||||||
import org.linphone.utils.AudioRouteUtils
|
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
import org.linphone.utils.LinphoneUtils
|
|
||||||
|
|
||||||
class CoreContext(val context: Context, coreConfig: Config) {
|
class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
var stopped = false
|
var stopped = false
|
||||||
|
@ -240,6 +238,21 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
|
|
||||||
previousCallState = state
|
previousCallState = state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMessageReceived(core: Core, chatRoom: ChatRoom, message: ChatMessage) {
|
||||||
|
if (core.maxSizeForAutoDownloadIncomingFiles != -1) {
|
||||||
|
var hasFile = false
|
||||||
|
for (content in message.contents) {
|
||||||
|
if (content.isFile) {
|
||||||
|
hasFile = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasFile) {
|
||||||
|
exportFilesInMessageToMediaStore(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val loggingServiceListener = object : LoggingServiceListenerStub() {
|
private val loggingServiceListener = object : LoggingServiceListenerStub() {
|
||||||
|
@ -581,6 +594,31 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
|
|
||||||
/* Coroutine related */
|
/* Coroutine related */
|
||||||
|
|
||||||
|
fun exportFilesInMessageToMediaStore(message: ChatMessage) {
|
||||||
|
if (message.isEphemeral) {
|
||||||
|
Log.w("[Context] Do not make ephemeral file(s) public")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (corePreferences.vfsEnabled) {
|
||||||
|
Log.w("[Context] Do not make received file(s) public when VFS is enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!corePreferences.makePublicMediaFilesDownloaded) {
|
||||||
|
Log.w("[Context] Making received files public setting disabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Version.sdkAboveOrEqual(Version.API29_ANDROID_10) || PermissionHelper.get().hasWriteExternalStorage()) {
|
||||||
|
for (content in message.contents) {
|
||||||
|
if (content.isFile && content.filePath != null && content.userData == null) {
|
||||||
|
addContentToMediaStore(content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e("[Context] Can't make file public, app doesn't have WRITE_EXTERNAL_STORAGE permission")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun addContentToMediaStore(content: Content) {
|
fun addContentToMediaStore(content: Content) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
when (content.type) {
|
when (content.type) {
|
||||||
|
|
|
@ -93,7 +93,7 @@
|
||||||
<include
|
<include
|
||||||
layout="@layout/settings_widget_switch"
|
layout="@layout/settings_widget_switch"
|
||||||
linphone:title="@{@string/chat_settings_downloaded_media_public_title}"
|
linphone:title="@{@string/chat_settings_downloaded_media_public_title}"
|
||||||
linphone:enabled="@{viewModel.autoDownloadIndex == 0 && !viewModel.vfs}"
|
linphone:enabled="@{!viewModel.vfs}"
|
||||||
linphone:subtitle="@{@string/chat_settings_downloaded_media_public_summary}"
|
linphone:subtitle="@{@string/chat_settings_downloaded_media_public_summary}"
|
||||||
linphone:listener="@{viewModel.downloadedMediaPublicListener}"
|
linphone:listener="@{viewModel.downloadedMediaPublicListener}"
|
||||||
linphone:checked="@={viewModel.downloadedMediaPublic}"/>
|
linphone:checked="@={viewModel.downloadedMediaPublic}"/>
|
||||||
|
|
Loading…
Reference in a new issue