Skip to content

Commit ec30ba3

Browse files
authored
Merge pull request #4214 from owncloud/feature/auto_upload_to_other_space_not_personal
[FEATURE REQUEST] OCIS: Auto Upload to other space that is not Personal
2 parents 07fe466 + 5cb5293 commit ec30ba3

File tree

24 files changed

+380
-116
lines changed

24 files changed

+380
-116
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ownCloud admins and users.
3434
* Enhancement - "Apply to all" when many name conflicts arise: [#4078](https://github.com/owncloud/android/issues/4078)
3535
* Enhancement - "Share to" in oCIS accounts allows upload to any space: [#4088](https://github.com/owncloud/android/issues/4088)
3636
* Enhancement - Auto-refresh when a file is uploaded: [#4103](https://github.com/owncloud/android/issues/4103)
37+
* Enhancement - Auto upload in oCIS accounts allows upload to any space: [#4117](https://github.com/owncloud/android/issues/4117)
3738
* Enhancement - Download log files: [#4155](https://github.com/owncloud/android/issues/4155)
3839
* Enhancement - Log file sharing allowed within ownCloud Android app: [#4156](https://github.com/owncloud/android/issues/4156)
3940
* Enhancement - New field "last usage" in database: [#4173](https://github.com/owncloud/android/issues/4173)
@@ -103,6 +104,14 @@ ownCloud admins and users.
103104
https://github.com/owncloud/android/issues/4103
104105
https://github.com/owncloud/android/pull/4199
105106

107+
* Enhancement - Auto upload in oCIS accounts allows upload to any space: [#4117](https://github.com/owncloud/android/issues/4117)
108+
109+
Auto uploads of images and videos can now be uploaded to any space and not only
110+
the personal one in oCIS accounts.
111+
112+
https://github.com/owncloud/android/issues/4117
113+
https://github.com/owncloud/android/pull/4214
114+
106115
* Enhancement - Download log files: [#4155](https://github.com/owncloud/android/issues/4155)
107116

108117
A new icon to download a log file to the Downloads folder of the device has been

changelog/unreleased/4214

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: Auto upload in oCIS accounts allows upload to any space
2+
3+
Auto uploads of images and videos can now be uploaded to any space and not only the personal one in oCIS accounts.
4+
5+
https://github.com/owncloud/android/issues/4117
6+
https://github.com/owncloud/android/pull/4214

owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import com.owncloud.android.domain.spaces.usecases.GetProjectSpacesWithSpecialsF
9393
import com.owncloud.android.domain.spaces.usecases.GetSpaceWithSpecialsByIdForAccountUseCase
9494
import com.owncloud.android.domain.spaces.usecases.GetSpacesFromEveryAccountUseCaseAsStream
9595
import com.owncloud.android.domain.spaces.usecases.RefreshSpacesFromServerAsyncUseCase
96+
import com.owncloud.android.domain.spaces.usecases.GetSpaceByIdForAccountUseCase
9697
import com.owncloud.android.domain.transfers.usecases.ClearSuccessfulTransfersUseCase
9798
import com.owncloud.android.domain.transfers.usecases.GetAllTransfersAsStreamUseCase
9899
import com.owncloud.android.domain.transfers.usecases.GetAllTransfersUseCase
@@ -214,6 +215,7 @@ val useCaseModule = module {
214215
factoryOf(::GetSpacesFromEveryAccountUseCaseAsStream)
215216
factoryOf(::GetWebDavUrlForSpaceUseCase)
216217
factoryOf(::RefreshSpacesFromServerAsyncUseCase)
218+
factoryOf(::GetSpaceByIdForAccountUseCase)
217219

218220
// Transfers
219221
factoryOf(::CancelDownloadForFileUseCase)

owncloudApp/src/main/java/com/owncloud/android/presentation/settings/autouploads/SettingsPictureUploadsFragment.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Juan Carlos Garrote Gascón
5+
* @author Aitor Ballesteros Pavón
56
*
6-
* Copyright (C) 2021 ownCloud GmbH.
7+
* Copyright (C) 2023 ownCloud GmbH.
78
* <p>
89
* This program is free software: you can redistribute it and/or modify
910
* it under the terms of the GNU General Public License version 2,
@@ -49,7 +50,6 @@ import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_PICTURE_UPLOADS_WI
4950
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
5051
import com.owncloud.android.extensions.showAlertDialog
5152
import com.owncloud.android.ui.activity.FolderPickerActivity
52-
import com.owncloud.android.ui.activity.UploadPathActivity
5353
import com.owncloud.android.utils.DisplayUtils
5454
import kotlinx.coroutines.launch
5555
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -68,6 +68,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
6868
private var prefPictureUploadsBehaviour: ListPreference? = null
6969
private var prefPictureUploadsAccount: ListPreference? = null
7070
private var prefPictureUploadsLastSync: Preference? = null
71+
private var spaceId: String? = null
7172

7273
private val selectPictureUploadsPathLauncher =
7374
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
@@ -96,7 +97,10 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
9697
prefPictureUploadsSourcePath = findPreference(PREF__CAMERA_PICTURE_UPLOADS_SOURCE)
9798
prefPictureUploadsLastSync = findPreference(PREF__CAMERA_PICTURE_UPLOADS_LAST_SYNC)
9899
prefPictureUploadsBehaviour = findPreference<ListPreference>(PREF__CAMERA_PICTURE_UPLOADS_BEHAVIOUR)?.apply {
99-
entries = listOf(getString(R.string.pref_behaviour_entries_keep_file), getString(R.string.pref_behaviour_entries_remove_original_file)).toTypedArray()
100+
entries = listOf(
101+
getString(R.string.pref_behaviour_entries_keep_file),
102+
getString(R.string.pref_behaviour_entries_remove_original_file)
103+
).toTypedArray()
100104
entryValues = listOf(UploadBehavior.COPY.name, UploadBehavior.MOVE.name).toTypedArray()
101105
}
102106
prefPictureUploadsAccount = findPreference<ListPreference>(PREF__CAMERA_PICTURE_UPLOADS_ACCOUNT_NAME)?.apply {
@@ -123,12 +127,13 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
123127
enablePictureUploads(pictureUploadsConfiguration != null)
124128
pictureUploadsConfiguration?.let {
125129
prefPictureUploadsAccount?.value = it.accountName
126-
prefPictureUploadsPath?.summary = DisplayUtils.getPathWithoutLastSlash(it.uploadPath)
130+
prefPictureUploadsPath?.summary = picturesViewModel.getUploadPathString()
127131
prefPictureUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path)
128132
prefPictureUploadsOnWifi?.isChecked = it.wifiOnly
129133
prefPictureUploadsOnCharging?.isChecked = it.chargingOnly
130134
prefPictureUploadsBehaviour?.value = it.behavior.name
131135
prefPictureUploadsLastSync?.summary = DisplayUtils.unixTimeToHumanReadable(it.lastSyncTimestamp)
136+
spaceId = it.spaceId
132137
} ?: resetFields()
133138
}
134139
}
@@ -165,10 +170,10 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {
165170
if (!uploadPath.endsWith(File.separator)) {
166171
uploadPath += File.separator
167172
}
168-
val intent = Intent(activity, UploadPathActivity::class.java).apply {
169-
putExtra(UploadPathActivity.KEY_CAMERA_UPLOAD_PATH, uploadPath)
173+
val intent = Intent(activity, FolderPickerActivity::class.java).apply {
170174
putExtra(FolderPickerActivity.EXTRA_PICKER_MODE, FolderPickerActivity.PickerMode.CAMERA_FOLDER)
171-
putExtra(UploadPathActivity.KEY_CAMERA_UPLOAD_ACCOUNT, picturesViewModel.getPictureUploadsAccount())
175+
putExtra(FolderPickerActivity.KEY_SPACE_ID, spaceId)
176+
putExtra(FolderPickerActivity.KEY_ACCOUNT_NAME, picturesViewModel.getPictureUploadsAccount())
172177
}
173178
selectPictureUploadsPathLauncher.launch(intent)
174179
true

owncloudApp/src/main/java/com/owncloud/android/presentation/settings/autouploads/SettingsPictureUploadsViewModel.kt

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Juan Carlos Garrote Gascón
5+
* @author Aitor Ballesteros Pavón
56
*
6-
* Copyright (C) 2021 ownCloud GmbH.
7+
* Copyright (C) 2023 ownCloud GmbH.
78
* <p>
89
* This program is free software: you can redistribute it and/or modify
910
* it under the terms of the GNU General Public License version 2,
@@ -24,6 +25,7 @@ import android.content.Intent
2425
import android.net.Uri
2526
import androidx.lifecycle.ViewModel
2627
import androidx.lifecycle.viewModelScope
28+
import com.owncloud.android.R
2729
import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_UPLOADS_DEFAULT_PATH
2830
import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration
2931
import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration.Companion.pictureUploadsName
@@ -32,7 +34,11 @@ import com.owncloud.android.domain.camerauploads.usecases.GetPictureUploadsConfi
3234
import com.owncloud.android.domain.camerauploads.usecases.ResetPictureUploadsUseCase
3335
import com.owncloud.android.domain.camerauploads.usecases.SavePictureUploadsConfigurationUseCase
3436
import com.owncloud.android.domain.files.model.OCFile
37+
import com.owncloud.android.domain.spaces.model.OCSpace
38+
import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase
39+
import com.owncloud.android.domain.spaces.usecases.GetSpaceByIdForAccountUseCase
3540
import com.owncloud.android.providers.AccountProvider
41+
import com.owncloud.android.providers.ContextProvider
3642
import com.owncloud.android.providers.CoroutinesDispatcherProvider
3743
import com.owncloud.android.providers.WorkManagerProvider
3844
import com.owncloud.android.ui.activity.FolderPickerActivity
@@ -48,20 +54,28 @@ class SettingsPictureUploadsViewModel(
4854
private val savePictureUploadsConfigurationUseCase: SavePictureUploadsConfigurationUseCase,
4955
private val getPictureUploadsConfigurationStreamUseCase: GetPictureUploadsConfigurationStreamUseCase,
5056
private val resetPictureUploadsUseCase: ResetPictureUploadsUseCase,
57+
private val getPersonalSpaceForAccountUseCase: GetPersonalSpaceForAccountUseCase,
58+
private val getSpaceByIdForAccountUseCase: GetSpaceByIdForAccountUseCase,
5159
private val workManagerProvider: WorkManagerProvider,
5260
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
61+
private val contextProvider: ContextProvider,
5362
) : ViewModel() {
5463

5564
private val _pictureUploads: MutableStateFlow<FolderBackUpConfiguration?> = MutableStateFlow(null)
5665
val pictureUploads: StateFlow<FolderBackUpConfiguration?> = _pictureUploads
5766

67+
private var pictureUploadsSpace: OCSpace? = null
68+
5869
init {
5970
initPictureUploads()
6071
}
6172

6273
private fun initPictureUploads() {
6374
viewModelScope.launch(coroutinesDispatcherProvider.io) {
6475
getPictureUploadsConfigurationStreamUseCase(Unit).collect { pictureUploadsConfiguration ->
76+
pictureUploadsConfiguration?.accountName?.let {
77+
getSpaceById(spaceId = pictureUploadsConfiguration.spaceId, accountName = it)
78+
}
6579
_pictureUploads.update { pictureUploadsConfiguration }
6680
}
6781
}
@@ -71,8 +85,14 @@ class SettingsPictureUploadsViewModel(
7185
// Use current account as default. It should never be null. If no accounts are attached, picture uploads are hidden
7286
accountProvider.getCurrentOwnCloudAccount()?.name?.let { name ->
7387
viewModelScope.launch(coroutinesDispatcherProvider.io) {
88+
getPersonalSpaceForAccount(name)
7489
savePictureUploadsConfigurationUseCase(
75-
SavePictureUploadsConfigurationUseCase.Params(composePictureUploadsConfiguration(accountName = name))
90+
SavePictureUploadsConfigurationUseCase.Params(
91+
composePictureUploadsConfiguration(
92+
accountName = name,
93+
spaceId = pictureUploadsSpace?.id,
94+
)
95+
)
7696
)
7797
}
7898
}
@@ -114,17 +134,30 @@ class SettingsPictureUploadsViewModel(
114134
val folderToUpload = data?.getParcelableExtra<OCFile>(FolderPickerActivity.EXTRA_FOLDER)
115135
folderToUpload?.remotePath?.let {
116136
viewModelScope.launch(coroutinesDispatcherProvider.io) {
137+
getSpaceById(spaceId = folderToUpload.spaceId, accountName = folderToUpload.owner)
117138
savePictureUploadsConfigurationUseCase(
118-
SavePictureUploadsConfigurationUseCase.Params(composePictureUploadsConfiguration(uploadPath = it))
139+
SavePictureUploadsConfigurationUseCase.Params(
140+
composePictureUploadsConfiguration(
141+
uploadPath = it,
142+
spaceId = pictureUploadsSpace?.id,
143+
)
144+
)
119145
)
120146
}
121147
}
122148
}
123149

124150
fun handleSelectAccount(accountName: String) {
125151
viewModelScope.launch(coroutinesDispatcherProvider.io) {
152+
getPersonalSpaceForAccount(accountName)
126153
savePictureUploadsConfigurationUseCase(
127-
SavePictureUploadsConfigurationUseCase.Params(composePictureUploadsConfiguration(accountName = accountName))
154+
SavePictureUploadsConfigurationUseCase.Params(
155+
composePictureUploadsConfiguration(
156+
accountName = accountName,
157+
uploadPath = null,
158+
spaceId = pictureUploadsSpace?.id,
159+
)
160+
)
128161
)
129162
}
130163
}
@@ -166,7 +199,8 @@ class SettingsPictureUploadsViewModel(
166199
chargingOnly: Boolean? = _pictureUploads.value?.chargingOnly,
167200
sourcePath: String? = _pictureUploads.value?.sourcePath,
168201
behavior: UploadBehavior? = _pictureUploads.value?.behavior,
169-
timestamp: Long? = _pictureUploads.value?.lastSyncTimestamp
202+
timestamp: Long? = _pictureUploads.value?.lastSyncTimestamp,
203+
spaceId: String? = _pictureUploads.value?.spaceId,
170204
): FolderBackUpConfiguration = FolderBackUpConfiguration(
171205
accountName = accountName ?: accountProvider.getCurrentOwnCloudAccount()!!.name,
172206
behavior = behavior ?: UploadBehavior.COPY,
@@ -175,8 +209,57 @@ class SettingsPictureUploadsViewModel(
175209
wifiOnly = wifiOnly ?: false,
176210
chargingOnly = chargingOnly ?: false,
177211
lastSyncTimestamp = timestamp ?: System.currentTimeMillis(),
178-
name = _pictureUploads.value?.name ?: pictureUploadsName
212+
name = _pictureUploads.value?.name ?: pictureUploadsName,
213+
spaceId = spaceId,
179214
).also {
180215
Timber.d("Picture uploads configuration updated. New configuration: $it")
181216
}
217+
218+
private fun handleSpaceName(spaceName: String?): String? {
219+
return if (pictureUploadsSpace?.isPersonal == true) {
220+
contextProvider.getString(R.string.bottom_nav_personal)
221+
} else {
222+
spaceName
223+
}
224+
}
225+
226+
fun getUploadPathString(): String {
227+
228+
val spaceName = handleSpaceName(pictureUploadsSpace?.name)
229+
val uploadPath = pictureUploads.value?.uploadPath
230+
val spaceId = pictureUploads.value?.spaceId
231+
232+
return if (uploadPath != null) {
233+
if (spaceId != null) {
234+
"$spaceName: $uploadPath"
235+
} else {
236+
uploadPath
237+
}
238+
} else {
239+
if (spaceId != null) {
240+
"$spaceName: $PREF__CAMERA_UPLOADS_DEFAULT_PATH"
241+
} else {
242+
PREF__CAMERA_UPLOADS_DEFAULT_PATH
243+
}
244+
}
245+
}
246+
247+
private fun getPersonalSpaceForAccount(accountName: String) {
248+
val result = getPersonalSpaceForAccountUseCase(
249+
GetPersonalSpaceForAccountUseCase.Params(
250+
accountName = accountName
251+
)
252+
)
253+
pictureUploadsSpace = result
254+
}
255+
256+
private fun getSpaceById(spaceId: String?, accountName: String) {
257+
val result = getSpaceByIdForAccountUseCase(
258+
GetSpaceByIdForAccountUseCase.Params(
259+
accountName = accountName,
260+
spaceId = spaceId
261+
)
262+
)
263+
pictureUploadsSpace = result
264+
}
182265
}

owncloudApp/src/main/java/com/owncloud/android/presentation/settings/autouploads/SettingsVideoUploadsFragment.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Juan Carlos Garrote Gascón
5+
* @author Aitor Ballesteros Pavón
56
*
6-
* Copyright (C) 2021 ownCloud GmbH.
7+
* Copyright (C) 2023 ownCloud GmbH.
78
* <p>
89
* This program is free software: you can redistribute it and/or modify
910
* it under the terms of the GNU General Public License version 2,
@@ -49,7 +50,6 @@ import com.owncloud.android.db.PreferenceManager.PREF__CAMERA_VIDEO_UPLOADS_WIFI
4950
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
5051
import com.owncloud.android.extensions.showAlertDialog
5152
import com.owncloud.android.ui.activity.FolderPickerActivity
52-
import com.owncloud.android.ui.activity.UploadPathActivity
5353
import com.owncloud.android.utils.DisplayUtils
5454
import kotlinx.coroutines.launch
5555
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -68,6 +68,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {
6868
private var prefVideoUploadsBehaviour: ListPreference? = null
6969
private var prefVideoUploadsAccount: ListPreference? = null
7070
private var prefVideoUploadsLastSync: Preference? = null
71+
private var spaceId: String? = null
7172

7273
private val selectVideoUploadsPathLauncher =
7374
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
@@ -123,12 +124,13 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {
123124
enableVideoUploads(videoUploadsConfiguration != null)
124125
videoUploadsConfiguration?.let {
125126
prefVideoUploadsAccount?.value = it.accountName
126-
prefVideoUploadsPath?.summary = DisplayUtils.getPathWithoutLastSlash(it.uploadPath)
127+
prefVideoUploadsPath?.summary = videosViewModel.getUploadPathString()
127128
prefVideoUploadsSourcePath?.summary = DisplayUtils.getPathWithoutLastSlash(it.sourcePath.toUri().path)
128129
prefVideoUploadsOnWifi?.isChecked = it.wifiOnly
129130
prefVideoUploadsOnCharging?.isChecked = it.chargingOnly
130131
prefVideoUploadsBehaviour?.value = it.behavior.name
131132
prefVideoUploadsLastSync?.summary = DisplayUtils.unixTimeToHumanReadable(it.lastSyncTimestamp)
133+
spaceId = it.spaceId
132134
} ?: resetFields()
133135
}
134136
}
@@ -165,10 +167,10 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {
165167
if (!uploadPath.endsWith(File.separator)) {
166168
uploadPath += File.separator
167169
}
168-
val intent = Intent(activity, UploadPathActivity::class.java).apply {
169-
putExtra(UploadPathActivity.KEY_CAMERA_UPLOAD_PATH, uploadPath)
170+
val intent = Intent(activity, FolderPickerActivity::class.java).apply {
170171
putExtra(FolderPickerActivity.EXTRA_PICKER_MODE, FolderPickerActivity.PickerMode.CAMERA_FOLDER)
171-
putExtra(UploadPathActivity.KEY_CAMERA_UPLOAD_ACCOUNT, videosViewModel.getVideoUploadsAccount())
172+
putExtra(FolderPickerActivity.KEY_SPACE_ID, spaceId)
173+
putExtra(FolderPickerActivity.KEY_ACCOUNT_NAME, videosViewModel.getVideoUploadsAccount())
172174
}
173175
selectVideoUploadsPathLauncher.launch(intent)
174176
true

0 commit comments

Comments
 (0)