diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsFragment.kt
index edb74b12ca4..c9e8abbd4f2 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsFragment.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsFragment.kt
@@ -3,8 +3,9 @@
*
* @author Juan Carlos Garrote Gascón
* @author Aitor Ballesteros Pavón
+ * @author Jorge Aguado Recio
*
- * Copyright (C) 2023 ownCloud GmbH.
+ * Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
@@ -48,7 +49,9 @@ import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_PICTURE_UPLOADS_PA
import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_PICTURE_UPLOADS_SOURCE
import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_PICTURE_UPLOADS_WIFI_ONLY
import com.owncloud.android.domain.automaticuploads.model.UploadBehavior
+import com.owncloud.android.extensions.collectLatestLifecycleFlow
import com.owncloud.android.extensions.showAlertDialog
+import com.owncloud.android.presentation.accounts.ManageAccountsViewModel
import com.owncloud.android.ui.activity.FolderPickerActivity
import com.owncloud.android.utils.DisplayUtils
import kotlinx.coroutines.launch
@@ -59,6 +62,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
// ViewModel
private val picturesViewModel by viewModel()
+ private val manageAccountsViewModel by viewModel()
private var prefEnablePictureUploads: SwitchPreferenceCompat? = null
private var prefPictureUploadsPath: Preference? = null
@@ -103,10 +107,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
).toTypedArray()
entryValues = listOf(UploadBehavior.COPY.name, UploadBehavior.MOVE.name).toTypedArray()
}
- prefPictureUploadsAccount = findPreference(PREF__CAMERA_PICTURE_UPLOADS_ACCOUNT_NAME)?.apply {
- entries = picturesViewModel.getLoggedAccountNames()
- entryValues = picturesViewModel.getLoggedAccountNames()
- }
+ prefPictureUploadsAccount = findPreference(PREF__CAMERA_PICTURE_UPLOADS_ACCOUNT_NAME)
val comment = getString(R.string.prefs_camera_upload_source_path_title_required)
prefPictureUploadsSourcePath?.title = String.format(prefPictureUploadsSourcePath?.title.toString(), comment)
@@ -123,18 +124,30 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
private fun initStateObservers() {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
- picturesViewModel.pictureUploads.collect { pictureUploadsConfiguration ->
- enablePictureUploads(pictureUploadsConfiguration != null)
- pictureUploadsConfiguration?.let {
- prefPictureUploadsAccount?.value = it.accountName
- prefPictureUploadsPath?.summary = picturesViewModel.getUploadPathString()
- prefPictureUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path)
- prefPictureUploadsOnWifi?.isChecked = it.wifiOnly
- prefPictureUploadsOnCharging?.isChecked = it.chargingOnly
- prefPictureUploadsBehaviour?.value = it.behavior.name
- prefPictureUploadsLastSync?.summary = DisplayUtils.unixTimeToHumanReadable(it.lastSyncTimestamp)
- spaceId = it.spaceId
- } ?: resetFields()
+ collectLatestLifecycleFlow(manageAccountsViewModel.userQuotas) { listUserQuotas ->
+ val availableAccounts = listUserQuotas.filter { it.available != -4L }
+ prefPictureUploadsAccount?.apply {
+ entries = availableAccounts.map { it.accountName }.toTypedArray()
+ entryValues = availableAccounts.map { it.accountName }.toTypedArray()
+ }
+
+ if (availableAccounts.isEmpty()) {
+ disableFields()
+ } else {
+ picturesViewModel.pictureUploads.collect { pictureUploadsConfiguration ->
+ enablePictureUploads(pictureUploadsConfiguration != null)
+ pictureUploadsConfiguration?.let {
+ prefPictureUploadsAccount?.value = it.accountName
+ prefPictureUploadsPath?.summary = picturesViewModel.getUploadPathString()
+ prefPictureUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path)
+ prefPictureUploadsOnWifi?.isChecked = it.wifiOnly
+ prefPictureUploadsOnCharging?.isChecked = it.chargingOnly
+ prefPictureUploadsBehaviour?.value = it.behavior.name
+ prefPictureUploadsLastSync?.summary = DisplayUtils.unixTimeToHumanReadable(it.lastSyncTimestamp)
+ spaceId = it.spaceId
+ } ?: resetFields()
+ }
+ }
}
}
}
@@ -248,4 +261,16 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
prefPictureUploadsBehaviour?.value = UploadBehavior.COPY.name
prefPictureUploadsLastSync?.summary = null
}
+
+ private fun disableFields() {
+ prefEnablePictureUploads?.isChecked = false
+ prefEnablePictureUploads?.isEnabled = false
+ prefPictureUploadsAccount?.isEnabled = false
+ prefPictureUploadsPath?.isEnabled = false
+ prefPictureUploadsSourcePath?.isEnabled = false
+ prefPictureUploadsOnWifi?.isEnabled = false
+ prefPictureUploadsOnCharging?.isEnabled = false
+ prefPictureUploadsBehaviour?.isEnabled = false
+ prefPictureUploadsLastSync?.isEnabled = false
+ }
}
diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsViewModel.kt
index 256c28e7a90..8b1443d5439 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsViewModel.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsPictureUploadsViewModel.kt
@@ -3,8 +3,9 @@
*
* @author Juan Carlos Garrote Gascón
* @author Aitor Ballesteros Pavón
+ * @author Jorge Aguado Recio
*
- * Copyright (C) 2023 ownCloud GmbH.
+ * Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
@@ -124,8 +125,6 @@ class SettingsPictureUploadsViewModel(
fun getPictureUploadsAccount() = _pictureUploads.value?.accountName
- fun getLoggedAccountNames(): Array = accountProvider.getLoggedAccounts().map { it.name }.toTypedArray()
-
fun getPictureUploadsPath() = _pictureUploads.value?.uploadPath ?: PREF__CAMERA_UPLOADS_DEFAULT_PATH
fun getPictureUploadsSourcePath(): String? = _pictureUploads.value?.sourcePath
diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsFragment.kt
index 2fbf963fba1..1d14aee33cc 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsFragment.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsFragment.kt
@@ -3,8 +3,9 @@
*
* @author Juan Carlos Garrote Gascón
* @author Aitor Ballesteros Pavón
+ * @author Jorge Aguado Recio
*
- * Copyright (C) 2023 ownCloud GmbH.
+ * Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
@@ -48,7 +49,9 @@ import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_VIDEO_UPLOADS_PATH
import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_VIDEO_UPLOADS_SOURCE
import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_VIDEO_UPLOADS_WIFI_ONLY
import com.owncloud.android.domain.automaticuploads.model.UploadBehavior
+import com.owncloud.android.extensions.collectLatestLifecycleFlow
import com.owncloud.android.extensions.showAlertDialog
+import com.owncloud.android.presentation.accounts.ManageAccountsViewModel
import com.owncloud.android.ui.activity.FolderPickerActivity
import com.owncloud.android.utils.DisplayUtils
import kotlinx.coroutines.launch
@@ -59,6 +62,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {
// ViewModel
private val videosViewModel by viewModel()
+ private val manageAccountsViewModel by viewModel()
private var prefEnableVideoUploads: SwitchPreferenceCompat? = null
private var prefVideoUploadsPath: Preference? = null
@@ -100,10 +104,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {
entries = listOf(getString(R.string.pref_behaviour_entries_keep_file), getString(R.string.pref_behaviour_entries_remove_original_file)).toTypedArray()
entryValues = listOf(UploadBehavior.COPY.name, UploadBehavior.MOVE.name).toTypedArray()
}
- prefVideoUploadsAccount = findPreference(PREF__CAMERA_VIDEO_UPLOADS_ACCOUNT_NAME)?.apply {
- entries = videosViewModel.getLoggedAccountNames()
- entryValues = videosViewModel.getLoggedAccountNames()
- }
+ prefVideoUploadsAccount = findPreference(PREF__CAMERA_VIDEO_UPLOADS_ACCOUNT_NAME)
val comment = getString(R.string.prefs_camera_upload_source_path_title_required)
prefVideoUploadsSourcePath?.title = String.format(prefVideoUploadsSourcePath?.title.toString(), comment)
@@ -120,18 +121,30 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {
private fun initLiveDataObservers() {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
- videosViewModel.videoUploads.collect { videoUploadsConfiguration ->
- enableVideoUploads(videoUploadsConfiguration != null)
- videoUploadsConfiguration?.let {
- prefVideoUploadsAccount?.value = it.accountName
- prefVideoUploadsPath?.summary = videosViewModel.getUploadPathString()
- prefVideoUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path)
- prefVideoUploadsOnWifi?.isChecked = it.wifiOnly
- prefVideoUploadsOnCharging?.isChecked = it.chargingOnly
- prefVideoUploadsBehaviour?.value = it.behavior.name
- prefVideoUploadsLastSync?.summary = DisplayUtils.unixTimeToHumanReadable(it.lastSyncTimestamp)
- spaceId = it.spaceId
- } ?: resetFields()
+ collectLatestLifecycleFlow(manageAccountsViewModel.userQuotas) { listUserQuotas ->
+ val availableAccounts = listUserQuotas.filter { it.available != -4L }
+ prefVideoUploadsAccount?.apply {
+ entries = availableAccounts.map { it.accountName }.toTypedArray()
+ entryValues = availableAccounts.map { it.accountName }.toTypedArray()
+ }
+
+ if (availableAccounts.isEmpty()) {
+ disableFields()
+ } else {
+ videosViewModel.videoUploads.collect { videoUploadsConfiguration ->
+ enableVideoUploads(videoUploadsConfiguration != null)
+ videoUploadsConfiguration?.let {
+ prefVideoUploadsAccount?.value = it.accountName
+ prefVideoUploadsPath?.summary = videosViewModel.getUploadPathString()
+ prefVideoUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path)
+ prefVideoUploadsOnWifi?.isChecked = it.wifiOnly
+ prefVideoUploadsOnCharging?.isChecked = it.chargingOnly
+ prefVideoUploadsBehaviour?.value = it.behavior.name
+ prefVideoUploadsLastSync?.summary = DisplayUtils.unixTimeToHumanReadable(it.lastSyncTimestamp)
+ spaceId = it.spaceId
+ } ?: resetFields()
+ }
+ }
}
}
}
@@ -245,4 +258,16 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {
prefVideoUploadsBehaviour?.value = UploadBehavior.COPY.name
prefVideoUploadsLastSync?.summary = null
}
+
+ private fun disableFields() {
+ prefEnableVideoUploads?.isChecked = false
+ prefEnableVideoUploads?.isEnabled = false
+ prefVideoUploadsAccount?.isEnabled = false
+ prefVideoUploadsPath?.isEnabled = false
+ prefVideoUploadsSourcePath?.isEnabled = false
+ prefVideoUploadsOnWifi?.isEnabled = false
+ prefVideoUploadsOnCharging?.isEnabled = false
+ prefVideoUploadsBehaviour?.isEnabled = false
+ prefVideoUploadsLastSync?.isEnabled = false
+ }
}
diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsViewModel.kt
index e205bd0477c..8a76cb1d2d9 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsViewModel.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/settings/automaticuploads/SettingsVideoUploadsViewModel.kt
@@ -3,8 +3,9 @@
*
* @author Juan Carlos Garrote Gascón
* @author Aitor Ballesteros Pavón
+ * @author Jorge Aguado Recio
*
- * Copyright (C) 2023 ownCloud GmbH.
+ * Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
@@ -124,8 +125,6 @@ class SettingsVideoUploadsViewModel(
fun getVideoUploadsAccount() = _videoUploads.value?.accountName
- fun getLoggedAccountNames(): Array = accountProvider.getLoggedAccounts().map { it.name }.toTypedArray()
-
fun getVideoUploadsPath() = _videoUploads.value?.uploadPath ?: PREF__CAMERA_UPLOADS_DEFAULT_PATH
fun getVideoUploadsSourcePath(): String? = _videoUploads.value?.sourcePath