diff --git a/changelog/unreleased/4160 b/changelog/unreleased/4160 index b3eee4c9b7c..5524ff0159a 100644 --- a/changelog/unreleased/4160 +++ b/changelog/unreleased/4160 @@ -1,6 +1,6 @@ -Enhancement: OCIS: "Share to" allows only upload to personal "space" +Enhancement: "Share to" in oCIS accounts allows upload to any space -With this improvement, it is possible to choose between different spaces to share something from outside the application to inside. +With this improvement, shared stuff from other apps can be uploaded to any space and not only the personal one in oCIS accounts. https://github.com/owncloud/android/issues/4088 -https://github.com/owncloud/android/pull/4160 \ No newline at end of file +https://github.com/owncloud/android/pull/4160 diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt index d5342417a40..a0ab9dedafc 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt @@ -142,7 +142,7 @@ val viewModelModule = module { ) } viewModel { (ocFile: OCFile) -> ConflictsResolveViewModel(get(), get(), get(), get(), get(), ocFile) } - viewModel { ReceiveExternalFilesViewModel(get(), get()) } + viewModel { ReceiveExternalFilesViewModel(get(), get(), get()) } viewModel { AccountsManagementViewModel(get()) } viewModel { (accountName: String, showPersonalSpace: Boolean) -> SpacesListViewModel(get(), get(), get(), get(), get(), accountName, showPersonalSpace) diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/ReceiveExternalFilesViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/ReceiveExternalFilesViewModel.kt index 24c62e70368..887c0a8d5c4 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/ReceiveExternalFilesViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/ReceiveExternalFilesViewModel.kt @@ -19,22 +19,32 @@ package com.owncloud.android.ui import androidx.lifecycle.LiveData import androidx.lifecycle.MediatorLiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.owncloud.android.domain.files.model.OCFile +import com.owncloud.android.domain.spaces.model.OCSpace +import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase import com.owncloud.android.domain.utils.Event import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult import com.owncloud.android.presentation.common.UIResult import com.owncloud.android.providers.CoroutinesDispatcherProvider import com.owncloud.android.usecases.synchronization.SynchronizeFolderUseCase +import kotlinx.coroutines.launch class ReceiveExternalFilesViewModel( private val synchronizeFolderUseCase: SynchronizeFolderUseCase, - private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider + private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, + private val getPersonalSpaceForAccountUseCase : GetPersonalSpaceForAccountUseCase, ) : ViewModel() { private val _syncFolderLiveData = MediatorLiveData>>() val syncFolderLiveData: LiveData>> = _syncFolderLiveData + private val _personalSpaceLiveData = MutableLiveData() + val personalSpaceLiveData: LiveData = _personalSpaceLiveData + + fun refreshFolderUseCase( folderToSync: OCFile, ) = runUseCaseWithResult( @@ -49,4 +59,17 @@ class ReceiveExternalFilesViewModel( syncMode = SynchronizeFolderUseCase.SyncFolderMode.REFRESH_FOLDER ) ) + + fun getPersonalSpaceforAcount(accountName: String) { + viewModelScope.launch(coroutinesDispatcherProvider.io) { + val result = getPersonalSpaceForAccountUseCase.execute( + GetPersonalSpaceForAccountUseCase.Params( + accountName = accountName + ) + ) + _personalSpaceLiveData.postValue(result) + } + } + + } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt index 114d4dd29e1..bbffbf166b8 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt @@ -376,7 +376,7 @@ class FileDisplayActivity : FileActivity(), } private fun initAndShowListOfSpaces() { - val listOfSpaces = SpacesListFragment(false, account.name) + val listOfSpaces = SpacesListFragment(accountName = account.name) this.fileListOption = FileListOption.SPACES_LIST val transaction = supportFragmentManager.beginTransaction() transaction.replace(R.id.left_fragment_container, listOfSpaces, TAG_LIST_OF_SPACES) diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt index 15aee0068b6..1f25e9ecc20 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt @@ -248,7 +248,7 @@ open class FolderPickerActivity : FileActivity(), } private fun initAndShowListOfSpaces() { - val listOfSpaces = SpacesListFragment(showPersonalSpace = true, account.name) + val listOfSpaces = SpacesListFragment(showPersonalSpace = true, accountName = account.name) val transaction = supportFragmentManager.beginTransaction() transaction.replace(R.id.fragment_container, listOfSpaces) transaction.commit() diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index cc9a3d205fa..6d2e4248bd8 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -67,10 +67,10 @@ import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.data.providers.implementation.OCSharedPreferencesProvider; -import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.db.PreferenceManager; import com.owncloud.android.domain.exceptions.UnauthorizedException; import com.owncloud.android.domain.files.model.OCFile; +import com.owncloud.android.domain.spaces.model.OCSpace; import com.owncloud.android.extensions.ActivityExtKt; import com.owncloud.android.extensions.ThrowableExtKt; import com.owncloud.android.lib.common.OwnCloudAccount; @@ -150,7 +150,9 @@ public class ReceiveExternalFilesActivity extends FileActivity private Button uploaderButton; private Button cancelButton; private TextView noPermissionsMessage; - private String currentSpace; + private String currentSpaceId; + + private Boolean haveMultiAccount = false; // this is inited lazily, when an account is selected. If no account is selected but an instance of this would // be crated it would result in an null pointer exception. @@ -175,8 +177,7 @@ public class ReceiveExternalFilesActivity extends FileActivity private boolean showHiddenFiles; private OCSharedPreferencesProvider sharedPreferencesProvider; - private FileDataStorageManager storageManager; - private OCFile root; + private OCSpace spacePersonal; Pattern pattern = Pattern.compile("[/\\\\]"); @@ -217,28 +218,68 @@ protected void onCreate(Bundle savedInstanceState) { } mSortOptionsView.setVisibility(View.GONE); - storageManager = new FileDataStorageManager(getAccount()); - root = storageManager.getRootPersonalFolder(); - if (root.getSpaceId() != null) { - initAndShowListOfSpaces(); - updateToolbar(getString(R.string.app_name)); - getSupportFragmentManager().setFragmentResultListener(SpacesListFragment.REQUEST_KEY_CLICK_SPACE, this, (requestKey, bundle) -> { - OCFile rootSpaceFolder = bundle.getParcelable(SpacesListFragment.BUNDLE_KEY_CLICK_SPACE); - mFile = rootSpaceFolder; - currentSpace = mFile.getSpaceId(); - showFilesview(); - updateDirectoryList(); - showRetainerFragment(); - }); - } else { - showFilesview(); - showRetainerFragment(); - } + mReceiveExternalFilesViewModel = get(ReceiveExternalFilesViewModel.class); + mReceiveExternalFilesViewModel.getPersonalSpaceforAcount(getAccount().name); + initPickerListener(); } - private void showFilesview() { + private void suscribeViewModel() { + mReceiveExternalFilesViewModel.getPersonalSpaceLiveData().observe(this, ocSpace -> { + spacePersonal = ocSpace; + + if (haveMultiAccount) { + if (spacePersonal == null) { + showListFiles(); + showRetainerFragment(); + updateDirectoryList(); + if (mParents.size() == 1) { + updateToolbar(getString(R.string.uploader_top_message)); + } + + } else { + mListView = findViewById(android.R.id.list); + fragmentContainer = findViewById(R.id.fragment_container); + mListView.setVisibility(View.GONE); + fragmentContainer.setVisibility(View.VISIBLE); + initAndShowListOfSpaces(); + updateToolbar(getString(R.string.choose_upload_space)); + getSupportFragmentManager().setFragmentResultListener(SpacesListFragment.REQUEST_KEY_CLICK_SPACE, this, (requestKey, + bundle) -> { + OCFile rootSpaceFolder = bundle.getParcelable(SpacesListFragment.BUNDLE_KEY_CLICK_SPACE); + mFile = rootSpaceFolder; + currentSpaceId = mFile.getSpaceId(); + showListFiles(); + updateDirectoryList(); + showRetainerFragment(); + }); + } + } else { //Sin multicuenta + if (spacePersonal != null) { + initAndShowListOfSpaces(); + updateToolbar(getString(R.string.choose_upload_space)); + getSupportFragmentManager().setFragmentResultListener(SpacesListFragment.REQUEST_KEY_CLICK_SPACE, this, (requestKey, + bundle) -> { + OCFile rootSpaceFolder = bundle.getParcelable(SpacesListFragment.BUNDLE_KEY_CLICK_SPACE); + mFile = rootSpaceFolder; + currentSpaceId = mFile.getSpaceId(); + showListFiles(); + updateDirectoryList(); + showRetainerFragment(); + }); + } else { + showListFiles(); + showRetainerFragment(); + updateDirectoryList(); + updateToolbar(getString(R.string.uploader_top_message)); + } + } + } + ); + } + + private void showListFiles() { fragmentContainer = findViewById(R.id.fragment_container); mListView = findViewById(android.R.id.list); fragmentContainer.setVisibility(View.GONE); @@ -276,9 +317,7 @@ private void initAndShowListOfSpaces() { private void initPickerListener() { cancelButton = findViewById(R.id.uploader_cancel); - cancelButton.setOnClickListener(view -> { - finish(); - }); + cancelButton.setOnClickListener(view -> finish()); } @Override @@ -311,12 +350,9 @@ protected void setAccount(Account account, boolean savedAccount) { @Override protected void onAccountSet(boolean stateWasRecovered) { super.onAccountSet(mAccountWasRestored); - mReceiveExternalFilesViewModel = get(ReceiveExternalFilesViewModel.class); + suscribeViewModel(); + mReceiveExternalFilesViewModel.getPersonalSpaceforAcount(getAccount().name); initTargetFolder(); - if (root.getSpaceId() == null) { - updateDirectoryList(); - updateToolbar(getString(R.string.uploader_top_message)); - } mReceiveExternalFilesViewModel.getSyncFolderLiveData().observe(this, eventUiResult -> { UIResult uiResult = eventUiResult.getContentIfNotHandled(); @@ -338,7 +374,7 @@ protected void onAccountSet(boolean stateWasRecovered) { } else if (uiResult instanceof UIResult.Success) { mSyncInProgress = false; updateDirectoryList(); - if (mParents.size() == 1 && root.getSpaceId() == null) { + if (mParents.size() == 1 && spacePersonal == null) { updateToolbar(getString(R.string.uploader_top_message)); } } @@ -385,6 +421,7 @@ public void onClick(DialogInterface dialog, int which) { Account[] accounts = mAccountManager.getAccountsByType(MainApp.Companion.getAccountType()); CharSequence[] dialogItems = new CharSequence[accounts.length]; OwnCloudAccount oca; + haveMultiAccount = true; for (int i = 0; i < dialogItems.length; ++i) { try { oca = new OwnCloudAccount(accounts[i], this); @@ -406,32 +443,7 @@ public void onClick(DialogInterface dialog, int which) { onAccountSet(mAccountWasRestored); dialog.dismiss(); PreferenceManager.setLastUploadPath("/", this); - root = getStorageManager().getRootPersonalFolder(); - if (root.getSpaceId() == null) { - showFilesview(); - showRetainerFragment(); - updateDirectoryList(); - if (mParents.size() == 1) { - updateToolbar(getString(R.string.uploader_top_message)); - } - - } else { - mListView = findViewById(android.R.id.list); - fragmentContainer = findViewById(R.id.fragment_container); - mListView.setVisibility(View.GONE); - fragmentContainer.setVisibility(View.VISIBLE); - initAndShowListOfSpaces(); - updateToolbar(getString(R.string.app_name)); - getSupportFragmentManager().setFragmentResultListener(SpacesListFragment.REQUEST_KEY_CLICK_SPACE, this, (requestKey, - bundle) -> { - OCFile rootSpaceFolder = bundle.getParcelable(SpacesListFragment.BUNDLE_KEY_CLICK_SPACE); - mFile = rootSpaceFolder; - currentSpace = mFile.getSpaceId(); - showFilesview(); - updateDirectoryList(); - showRetainerFragment(); - }); - } + mReceiveExternalFilesViewModel.getPersonalSpaceforAcount(getAccount().name); mAccountSelected = true; mAccountSelectionShowing = false; }); @@ -454,9 +466,9 @@ public void onBackPressed() { } else { mParents.pop(); String full_path = generatePath(mParents); - startSyncFolderOperation(getStorageManager().getFileByPath(full_path, currentSpace)); + startSyncFolderOperation(getStorageManager().getFileByPath(full_path, currentSpaceId)); updateDirectoryList(); - if (mParents.size() <= 1 && root.getSpaceId() == null) { + if (mParents.size() <= 1 && spacePersonal == null) { updateToolbar(getString(R.string.uploader_top_message)); } } @@ -542,7 +554,7 @@ private void updateDirectoryList() { sharedPreferencesProvider = new OCSharedPreferencesProvider(getApplicationContext()); showHiddenFiles = sharedPreferencesProvider.getBoolean(PREF_SHOW_HIDDEN_FILES, false); - mFile = getStorageManager().getFileByPath(full_path, currentSpace); + mFile = getStorageManager().getFileByPath(full_path, currentSpaceId); if (mFile != null) { if (mAdapter == null) { @@ -697,7 +709,7 @@ public void uploadFiles() { mStreamsToUpload, mUploadPath, getAccount(), - currentSpace, + currentSpaceId, true, // Show waiting dialog while file is being copied from private storage this // Copy temp task listener ); @@ -779,7 +791,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } else { mFile = null; initAndShowListOfSpaces(); - updateToolbar(getString(R.string.app_name)); + updateToolbar(getString(R.string.choose_upload_space)); fragmentContainer.setVisibility(View.VISIBLE); mListView.setVisibility(View.GONE); noPermissionsMessage.setVisibility(View.GONE); @@ -814,7 +826,7 @@ private OCFile getCurrentFolder() { if (file.isFolder()) { return file; } else if (getStorageManager() != null) { - return getStorageManager().getFileByPath(file.getParentRemotePath(), currentSpace); + return getStorageManager().getFileByPath(file.getParentRemotePath(), currentSpaceId); } } return null; @@ -985,7 +997,7 @@ private void showUploadTextDialog() { fileToUpload.add(filePath); @NotNull Lazy transfersViewModelLazy = inject(TransfersViewModel.class); TransfersViewModel transfersViewModel = transfersViewModelLazy.getValue(); - transfersViewModel.uploadFilesFromSystem(getAccount().name, fileToUpload, mUploadPath, currentSpace); + transfersViewModel.uploadFilesFromSystem(getAccount().name, fileToUpload, mUploadPath, currentSpaceId); finish(); inputLayout.setErrorEnabled(error != null); diff --git a/owncloudApp/src/main/res/values/strings.xml b/owncloudApp/src/main/res/values/strings.xml index b83d577a3ab..7e4b98db423 100644 --- a/owncloudApp/src/main/res/values/strings.xml +++ b/owncloudApp/src/main/res/values/strings.xml @@ -142,6 +142,7 @@ Log in Upload Choose upload folder + Choose upload space No account found There are no %1$s accounts on your device. Please set up an account first. Setup