Skip to content

Commit

Permalink
fix: set an account by default when automatic uploads are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
joragua committed Dec 2, 2024
1 parent 9832da9 commit bf814d7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
}
)
}
}

Expand Down

0 comments on commit bf814d7

Please sign in to comment.