From 98ebf7c9a85258d2b4a2429c422b483f0440be6f Mon Sep 17 00:00:00 2001 From: joragua Date: Mon, 2 Dec 2024 11:30:52 +0100 Subject: [PATCH] fix: set an account by default when automatic uploads are enabled --- .../SettingsPictureUploadsFragment.kt | 6 +++-- .../SettingsPictureUploadsViewModel.kt | 22 +++++++++---------- .../SettingsVideoUploadsFragment.kt | 6 +++-- .../SettingsVideoUploadsViewModel.kt | 22 +++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) 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..3bc89b18374 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 -> @@ -136,10 +137,11 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() { enablePictureUploads(false, true) showMessageInSnackbar(getString(R.string.prefs_automatic_uploads_not_available_users_light)) } else { + selectedAccount = availableAccounts.first().accountName 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..ba09630b7f6 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 -> @@ -133,10 +134,11 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() { enableVideoUploads(false, true) showMessageInSnackbar(getString(R.string.prefs_automatic_uploads_not_available_users_light)) } else { + selectedAccount = availableAccounts.first().accountName 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, ) ) - } + ) } }