diff --git a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt index d7fd7fc1b..d5d1a5690 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt @@ -20,6 +20,7 @@ package org.linphone.activities.main.settings.viewmodels import androidx.lifecycle.MutableLiveData +import org.linphone.R import org.linphone.activities.main.settings.SettingListenerStub import org.linphone.utils.Event @@ -31,6 +32,32 @@ class ChatSettingsViewModel : GenericSettingsViewModel() { } val fileSharingUrl = MutableLiveData() + val autoDownloadListener = object : SettingListenerStub() { + override fun onListValueChanged(position: Int) { + val maxSize = when (position) { + 0 -> -1 + 1 -> 0 + else -> 10000000 + } + core.maxSizeForAutoDownloadIncomingFiles = maxSize + autoDownloadMaxSize.value = maxSize + updateAutoDownloadIndexFromMaxSize(maxSize) + } + } + val autoDownloadIndex = MutableLiveData() + val autoDownloadLabels = MutableLiveData>() + + val autoDownloadMaxSizeListener = object : SettingListenerStub() { + override fun onTextValueChanged(newValue: String) { + if (newValue.isNotEmpty()) { + val maxSize = newValue.toInt() + core.maxSizeForAutoDownloadIncomingFiles = maxSize + updateAutoDownloadIndexFromMaxSize(maxSize) + } + } + } + val autoDownloadMaxSize = MutableLiveData() + val downloadedImagesPublicListener = object : SettingListenerStub() { override fun onBoolValueChanged(newValue: Boolean) { prefs.makePublicDownloadedImages = newValue @@ -63,9 +90,30 @@ class ChatSettingsViewModel : GenericSettingsViewModel() { init { downloadedImagesPublic.value = prefs.makePublicDownloadedImages + initAutoDownloadList() launcherShortcuts.value = prefs.chatRoomShortcuts hideEmptyRooms.value = prefs.hideEmptyRooms hideRoomsRemovedProxies.value = prefs.hideRoomsFromRemovedProxies fileSharingUrl.value = core.fileTransferServer } + + private fun initAutoDownloadList() { + val labels = arrayListOf() + labels.add(prefs.getString(R.string.chat_settings_auto_download_never)) + labels.add(prefs.getString(R.string.chat_settings_auto_download_always)) + labels.add(prefs.getString(R.string.chat_settings_auto_download_under_size)) + autoDownloadLabels.value = labels + + val currentValue = core.maxSizeForAutoDownloadIncomingFiles + autoDownloadMaxSize.value = currentValue + updateAutoDownloadIndexFromMaxSize(currentValue) + } + + private fun updateAutoDownloadIndexFromMaxSize(maxSize: Int) { + autoDownloadIndex.value = when (maxSize) { + -1 -> 0 + 0 -> 1 + else -> 2 + } + } } diff --git a/app/src/main/res/layout/settings_chat_fragment.xml b/app/src/main/res/layout/settings_chat_fragment.xml index c425cd766..82b8c9406 100644 --- a/app/src/main/res/layout/settings_chat_fragment.xml +++ b/app/src/main/res/layout/settings_chat_fragment.xml @@ -73,6 +73,23 @@ linphone:defaultValue="@{viewModel.fileSharingUrl}" linphone:inputType="@{InputType.TYPE_TEXT_VARIATION_URI}"/> + + + + Sharing server URL Do not edit unless you know what you are doing! + Auto download incoming files policy + Whether to download files attached in received chat messages automatically or not + Always + Never + If lighter than given maximum size + Max size + in bytes Make downloaded images visible in native gallery Images in ephemeral messages won\'t be Create shortcuts to chat rooms in launcher