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 3c2d608a0fe..416c22f3ea4 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 @@ -74,6 +74,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() { private var prefPictureUploadsAccount: ListPreference? = null private var prefPictureUploadsLastSync: Preference? = null private var spaceId: String? = null + private lateinit var selectedAccount: String private val selectPictureUploadsPathLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> @@ -131,6 +132,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() { entries = availableAccounts.map { it.accountName }.toTypedArray() entryValues = availableAccounts.map { it.accountName }.toTypedArray() } + selectedAccount = availableAccounts.first().accountName if (availableAccounts.isEmpty()) { enablePictureUploads(false, true) @@ -139,7 +141,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() { picturesViewModel.pictureUploads.collect { pictureUploadsConfiguration -> enablePictureUploads(pictureUploadsConfiguration != null, false) pictureUploadsConfiguration?.let { - prefPictureUploadsAccount?.value = it.accountName + prefPictureUploadsAccount?.value = selectedAccount prefPictureUploadsPath?.summary = picturesViewModel.getUploadPathString() prefPictureUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path) prefPictureUploadsOnWifi?.isChecked = it.wifiOnly @@ -160,7 +162,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() { val value = newValue as Boolean if (value) { - picturesViewModel.enablePictureUploads() + picturesViewModel.enablePictureUploads(selectedAccount) showAlertDialog( title = getString(R.string.common_important), message = getString(R.string.proper_pics_folder_warning_camera_upload) 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 8b1443d5439..beedf878cc3 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 @@ -82,20 +82,18 @@ class SettingsPictureUploadsViewModel( } } - fun enablePictureUploads() { - // Use current account as default. It should never be null. If no accounts are attached, picture uploads are hidden - accountProvider.getCurrentOwnCloudAccount()?.name?.let { name -> - viewModelScope.launch(coroutinesDispatcherProvider.io) { - getPersonalSpaceForAccount(name) - savePictureUploadsConfigurationUseCase( - SavePictureUploadsConfigurationUseCase.Params( - composePictureUploadsConfiguration( - accountName = name, - spaceId = pictureUploadsSpace?.id, - ) + fun enablePictureUploads(accountName: String) { + // Use selected account as default. + viewModelScope.launch(coroutinesDispatcherProvider.io) { + getPersonalSpaceForAccount(accountName) + savePictureUploadsConfigurationUseCase( + SavePictureUploadsConfigurationUseCase.Params( + composePictureUploadsConfiguration( + accountName = accountName, + spaceId = pictureUploadsSpace?.id, ) ) - } + ) } } 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 bc7b5e066b0..639a5d57dc6 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 @@ -74,6 +74,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() { private var prefVideoUploadsAccount: ListPreference? = null private var prefVideoUploadsLastSync: Preference? = null private var spaceId: String? = null + private lateinit var selectedAccount: String private val selectVideoUploadsPathLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> @@ -128,6 +129,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() { entries = availableAccounts.map { it.accountName }.toTypedArray() entryValues = availableAccounts.map { it.accountName }.toTypedArray() } + selectedAccount = availableAccounts.first().accountName if (availableAccounts.isEmpty()) { enableVideoUploads(false, true) @@ -136,7 +138,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() { videosViewModel.videoUploads.collect { videoUploadsConfiguration -> enableVideoUploads(videoUploadsConfiguration != null, false) videoUploadsConfiguration?.let { - prefVideoUploadsAccount?.value = it.accountName + prefVideoUploadsAccount?.value = selectedAccount prefVideoUploadsPath?.summary = videosViewModel.getUploadPathString() prefVideoUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path) prefVideoUploadsOnWifi?.isChecked = it.wifiOnly @@ -157,7 +159,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() { val value = newValue as Boolean if (value) { - videosViewModel.enableVideoUploads() + videosViewModel.enableVideoUploads(selectedAccount) showAlertDialog( title = getString(R.string.common_important), message = getString(R.string.proper_videos_folder_warning_camera_upload) 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 8a76cb1d2d9..89d88041c48 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 @@ -82,20 +82,18 @@ class SettingsVideoUploadsViewModel( } } - fun enableVideoUploads() { - // Use current account as default. It should never be null. If no accounts are attached, video uploads are hidden - accountProvider.getCurrentOwnCloudAccount()?.name?.let { name -> - viewModelScope.launch(coroutinesDispatcherProvider.io) { - getPersonalSpaceForAccount(name) - saveVideoUploadsConfigurationUseCase( - SaveVideoUploadsConfigurationUseCase.Params( - composeVideoUploadsConfiguration( - accountName = name, - spaceId = videoUploadsSpace?.id, - ) + fun enableVideoUploads(accountName: String) { + // Use selected account as default. + viewModelScope.launch(coroutinesDispatcherProvider.io) { + getPersonalSpaceForAccount(accountName) + saveVideoUploadsConfigurationUseCase( + SaveVideoUploadsConfigurationUseCase.Params( + composeVideoUploadsConfiguration( + accountName = accountName, + spaceId = videoUploadsSpace?.id, ) ) - } + ) } }