Skip to content

Commit

Permalink
Corrections from CR
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitorbp committed Sep 22, 2023
1 parent 9d4aca4 commit c515817
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 71 deletions.
6 changes: 3 additions & 3 deletions changelog/unreleased/4160
Original file line number Diff line number Diff line change
@@ -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
https://github.com/owncloud/android/pull/4160
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event<UIResult<Unit>>>()
val syncFolderLiveData: LiveData<Event<UIResult<Unit>>> = _syncFolderLiveData

private val _personalSpaceLiveData = MutableLiveData<OCSpace?>()
val personalSpaceLiveData: LiveData<OCSpace?> = _personalSpaceLiveData


fun refreshFolderUseCase(
folderToSync: OCFile,
) = runUseCaseWithResult(
Expand All @@ -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)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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("[/\\\\]");

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Unit> uiResult = eventUiResult.getContentIfNotHandled();
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
});
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -985,7 +997,7 @@ private void showUploadTextDialog() {
fileToUpload.add(filePath);
@NotNull Lazy<TransfersViewModel> 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);
Expand Down
1 change: 1 addition & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<string name="setup_btn_login">Log in</string>
<string name="uploader_btn_upload_text">Upload</string>
<string name="uploader_top_message">Choose upload folder</string>
<string name="choose_upload_space">Choose upload space</string>
<string name="uploader_wrn_no_account_title">No account found</string>
<string name="uploader_wrn_no_account_text">There are no %1$s accounts on your device. Please set up an account first.</string>
<string name="uploader_wrn_no_account_setup_btn_text">Setup</string>
Expand Down

0 comments on commit c515817

Please sign in to comment.