Skip to content

Commit

Permalink
Use default source path when opening the native picker to select the …
Browse files Browse the repository at this point in the history
…camera uploads source folder
  • Loading branch information
abelgardep committed Jul 8, 2021
1 parent 0bd31c5 commit 090df6e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class SettingsPictureUploadsFragment : PreferenceFragmentCompat() {

prefPictureUploadsSourcePath?.setOnPreferenceClickListener {
var sourcePath = picturesViewModel.getPictureUploadsSourcePath()
.takeUnless { it.isNullOrBlank() } ?: picturesViewModel.getDefaultSourcePath()
if (!sourcePath.endsWith(File.separator)) {
sourcePath += File.separator
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class SettingsVideoUploadsFragment : PreferenceFragmentCompat() {

prefVideoUploadsSourcePath?.setOnPreferenceClickListener {
var sourcePath = videosViewModel.getVideoUploadsSourcePath()
.takeUnless { it.isNullOrBlank() } ?: videosViewModel.getDefaultCameraSourcePath()
if (!sourcePath.endsWith(File.separator)) {
sourcePath += File.separator
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class SettingsPictureUploadsViewModel(

fun getPictureUploadsPath() = _pictureUploads.value?.uploadPath ?: PREF__CAMERA_UPLOADS_DEFAULT_PATH

fun getPictureUploadsSourcePath(): String = _pictureUploads.value?.sourcePath ?: getDefaultCameraSourcePath()
fun getPictureUploadsSourcePath(): String? = _pictureUploads.value?.sourcePath

fun getDefaultSourcePath(): String = getDefaultCameraSourcePath()

fun handleSelectPictureUploadsPath(data: Intent?) {
val folderToUpload = data?.getParcelableExtra<OCFile>(UploadPathActivity.EXTRA_FOLDER)
Expand Down Expand Up @@ -134,7 +136,7 @@ class SettingsPictureUploadsViewModel(
// If the source path has changed, update camera uploads last sync
var previousSourcePath = _pictureUploads.value?.sourcePath ?: getDefaultCameraSourcePath()

previousSourcePath = previousSourcePath?.trimEnd(File.separatorChar)
previousSourcePath = previousSourcePath.trimEnd(File.separatorChar)

viewModelScope.launch(coroutinesDispatcherProvider.io) {
savePictureUploadsConfigurationUseCase.execute(
Expand Down Expand Up @@ -163,7 +165,7 @@ class SettingsPictureUploadsViewModel(
FolderBackUpConfiguration(
accountName = accountName ?: accountProvider.getCurrentOwnCloudAccount()!!.name,
behavior = behavior ?: FolderBackUpConfiguration.Behavior.COPY,
sourcePath = sourcePath ?: getDefaultCameraSourcePath(),
sourcePath = sourcePath.orEmpty(),
uploadPath = uploadPath ?: PREF__CAMERA_UPLOADS_DEFAULT_PATH,
wifiOnly = wifiOnly ?: false,
lastSyncTimestamp = timestamp ?: System.currentTimeMillis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.owncloud.android.providers.AccountProvider
import com.owncloud.android.providers.CoroutinesDispatcherProvider
import com.owncloud.android.providers.WorkManagerProvider
import com.owncloud.android.ui.activity.UploadPathActivity
import com.owncloud.android.utils.FileStorageUtils.getDefaultCameraSourcePath
import com.owncloud.android.utils.FileStorageUtils
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import java.io.File
Expand Down Expand Up @@ -99,7 +99,9 @@ class SettingsVideoUploadsViewModel(

fun getVideoUploadsPath() = _videoUploads.value?.uploadPath ?: PREF__CAMERA_UPLOADS_DEFAULT_PATH

fun getVideoUploadsSourcePath(): String = _videoUploads.value?.sourcePath ?: getDefaultCameraSourcePath()
fun getVideoUploadsSourcePath(): String? = _videoUploads.value?.sourcePath

fun getDefaultCameraSourcePath(): String = FileStorageUtils.getDefaultCameraSourcePath()

fun handleSelectVideoUploadsPath(data: Intent?) {
val folderToUpload = data?.getParcelableExtra<OCFile>(UploadPathActivity.EXTRA_FOLDER)
Expand Down Expand Up @@ -134,7 +136,7 @@ class SettingsVideoUploadsViewModel(
// If the source path has changed, update camera uploads last sync
var previousSourcePath = _videoUploads.value?.sourcePath ?: getDefaultCameraSourcePath()

previousSourcePath = previousSourcePath?.trimEnd(File.separatorChar)
previousSourcePath = previousSourcePath.trimEnd(File.separatorChar)

viewModelScope.launch(coroutinesDispatcherProvider.io) {
saveVideoUploadsConfigurationUseCase.execute(
Expand Down Expand Up @@ -163,7 +165,7 @@ class SettingsVideoUploadsViewModel(
FolderBackUpConfiguration(
accountName = accountName ?: accountProvider.getCurrentOwnCloudAccount()!!.name,
behavior = behavior ?: FolderBackUpConfiguration.Behavior.COPY,
sourcePath = sourcePath ?: getDefaultCameraSourcePath(),
sourcePath = sourcePath.orEmpty(),
uploadPath = uploadPath ?: PREF__CAMERA_UPLOADS_DEFAULT_PATH,
wifiOnly = wifiOnly ?: false,
lastSyncTimestamp = timestamp ?: System.currentTimeMillis(),
Expand Down

0 comments on commit 090df6e

Please sign in to comment.