Rework to rename classes that weren't real view models to avoid confusion and have a proper cleaning

This commit is contained in:
Sylvain Berfini 2021-04-07 10:20:00 +02:00
parent 2215cb4621
commit 1eabce5220
36 changed files with 242 additions and 160 deletions

View file

@ -34,9 +34,9 @@ import androidx.recyclerview.widget.RecyclerView
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R import org.linphone.R
import org.linphone.activities.main.adapters.SelectionListAdapter import org.linphone.activities.main.adapters.SelectionListAdapter
import org.linphone.activities.main.chat.viewmodels.ChatMessageViewModel import org.linphone.activities.main.chat.data.ChatMessageData
import org.linphone.activities.main.chat.viewmodels.EventViewModel import org.linphone.activities.main.chat.data.EventData
import org.linphone.activities.main.chat.viewmodels.OnContentClickedListener import org.linphone.activities.main.chat.data.OnContentClickedListener
import org.linphone.activities.main.viewmodels.ListTopBarViewModel import org.linphone.activities.main.viewmodels.ListTopBarViewModel
import org.linphone.core.ChatMessage import org.linphone.core.ChatMessage
import org.linphone.core.ChatRoomCapabilities import org.linphone.core.ChatRoomCapabilities
@ -117,6 +117,12 @@ class ChatMessagesListAdapter(
} }
} }
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
when (holder) {
is ChatMessageViewHolder -> holder.binding.viewModel?.destroy()
}
}
override fun getItemViewType(position: Int): Int { override fun getItemViewType(position: Int): Int {
val eventLog = getItem(position) val eventLog = getItem(position)
return eventLog.type.toInt() return eventLog.type.toInt()
@ -127,14 +133,14 @@ class ChatMessagesListAdapter(
} }
inner class ChatMessageViewHolder( inner class ChatMessageViewHolder(
private val binding: ChatMessageListCellBinding val binding: ChatMessageListCellBinding
) : RecyclerView.ViewHolder(binding.root), PopupMenu.OnMenuItemClickListener { ) : RecyclerView.ViewHolder(binding.root), PopupMenu.OnMenuItemClickListener {
fun bind(eventLog: EventLog) { fun bind(eventLog: EventLog) {
with(binding) { with(binding) {
if (eventLog.type == EventLog.Type.ConferenceChatMessage) { if (eventLog.type == EventLog.Type.ConferenceChatMessage) {
val chatMessage = eventLog.chatMessage val chatMessage = eventLog.chatMessage
chatMessage ?: return chatMessage ?: return
val chatMessageViewModel = ChatMessageViewModel(chatMessage, contentClickedListener) val chatMessageViewModel = ChatMessageData(chatMessage, contentClickedListener)
viewModel = chatMessageViewModel viewModel = chatMessageViewModel
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner
@ -298,7 +304,7 @@ class ChatMessagesListAdapter(
) : RecyclerView.ViewHolder(binding.root) { ) : RecyclerView.ViewHolder(binding.root) {
fun bind(eventLog: EventLog) { fun bind(eventLog: EventLog) {
with(binding) { with(binding) {
val eventViewModel = EventViewModel(eventLog) val eventViewModel = EventData(eventLog)
viewModel = eventViewModel viewModel = eventViewModel
binding.lifecycleOwner = viewLifecycleOwner binding.lifecycleOwner = viewLifecycleOwner

View file

@ -29,7 +29,7 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R import org.linphone.R
import org.linphone.activities.main.chat.viewmodels.ChatRoomCreationContactViewModel import org.linphone.activities.main.chat.data.ChatRoomCreationContactData
import org.linphone.core.Address import org.linphone.core.Address
import org.linphone.core.FriendCapability import org.linphone.core.FriendCapability
import org.linphone.core.SearchResult import org.linphone.core.SearchResult
@ -74,7 +74,7 @@ class ChatRoomCreationContactsAdapter(
) : RecyclerView.ViewHolder(binding.root) { ) : RecyclerView.ViewHolder(binding.root) {
fun bind(searchResult: SearchResult) { fun bind(searchResult: SearchResult) {
with(binding) { with(binding) {
val searchResultViewModel = ChatRoomCreationContactViewModel(searchResult) val searchResultViewModel = ChatRoomCreationContactData(searchResult)
viewModel = searchResultViewModel viewModel = searchResultViewModel
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner
@ -97,7 +97,7 @@ class ChatRoomCreationContactsAdapter(
private fun updateSecurity( private fun updateSecurity(
searchResult: SearchResult, searchResult: SearchResult,
viewModel: ChatRoomCreationContactViewModel, viewModel: ChatRoomCreationContactData,
securityEnabled: Boolean securityEnabled: Boolean
) { ) {
val searchAddress = searchResult.address val searchAddress = searchResult.address

View file

@ -29,7 +29,7 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import org.linphone.R import org.linphone.R
import org.linphone.activities.main.chat.GroupChatRoomMember import org.linphone.activities.main.chat.GroupChatRoomMember
import org.linphone.activities.main.chat.viewmodels.GroupInfoParticipantViewModel import org.linphone.activities.main.chat.data.GroupInfoParticipantData
import org.linphone.databinding.ChatRoomGroupInfoParticipantCellBinding import org.linphone.databinding.ChatRoomGroupInfoParticipantCellBinding
import org.linphone.utils.Event import org.linphone.utils.Event
@ -55,17 +55,21 @@ class GroupInfoParticipantsAdapter(
(holder as ViewHolder).bind(getItem(position)) (holder as ViewHolder).bind(getItem(position))
} }
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
(holder as ViewHolder).binding.viewModel?.destroy()
}
fun showAdminControls(show: Boolean) { fun showAdminControls(show: Boolean) {
showAdmin = show showAdmin = show
notifyDataSetChanged() notifyDataSetChanged()
} }
inner class ViewHolder( inner class ViewHolder(
private val binding: ChatRoomGroupInfoParticipantCellBinding val binding: ChatRoomGroupInfoParticipantCellBinding
) : RecyclerView.ViewHolder(binding.root) { ) : RecyclerView.ViewHolder(binding.root) {
fun bind(participant: GroupChatRoomMember) { fun bind(participant: GroupChatRoomMember) {
with(binding) { with(binding) {
val participantViewModel = GroupInfoParticipantViewModel(participant) val participantViewModel = GroupInfoParticipantData(participant)
participantViewModel.showAdminControls.value = showAdmin participantViewModel.showAdminControls.value = showAdmin
viewModel = participantViewModel viewModel = participantViewModel

View file

@ -29,7 +29,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import org.linphone.R import org.linphone.R
import org.linphone.activities.main.chat.viewmodels.ImdnParticipantViewModel import org.linphone.activities.main.chat.data.ImdnParticipantData
import org.linphone.core.ChatMessage import org.linphone.core.ChatMessage
import org.linphone.core.ParticipantImdnState import org.linphone.core.ParticipantImdnState
import org.linphone.databinding.ChatRoomImdnParticipantCellBinding import org.linphone.databinding.ChatRoomImdnParticipantCellBinding
@ -51,12 +51,16 @@ class ImdnAdapter(
(holder as ViewHolder).bind(getItem(position)) (holder as ViewHolder).bind(getItem(position))
} }
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
(holder as ViewHolder).binding.viewModel?.destroy()
}
inner class ViewHolder( inner class ViewHolder(
private val binding: ChatRoomImdnParticipantCellBinding val binding: ChatRoomImdnParticipantCellBinding
) : RecyclerView.ViewHolder(binding.root) { ) : RecyclerView.ViewHolder(binding.root) {
fun bind(participantImdnState: ParticipantImdnState) { fun bind(participantImdnState: ParticipantImdnState) {
with(binding) { with(binding) {
viewModel = ImdnParticipantViewModel(participantImdnState) viewModel = ImdnParticipantData(participantImdnState)
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner

View file

@ -17,30 +17,28 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import kotlinx.coroutines.*
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.linphone.utils.FileUtils import org.linphone.utils.FileUtils
import org.linphone.utils.ImageUtils import org.linphone.utils.ImageUtils
class ChatMessageAttachmentViewModel( class ChatMessageAttachmentData(
val path: String, val path: String,
private val deleteCallback: (attachment: ChatMessageAttachmentViewModel) -> Unit private val deleteCallback: (attachment: ChatMessageAttachmentData) -> Unit
) : ViewModel() { ) {
val fileName: String = FileUtils.getNameFromFilePath(path) val fileName: String = FileUtils.getNameFromFilePath(path)
val isImage: Boolean = FileUtils.isExtensionImage(path) val isImage: Boolean = FileUtils.isExtensionImage(path)
val isVideo: Boolean = FileUtils.isExtensionVideo(path) val isVideo: Boolean = FileUtils.isExtensionVideo(path)
val videoPreview = MutableLiveData<Bitmap>() val videoPreview = MutableLiveData<Bitmap>()
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
init { init {
if (isVideo) { if (isVideo) {
viewModelScope.launch { scope.launch {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
videoPreview.postValue(ImageUtils.getVideoPreview(path)) videoPreview.postValue(ImageUtils.getVideoPreview(path))
} }
@ -48,6 +46,10 @@ class ChatMessageAttachmentViewModel(
} }
} }
fun destroy() {
scope.cancel()
}
fun delete() { fun delete() {
deleteCallback(this) deleteCallback(this)
} }

View file

@ -17,15 +17,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import kotlinx.coroutines.*
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
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
@ -34,11 +30,11 @@ import org.linphone.utils.AppUtils
import org.linphone.utils.FileUtils import org.linphone.utils.FileUtils
import org.linphone.utils.ImageUtils import org.linphone.utils.ImageUtils
class ChatMessageContentViewModel( class ChatMessageContentData(
val content: Content, val content: Content,
private val chatMessage: ChatMessage, private val chatMessage: ChatMessage,
private val listener: OnContentClickedListener? private val listener: OnContentClickedListener?
) : ViewModel() { ) {
val isImage = MutableLiveData<Boolean>() val isImage = MutableLiveData<Boolean>()
val isVideo = MutableLiveData<Boolean>() val isVideo = MutableLiveData<Boolean>()
val isAudio = MutableLiveData<Boolean>() val isAudio = MutableLiveData<Boolean>()
@ -89,6 +85,8 @@ class ChatMessageContentViewModel(
} }
} }
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
init { init {
filePath.value = "" filePath.value = ""
fileName.value = if (content.name.isNullOrEmpty() && !content.filePath.isNullOrEmpty()) { fileName.value = if (content.name.isNullOrEmpty() && !content.filePath.isNullOrEmpty()) {
@ -110,7 +108,7 @@ class ChatMessageContentViewModel(
isAudio.value = FileUtils.isExtensionAudio(path) isAudio.value = FileUtils.isExtensionAudio(path)
if (isVideo.value == true) { if (isVideo.value == true) {
viewModelScope.launch { scope.launch {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
videoPreview.postValue(ImageUtils.getVideoPreview(path)) videoPreview.postValue(ImageUtils.getVideoPreview(path))
} }
@ -134,15 +132,15 @@ class ChatMessageContentViewModel(
chatMessage.addListener(chatMessageListener) chatMessage.addListener(chatMessageListener)
} }
override fun onCleared() { fun destroy() {
scope.cancel()
val path = filePath.value.orEmpty() val path = filePath.value.orEmpty()
if (content.isFileEncrypted && path.isNotEmpty()) { if (content.isFileEncrypted && path.isNotEmpty()) {
Log.i("[Content] Deleting file used for preview: $path") Log.i("[Content] Deleting file used for preview: $path")
FileUtils.deleteFile(path) FileUtils.deleteFile(path)
filePath.value = "" filePath.value = ""
} }
super.onCleared()
} }
fun download() { fun download() {

View file

@ -17,20 +17,18 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import android.os.CountDownTimer import android.os.CountDownTimer
import android.text.Spannable import android.text.Spannable
import android.text.util.Linkify 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 androidx.lifecycle.viewModelScope import kotlinx.coroutines.*
import kotlinx.coroutines.launch
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R import org.linphone.R
import org.linphone.compatibility.Compatibility import org.linphone.contact.GenericContactData
import org.linphone.contact.GenericContactViewModel
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
@ -40,10 +38,10 @@ import org.linphone.utils.AppUtils
import org.linphone.utils.PermissionHelper import org.linphone.utils.PermissionHelper
import org.linphone.utils.TimestampUtils import org.linphone.utils.TimestampUtils
class ChatMessageViewModel( class ChatMessageData(
val chatMessage: ChatMessage, val chatMessage: ChatMessage,
private var contentListener: OnContentClickedListener? = null private var contentListener: OnContentClickedListener? = null
) : GenericContactViewModel(chatMessage.fromAddress) { ) : GenericContactData(chatMessage.fromAddress) {
val sendInProgress = MutableLiveData<Boolean>() val sendInProgress = MutableLiveData<Boolean>()
val transferInProgress = MutableLiveData<Boolean>() val transferInProgress = MutableLiveData<Boolean>()
@ -58,7 +56,7 @@ class ChatMessageViewModel(
val hideTime = MutableLiveData<Boolean>() val hideTime = MutableLiveData<Boolean>()
val contents = MutableLiveData<ArrayList<ChatMessageContentViewModel>>() val contents = MutableLiveData<ArrayList<ChatMessageContentData>>()
val time = MutableLiveData<String>() val time = MutableLiveData<String>()
@ -76,6 +74,7 @@ class ChatMessageViewModel(
// TODO FIXME : find a way to refresh outgoing message downloaded // TODO FIXME : find a way to refresh outgoing message downloaded
if (state == ChatMessage.State.FileTransferDone && !message.isOutgoing) { if (state == ChatMessage.State.FileTransferDone && !message.isOutgoing) {
Log.i("[Chat Message] File transfer done") Log.i("[Chat Message] File transfer done")
contents.value.orEmpty().forEach(ChatMessageContentData::destroy)
updateContentsList() updateContentsList()
if (!message.isEphemeral && corePreferences.makePublicMediaFilesDownloaded) { if (!message.isEphemeral && corePreferences.makePublicMediaFilesDownloaded) {
@ -109,11 +108,12 @@ class ChatMessageViewModel(
updateContentsList() updateContentsList()
} }
override fun onCleared() { override fun destroy() {
super.destroy()
contents.value.orEmpty().forEach(ChatMessageContentData::destroy)
chatMessage.removeListener(listener) chatMessage.removeListener(listener)
contentListener = null contentListener = null
super.onCleared()
} }
fun updateBubbleBackground(hasPrevious: Boolean, hasNext: Boolean) { fun updateBubbleBackground(hasPrevious: Boolean, hasNext: Boolean) {
@ -164,16 +164,19 @@ class ChatMessageViewModel(
} }
private fun updateContentsList() { private fun updateContentsList() {
val list = arrayListOf<ChatMessageContentViewModel>() contents.value.orEmpty().forEach(ChatMessageContentData::destroy)
val list = arrayListOf<ChatMessageContentData>()
for (content in chatMessage.contents) { for (content in chatMessage.contents) {
if (content.isFileTransfer || content.isFile) { if (content.isFileTransfer || content.isFile) {
list.add(ChatMessageContentViewModel(content, chatMessage, contentListener)) list.add(ChatMessageContentData(content, chatMessage, contentListener))
} else if (content.isText) { } else if (content.isText) {
val spannable = Spannable.Factory.getInstance().newSpannable(content.utf8Text) val spannable = Spannable.Factory.getInstance().newSpannable(content.utf8Text)
LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS) LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS)
text.value = spannable text.value = spannable
} }
} }
contents.value = list contents.value = list
} }
@ -210,33 +213,6 @@ class ChatMessageViewModel(
} }
private fun addContentToMediaStore(content: Content) { private fun addContentToMediaStore(content: Content) {
viewModelScope.launch { coreContext.addContentToMediaStore(content)
when (content.type) {
"image" -> {
if (Compatibility.addImageToMediaStore(coreContext.context, content)) {
Log.i("[Chat Message] Adding image ${content.name} to Media Store terminated")
} else {
Log.e("[Chat Message] Something went wrong while copying file to Media Store...")
}
}
"video" -> {
if (Compatibility.addVideoToMediaStore(coreContext.context, content)) {
Log.i("[Chat Message] Adding video ${content.name} to Media Store terminated")
} else {
Log.e("[Chat Message] Something went wrong while copying file to Media Store...")
}
}
"audio" -> {
if (Compatibility.addAudioToMediaStore(coreContext.context, content)) {
Log.i("[Chat Message] Adding audio ${content.name} to Media Store terminated")
} else {
Log.e("[Chat Message] Something went wrong while copying file to Media Store...")
}
}
else -> {
Log.w("[Chat Message] File ${content.name} isn't either an image, an audio file or a video, can't add it to the Media Store")
}
}
}
} }
} }

View file

@ -17,17 +17,16 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.contact.Contact import org.linphone.contact.Contact
import org.linphone.contact.ContactViewModelInterface import org.linphone.contact.ContactDataInterface
import org.linphone.core.* import org.linphone.core.*
import org.linphone.utils.LinphoneUtils import org.linphone.utils.LinphoneUtils
class ChatRoomCreationContactViewModel(private val searchResult: SearchResult) : ViewModel(), ContactViewModelInterface { class ChatRoomCreationContactData(private val searchResult: SearchResult) : ContactDataInterface {
override val contact = MutableLiveData<Contact>() override val contact = MutableLiveData<Contact>()
override val displayName: String by lazy { override val displayName: String by lazy {
@ -58,8 +57,6 @@ class ChatRoomCreationContactViewModel(private val searchResult: SearchResult) :
val hasLimeX3DHCapability: Boolean val hasLimeX3DHCapability: Boolean
get() = searchResult.hasCapability(FriendCapability.LimeX3Dh) get() = searchResult.hasCapability(FriendCapability.LimeX3Dh)
var listener: ChatRoomCreationContactSelectionListener? = null
init { init {
isDisabled.value = false isDisabled.value = false
isSelected.value = false isSelected.value = false
@ -75,7 +72,3 @@ class ChatRoomCreationContactViewModel(private val searchResult: SearchResult) :
} }
} }
} }
interface ChatRoomCreationContactSelectionListener {
fun onUnSelected(searchResult: SearchResult)
}

View file

@ -17,15 +17,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R import org.linphone.R
import org.linphone.core.ChatRoomSecurityLevel import org.linphone.core.ChatRoomSecurityLevel
import org.linphone.core.ParticipantDevice import org.linphone.core.ParticipantDevice
class DevicesListChildViewModel(private val device: ParticipantDevice) : ViewModel() { class DevicesListChildData(private val device: ParticipantDevice) {
val deviceName: String = device.name.orEmpty() val deviceName: String = device.name.orEmpty()
val securityLevelIcon: Int by lazy { val securityLevelIcon: Int by lazy {

View file

@ -17,17 +17,17 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R import org.linphone.R
import org.linphone.contact.GenericContactViewModel import org.linphone.contact.GenericContactData
import org.linphone.core.ChatRoomSecurityLevel import org.linphone.core.ChatRoomSecurityLevel
import org.linphone.core.Participant import org.linphone.core.Participant
import org.linphone.utils.LinphoneUtils import org.linphone.utils.LinphoneUtils
class DevicesListGroupViewModel(private val participant: Participant) : GenericContactViewModel(participant.address) { class DevicesListGroupData(private val participant: Participant) : GenericContactData(participant.address) {
override val securityLevel: ChatRoomSecurityLevel override val securityLevel: ChatRoomSecurityLevel
get() = participant.securityLevel get() = participant.securityLevel
@ -53,14 +53,14 @@ class DevicesListGroupViewModel(private val participant: Participant) : GenericC
val isExpanded = MutableLiveData<Boolean>() val isExpanded = MutableLiveData<Boolean>()
val devices = MutableLiveData<ArrayList<DevicesListChildViewModel>>() val devices = MutableLiveData<ArrayList<DevicesListChildData>>()
init { init {
isExpanded.value = false isExpanded.value = false
val list = arrayListOf<DevicesListChildViewModel>() val list = arrayListOf<DevicesListChildData>()
for (device in participant.devices) { for (device in participant.devices) {
list.add(DevicesListChildViewModel((device))) list.add(DevicesListChildData((device)))
} }
devices.value = list devices.value = list
} }

View file

@ -17,16 +17,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import androidx.lifecycle.ViewModel class EphemeralDurationData(
class EphemeralDurationViewModel(
val textResource: Int, val textResource: Int,
selectedDuration: Long, selectedDuration: Long,
private val duration: Long, private val duration: Long,
private val listener: DurationItemClicked private val listener: DurationItemClicked
) : ViewModel() { ) {
val selected: Boolean = selectedDuration == duration val selected: Boolean = selectedDuration == duration
fun setSelected() { fun setSelected() {

View file

@ -17,11 +17,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import android.content.Context import android.content.Context
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R import org.linphone.R
import org.linphone.contact.Contact import org.linphone.contact.Contact
@ -29,7 +28,7 @@ import org.linphone.core.EventLog
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
import org.linphone.utils.LinphoneUtils import org.linphone.utils.LinphoneUtils
class EventViewModel(private val eventLog: EventLog) : ViewModel() { class EventData(private val eventLog: EventLog) {
val text = MutableLiveData<String>() val text = MutableLiveData<String>()
val isSecurity: Boolean by lazy { val isSecurity: Boolean by lazy {

View file

@ -17,15 +17,15 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import org.linphone.activities.main.chat.GroupChatRoomMember import org.linphone.activities.main.chat.GroupChatRoomMember
import org.linphone.contact.GenericContactViewModel import org.linphone.contact.GenericContactData
import org.linphone.core.ChatRoomSecurityLevel import org.linphone.core.ChatRoomSecurityLevel
import org.linphone.utils.LinphoneUtils import org.linphone.utils.LinphoneUtils
class GroupInfoParticipantViewModel(private val participant: GroupChatRoomMember) : GenericContactViewModel(participant.address) { class GroupInfoParticipantData(private val participant: GroupChatRoomMember) : GenericContactData(participant.address) {
override val securityLevel: ChatRoomSecurityLevel override val securityLevel: ChatRoomSecurityLevel
get() = participant.securityLevel get() = participant.securityLevel

View file

@ -17,13 +17,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.linphone.activities.main.chat.viewmodels package org.linphone.activities.main.chat.data
import org.linphone.contact.GenericContactViewModel import org.linphone.contact.GenericContactData
import org.linphone.core.ParticipantImdnState import org.linphone.core.ParticipantImdnState
import org.linphone.utils.TimestampUtils import org.linphone.utils.TimestampUtils
class ImdnParticipantViewModel(imdnState: ParticipantImdnState) : GenericContactViewModel(imdnState.participant.address) { class ImdnParticipantData(imdnState: ParticipantImdnState) : GenericContactData(imdnState.participant.address) {
val sipUri: String = imdnState.participant.address.asStringUriOnly() val sipUri: String = imdnState.participant.address.asStringUriOnly()
val time: String = TimestampUtils.toString(imdnState.stateChangeTime) val time: String = TimestampUtils.toString(imdnState.stateChangeTime)

View file

@ -24,6 +24,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import java.io.File import java.io.File
import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.activities.main.chat.data.ChatMessageAttachmentData
import org.linphone.core.ChatMessage import org.linphone.core.ChatMessage
import org.linphone.core.ChatRoom import org.linphone.core.ChatRoom
import org.linphone.core.ChatRoomCapabilities import org.linphone.core.ChatRoomCapabilities
@ -42,7 +43,7 @@ class ChatMessageSendingViewModelFactory(private val chatRoom: ChatRoom) :
class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel() { class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel() {
var temporaryFileUploadPath: File? = null var temporaryFileUploadPath: File? = null
val attachments = MutableLiveData<ArrayList<ChatMessageAttachmentViewModel>>() val attachments = MutableLiveData<ArrayList<ChatMessageAttachmentData>>()
val attachFileEnabled = MutableLiveData<Boolean>() val attachFileEnabled = MutableLiveData<Boolean>()
@ -60,6 +61,11 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
isReadOnly.value = chatRoom.hasBeenLeft() isReadOnly.value = chatRoom.hasBeenLeft()
} }
override fun onCleared() {
attachments.value.orEmpty().forEach(ChatMessageAttachmentData::destroy)
super.onCleared()
}
fun onTextToSendChanged(value: String) { fun onTextToSendChanged(value: String) {
sendMessageEnabled.value = value.isNotEmpty() || attachments.value?.isNotEmpty() ?: false sendMessageEnabled.value = value.isNotEmpty() || attachments.value?.isNotEmpty() ?: false
if (value.isNotEmpty()) { if (value.isNotEmpty()) {
@ -75,9 +81,9 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
} }
fun addAttachment(path: String) { fun addAttachment(path: String) {
val list = arrayListOf<ChatMessageAttachmentViewModel>() val list = arrayListOf<ChatMessageAttachmentData>()
list.addAll(attachments.value.orEmpty()) list.addAll(attachments.value.orEmpty())
list.add(ChatMessageAttachmentViewModel(path) { list.add(ChatMessageAttachmentData(path) {
removeAttachment(it) removeAttachment(it)
}) })
attachments.value = list attachments.value = list
@ -88,10 +94,11 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
} }
} }
private fun removeAttachment(attachment: ChatMessageAttachmentViewModel) { private fun removeAttachment(attachment: ChatMessageAttachmentData) {
val list = arrayListOf<ChatMessageAttachmentViewModel>() val list = arrayListOf<ChatMessageAttachmentData>()
list.addAll(attachments.value.orEmpty()) list.addAll(attachments.value.orEmpty())
list.remove(attachment) list.remove(attachment)
attachment.destroy()
attachments.value = list attachments.value = list
sendMessageEnabled.value = textToSend.value.orEmpty().isNotEmpty() || list.isNotEmpty() sendMessageEnabled.value = textToSend.value.orEmpty().isNotEmpty() || list.isNotEmpty()
@ -137,6 +144,7 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
message.send() message.send()
} }
attachments.value.orEmpty().forEach(ChatMessageAttachmentData::destroy)
attachments.value = arrayListOf() attachments.value = arrayListOf()
} }

View file

@ -25,7 +25,7 @@ import androidx.lifecycle.ViewModelProvider
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R import org.linphone.R
import org.linphone.contact.Contact import org.linphone.contact.Contact
import org.linphone.contact.ContactViewModelInterface import org.linphone.contact.ContactDataInterface
import org.linphone.contact.ContactsUpdatedListenerStub import org.linphone.contact.ContactsUpdatedListenerStub
import org.linphone.core.* import org.linphone.core.*
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
@ -42,7 +42,7 @@ class ChatRoomViewModelFactory(private val chatRoom: ChatRoom) :
} }
} }
class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactViewModelInterface { class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterface {
override val contact = MutableLiveData<Contact>() override val contact = MutableLiveData<Contact>()
override val displayName: String override val displayName: String

View file

@ -22,6 +22,7 @@ package org.linphone.activities.main.chat.viewmodels
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import org.linphone.activities.main.chat.data.DevicesListGroupData
import org.linphone.core.ChatRoom import org.linphone.core.ChatRoom
import org.linphone.core.ChatRoomListenerStub import org.linphone.core.ChatRoomListenerStub
import org.linphone.core.EventLog import org.linphone.core.EventLog
@ -36,7 +37,7 @@ class DevicesListViewModelFactory(private val chatRoom: ChatRoom) :
} }
class DevicesListViewModel(private val chatRoom: ChatRoom) : ViewModel() { class DevicesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
val participants = MutableLiveData<ArrayList<DevicesListGroupViewModel>>() val participants = MutableLiveData<ArrayList<DevicesListGroupData>>()
private val listener = object : ChatRoomListenerStub() { private val listener = object : ChatRoomListenerStub() {
override fun onParticipantDeviceAdded(chatRoom: ChatRoom, eventLog: EventLog) { override fun onParticipantDeviceAdded(chatRoom: ChatRoom, eventLog: EventLog) {
@ -62,17 +63,21 @@ class DevicesListViewModel(private val chatRoom: ChatRoom) : ViewModel() {
} }
override fun onCleared() { override fun onCleared() {
participants.value.orEmpty().forEach(DevicesListGroupData::destroy)
chatRoom.removeListener(listener) chatRoom.removeListener(listener)
super.onCleared() super.onCleared()
} }
private fun updateParticipants() { private fun updateParticipants() {
val list = arrayListOf<DevicesListGroupViewModel>() participants.value.orEmpty().forEach(DevicesListGroupData::destroy)
val list = arrayListOf<DevicesListGroupData>()
val me = chatRoom.me val me = chatRoom.me
if (me != null) list.add(DevicesListGroupViewModel(me)) if (me != null) list.add(DevicesListGroupData(me))
for (participant in chatRoom.participants) { for (participant in chatRoom.participants) {
list.add(DevicesListGroupViewModel(participant)) list.add(DevicesListGroupData(participant))
} }
participants.value = list participants.value = list
} }
} }

View file

@ -23,6 +23,8 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import org.linphone.R import org.linphone.R
import org.linphone.activities.main.chat.data.DurationItemClicked
import org.linphone.activities.main.chat.data.EphemeralDurationData
import org.linphone.core.ChatRoom import org.linphone.core.ChatRoom
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
@ -36,7 +38,7 @@ class EphemeralViewModelFactory(private val chatRoom: ChatRoom) :
} }
class EphemeralViewModel(private val chatRoom: ChatRoom) : ViewModel() { class EphemeralViewModel(private val chatRoom: ChatRoom) : ViewModel() {
val durationsList = MutableLiveData<ArrayList<EphemeralDurationViewModel>>() val durationsList = MutableLiveData<ArrayList<EphemeralDurationData>>()
var currentSelectedDuration: Long = 0 var currentSelectedDuration: Long = 0
@ -74,13 +76,13 @@ class EphemeralViewModel(private val chatRoom: ChatRoom) : ViewModel() {
} }
private fun computeEphemeralDurationValues() { private fun computeEphemeralDurationValues() {
val list = arrayListOf<EphemeralDurationViewModel>() val list = arrayListOf<EphemeralDurationData>()
list.add(EphemeralDurationViewModel(R.string.chat_room_ephemeral_message_disabled, currentSelectedDuration, 0, listener)) list.add(EphemeralDurationData(R.string.chat_room_ephemeral_message_disabled, currentSelectedDuration, 0, listener))
list.add(EphemeralDurationViewModel(R.string.chat_room_ephemeral_message_one_minute, currentSelectedDuration, 60, listener)) list.add(EphemeralDurationData(R.string.chat_room_ephemeral_message_one_minute, currentSelectedDuration, 60, listener))
list.add(EphemeralDurationViewModel(R.string.chat_room_ephemeral_message_one_hour, currentSelectedDuration, 3600, listener)) list.add(EphemeralDurationData(R.string.chat_room_ephemeral_message_one_hour, currentSelectedDuration, 3600, listener))
list.add(EphemeralDurationViewModel(R.string.chat_room_ephemeral_message_one_day, currentSelectedDuration, 86400, listener)) list.add(EphemeralDurationData(R.string.chat_room_ephemeral_message_one_day, currentSelectedDuration, 86400, listener))
list.add(EphemeralDurationViewModel(R.string.chat_room_ephemeral_message_three_days, currentSelectedDuration, 259200, listener)) list.add(EphemeralDurationData(R.string.chat_room_ephemeral_message_three_days, currentSelectedDuration, 259200, listener))
list.add(EphemeralDurationViewModel(R.string.chat_room_ephemeral_message_one_week, currentSelectedDuration, 604800, listener)) list.add(EphemeralDurationData(R.string.chat_room_ephemeral_message_one_week, currentSelectedDuration, 604800, listener))
durationsList.value = list durationsList.value = list
} }
} }

View file

@ -22,6 +22,7 @@ package org.linphone.activities.main.chat.viewmodels
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import org.linphone.activities.main.chat.data.ChatMessageData
import org.linphone.core.ChatMessage import org.linphone.core.ChatMessage
import org.linphone.core.ChatMessageListenerStub import org.linphone.core.ChatMessageListenerStub
import org.linphone.core.ParticipantImdnState import org.linphone.core.ParticipantImdnState
@ -38,7 +39,7 @@ class ImdnViewModelFactory(private val chatMessage: ChatMessage) :
class ImdnViewModel(private val chatMessage: ChatMessage) : ViewModel() { class ImdnViewModel(private val chatMessage: ChatMessage) : ViewModel() {
val participants = MutableLiveData<ArrayList<ParticipantImdnState>>() val participants = MutableLiveData<ArrayList<ParticipantImdnState>>()
val chatMessageViewModel = ChatMessageViewModel(chatMessage) val chatMessageViewModel = ChatMessageData(chatMessage)
private val listener = object : ChatMessageListenerStub() { private val listener = object : ChatMessageListenerStub() {
override fun onParticipantImdnStateChanged( override fun onParticipantImdnStateChanged(

View file

@ -43,7 +43,7 @@ class ContactEditorViewModelFactory(private val contact: Contact?) :
} }
} }
class ContactEditorViewModel(val c: Contact?) : ViewModel(), ContactViewModelInterface { class ContactEditorViewModel(val c: Contact?) : ViewModel(), ContactDataInterface {
override val contact = MutableLiveData<Contact>() override val contact = MutableLiveData<Contact>()
override val displayName: String override val displayName: String

View file

@ -29,7 +29,7 @@ import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R import org.linphone.R
import org.linphone.activities.main.viewmodels.ErrorReportingViewModel import org.linphone.activities.main.viewmodels.ErrorReportingViewModel
import org.linphone.contact.Contact import org.linphone.contact.Contact
import org.linphone.contact.ContactViewModelInterface import org.linphone.contact.ContactDataInterface
import org.linphone.contact.ContactsUpdatedListenerStub import org.linphone.contact.ContactsUpdatedListenerStub
import org.linphone.contact.NativeContact import org.linphone.contact.NativeContact
import org.linphone.core.* import org.linphone.core.*
@ -46,7 +46,7 @@ class ContactViewModelFactory(private val contact: Contact) :
} }
} }
class ContactViewModel(private val c: Contact) : ErrorReportingViewModel(), ContactViewModelInterface { class ContactViewModel(private val c: Contact) : ErrorReportingViewModel(), ContactDataInterface {
override val contact = MutableLiveData<Contact>() override val contact = MutableLiveData<Contact>()
override val displayName: String by lazy { override val displayName: String by lazy {

View file

@ -51,7 +51,7 @@ class BigContactAvatarView : LinearLayout {
) )
} }
fun setViewModel(viewModel: ContactViewModelInterface?) { fun setViewModel(viewModel: ContactDataInterface?) {
if (viewModel == null) { if (viewModel == null) {
binding.root.visibility = View.GONE binding.root.visibility = View.GONE
return return

View file

@ -51,7 +51,7 @@ class ContactAvatarView : LinearLayout {
) )
} }
fun setViewModel(viewModel: ContactViewModelInterface) { fun setViewModel(viewModel: ContactDataInterface) {
val contact: Contact? = viewModel.contact.value val contact: Contact? = viewModel.contact.value
val initials = if (contact != null) { val initials = if (contact != null) {
AppUtils.getInitials(contact.fullName ?: contact.firstName + " " + contact.lastName) AppUtils.getInitials(contact.fullName ?: contact.firstName + " " + contact.lastName)

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2010-2021 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.contact
import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication
import org.linphone.core.Address
import org.linphone.core.ChatRoomSecurityLevel
import org.linphone.utils.LinphoneUtils
interface ContactDataInterface {
val contact: MutableLiveData<Contact>
val displayName: String
val securityLevel: ChatRoomSecurityLevel
get() = ChatRoomSecurityLevel.ClearText
val showGroupChatAvatar: Boolean
get() = false
}
open class GenericContactData(private val sipAddress: Address) : ContactDataInterface {
override val displayName: String = LinphoneUtils.getDisplayName(sipAddress)
override val contact = MutableLiveData<Contact>()
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
override fun onContactUpdated(contact: Contact) {
contactLookup()
}
}
init {
LinphoneApplication.coreContext.contactsManager.addListener(contactsUpdatedListener)
contactLookup()
}
open fun destroy() {
LinphoneApplication.coreContext.contactsManager.removeListener(contactsUpdatedListener)
}
private fun contactLookup() {
contact.value = LinphoneApplication.coreContext.contactsManager.findContactByAddress(sipAddress)
}
}

View file

@ -23,22 +23,9 @@ import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.activities.main.viewmodels.ErrorReportingViewModel import org.linphone.activities.main.viewmodels.ErrorReportingViewModel
import org.linphone.core.Address import org.linphone.core.Address
import org.linphone.core.ChatRoomSecurityLevel
import org.linphone.utils.LinphoneUtils import org.linphone.utils.LinphoneUtils
interface ContactViewModelInterface { abstract class GenericContactViewModel(private val sipAddress: Address) : ErrorReportingViewModel(), ContactDataInterface {
val contact: MutableLiveData<Contact>
val displayName: String
val securityLevel: ChatRoomSecurityLevel
get() = ChatRoomSecurityLevel.ClearText
val showGroupChatAvatar: Boolean
get() = false
}
abstract class GenericContactViewModel(private val sipAddress: Address) : ErrorReportingViewModel(), ContactViewModelInterface {
override val displayName: String = LinphoneUtils.getDisplayName(sipAddress) override val displayName: String = LinphoneUtils.getDisplayName(sipAddress)
override val contact = MutableLiveData<Contact>() override val contact = MutableLiveData<Contact>()

View file

@ -49,6 +49,7 @@ import javax.crypto.KeyGenerator
import javax.crypto.SecretKey import javax.crypto.SecretKey
import javax.crypto.spec.GCMParameterSpec import javax.crypto.spec.GCMParameterSpec
import kotlin.math.abs import kotlin.math.abs
import kotlinx.coroutines.*
import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R import org.linphone.R
import org.linphone.activities.call.CallActivity import org.linphone.activities.call.CallActivity
@ -100,6 +101,8 @@ class CoreContext(val context: Context, coreConfig: Config) {
private val loggingService = Factory.instance().loggingService private val loggingService = Factory.instance().loggingService
private val coroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
private var gsmCallActive = false private var gsmCallActive = false
private val phoneStateListener = object : PhoneStateListener() { private val phoneStateListener = object : PhoneStateListener() {
override fun onCallStateChanged(state: Int, phoneNumber: String?) { override fun onCallStateChanged(state: Int, phoneNumber: String?) {
@ -322,6 +325,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
fun stop() { fun stop() {
Log.i("[Context] Stopping") Log.i("[Context] Stopping")
coroutineScope.cancel()
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
Log.i("[Context] Unregistering phone state listener") Log.i("[Context] Unregistering phone state listener")
@ -598,6 +602,39 @@ class CoreContext(val context: Context, coreConfig: Config) {
} }
} }
/* Coroutine related */
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...")
}
}
"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...")
}
}
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")
}
}
}
}
/* Start call related activities */ /* Start call related activities */
private fun onIncomingReceived() { private fun onIncomingReceived() {

View file

@ -11,7 +11,7 @@
type="android.view.View.OnClickListener" /> type="android.view.View.OnClickListener" />
<variable <variable
name="viewModel" name="viewModel"
type="org.linphone.activities.main.chat.viewmodels.EventViewModel" /> type="org.linphone.activities.main.chat.data.EventData" />
<variable <variable
name="selectionListViewModel" name="selectionListViewModel"
type="org.linphone.activities.main.viewmodels.ListTopBarViewModel" /> type="org.linphone.activities.main.viewmodels.ListTopBarViewModel" />

View file

@ -6,7 +6,7 @@
<import type="android.view.View"/> <import type="android.view.View"/>
<variable <variable
name="data" name="data"
type="org.linphone.activities.main.chat.viewmodels.ChatMessageAttachmentViewModel" /> type="org.linphone.activities.main.chat.data.ChatMessageAttachmentData" />
</data> </data>
<RelativeLayout <RelativeLayout

View file

@ -6,7 +6,7 @@
<import type="android.view.View"/> <import type="android.view.View"/>
<variable <variable
name="data" name="data"
type="org.linphone.activities.main.chat.viewmodels.ChatMessageContentViewModel" /> type="org.linphone.activities.main.chat.data.ChatMessageContentData" />
<variable <variable
name="longClickListener" name="longClickListener"
type="android.view.View.OnLongClickListener"/> type="android.view.View.OnLongClickListener"/>

View file

@ -18,7 +18,7 @@
type="Integer"/> type="Integer"/>
<variable <variable
name="viewModel" name="viewModel"
type="org.linphone.activities.main.chat.viewmodels.ChatMessageViewModel" /> type="org.linphone.activities.main.chat.data.ChatMessageData" />
<variable <variable
name="selectionListViewModel" name="selectionListViewModel"
type="org.linphone.activities.main.viewmodels.ListTopBarViewModel" /> type="org.linphone.activities.main.viewmodels.ListTopBarViewModel" />

View file

@ -10,7 +10,7 @@
type="android.view.View.OnClickListener"/> type="android.view.View.OnClickListener"/>
<variable <variable
name="viewModel" name="viewModel"
type="org.linphone.activities.main.chat.viewmodels.ChatRoomCreationContactViewModel" /> type="org.linphone.activities.main.chat.data.ChatRoomCreationContactData" />
</data> </data>
<FrameLayout <FrameLayout

View file

@ -5,7 +5,7 @@
<import type="android.view.View"/> <import type="android.view.View"/>
<variable <variable
name="data" name="data"
type="org.linphone.activities.main.chat.viewmodels.DevicesListChildViewModel" /> type="org.linphone.activities.main.chat.data.DevicesListChildData" />
</data> </data>
<RelativeLayout <RelativeLayout

View file

@ -7,7 +7,7 @@
<import type="android.view.View"/> <import type="android.view.View"/>
<variable <variable
name="data" name="data"
type="org.linphone.activities.main.chat.viewmodels.DevicesListGroupViewModel" /> type="org.linphone.activities.main.chat.data.DevicesListGroupData" />
</data> </data>
<LinearLayout <LinearLayout

View file

@ -6,7 +6,7 @@
<import type="android.graphics.Typeface" /> <import type="android.graphics.Typeface" />
<variable <variable
name="data" name="data"
type="org.linphone.activities.main.chat.viewmodels.EphemeralDurationViewModel" /> type="org.linphone.activities.main.chat.data.EphemeralDurationData" />
</data> </data>
<RelativeLayout <RelativeLayout

View file

@ -11,7 +11,7 @@
type="android.view.View.OnClickListener"/> type="android.view.View.OnClickListener"/>
<variable <variable
name="viewModel" name="viewModel"
type="org.linphone.activities.main.chat.viewmodels.GroupInfoParticipantViewModel" /> type="org.linphone.activities.main.chat.data.GroupInfoParticipantData" />
<variable <variable
name="isEncrypted" name="isEncrypted"
type="Boolean" /> type="Boolean" />

View file

@ -7,7 +7,7 @@
<import type="android.view.View"/> <import type="android.view.View"/>
<variable <variable
name="viewModel" name="viewModel"
type="org.linphone.activities.main.chat.viewmodels.ImdnParticipantViewModel" /> type="org.linphone.activities.main.chat.data.ImdnParticipantData" />
</data> </data>
<RelativeLayout <RelativeLayout