Improved media store export
This commit is contained in:
parent
2c4df28603
commit
fb916eeea3
3 changed files with 42 additions and 36 deletions
|
@ -26,6 +26,7 @@ import android.text.Spanned
|
|||
import android.text.style.UnderlineSpan
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import kotlinx.coroutines.*
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.core.ChatMessage
|
||||
import org.linphone.core.ChatMessageListenerStub
|
||||
|
@ -92,6 +93,14 @@ class ChatMessageContentData(
|
|||
|
||||
if (state == ChatMessage.State.FileTransferDone || state == ChatMessage.State.FileTransferError) {
|
||||
updateContent()
|
||||
|
||||
if (state == ChatMessage.State.FileTransferDone) {
|
||||
Log.i("[Chat Message] File transfer done")
|
||||
if (!message.isOutgoing && !message.isEphemeral) {
|
||||
Log.i("[Chat Message] Adding content to media store")
|
||||
coreContext.addContentToMediaStore(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,13 +24,10 @@ import android.text.Spannable
|
|||
import android.text.util.Linkify
|
||||
import androidx.core.text.util.LinkifyCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.contact.GenericContactData
|
||||
import org.linphone.core.ChatMessage
|
||||
import org.linphone.core.ChatMessageListenerStub
|
||||
import org.linphone.core.Content
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.TimestampUtils
|
||||
|
||||
|
@ -66,13 +63,6 @@ class ChatMessageData(
|
|||
override fun onMsgStateChanged(message: ChatMessage, state: ChatMessage.State) {
|
||||
time.value = TimestampUtils.toString(chatMessage.time)
|
||||
updateChatMessageState(state)
|
||||
|
||||
if (state == ChatMessage.State.FileTransferDone) {
|
||||
Log.i("[Chat Message] File transfer done")
|
||||
if (!message.isOutgoing) {
|
||||
coreContext.exportFilesInMessageToMediaStore(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onEphemeralMessageTimerStarted(message: ChatMessage) {
|
||||
|
@ -197,8 +187,4 @@ class ChatMessageData(
|
|||
else -> String.format("%02d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 60))
|
||||
}
|
||||
}
|
||||
|
||||
private fun addContentToMediaStore(content: Content) {
|
||||
coreContext.addContentToMediaStore(content)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -636,31 +636,42 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
|||
}
|
||||
|
||||
fun addContentToMediaStore(content: Content) {
|
||||
coroutineScope.launch {
|
||||
when (content.type) {
|
||||
"image" -> {
|
||||
if (Compatibility.addImageToMediaStore(context, content)) {
|
||||
Log.i("[Context] Adding image ${content.name} to Media Store terminated")
|
||||
} else {
|
||||
Log.e("[Context] Something went wrong while copying file to Media Store...")
|
||||
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()) {
|
||||
coroutineScope.launch {
|
||||
when (content.type) {
|
||||
"image" -> {
|
||||
if (Compatibility.addImageToMediaStore(context, content)) {
|
||||
Log.i("[Context] Adding image ${content.name} to Media Store terminated")
|
||||
} else {
|
||||
Log.e("[Context] Something went wrong while copying file to Media Store...")
|
||||
}
|
||||
}
|
||||
}
|
||||
"video" -> {
|
||||
if (Compatibility.addVideoToMediaStore(context, content)) {
|
||||
Log.i("[Context] Adding video ${content.name} to Media Store terminated")
|
||||
} else {
|
||||
Log.e("[Context] Something went wrong while copying file to Media Store...")
|
||||
"video" -> {
|
||||
if (Compatibility.addVideoToMediaStore(context, content)) {
|
||||
Log.i("[Context] Adding video ${content.name} to Media Store terminated")
|
||||
} else {
|
||||
Log.e("[Context] Something went wrong while copying file to Media Store...")
|
||||
}
|
||||
}
|
||||
}
|
||||
"audio" -> {
|
||||
if (Compatibility.addAudioToMediaStore(context, content)) {
|
||||
Log.i("[Context] Adding audio ${content.name} to Media Store terminated")
|
||||
} else {
|
||||
Log.e("[Context] Something went wrong while copying file to Media Store...")
|
||||
"audio" -> {
|
||||
if (Compatibility.addAudioToMediaStore(context, content)) {
|
||||
Log.i("[Context] Adding audio ${content.name} to Media Store terminated")
|
||||
} else {
|
||||
Log.e("[Context] Something went wrong while copying file to Media Store...")
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Log.w("[Context] File ${content.name} isn't either an image, an audio file or a video, can't add it to the Media Store")
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Log.w("[Context] File ${content.name} isn't either an image, an audio file or a video, can't add it to the Media Store")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue