Skip to content

Commit

Permalink
feat: adapted ReceiveExternalFiles (Activity and ViewModel) for lig…
Browse files Browse the repository at this point in the history
…ht users
  • Loading branch information
joragua committed Nov 26, 2024
1 parent 507a4fe commit daa5ad4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ val viewModelModule = module {
viewModel { AuthenticationViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { MigrationViewModel(MainApp.dataFolder, get(), get(), get(), get(), get(), get(), get()) }
viewModel { TransfersViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { ReceiveExternalFilesViewModel(get(), get(), get()) }
viewModel { ReceiveExternalFilesViewModel(get(), get(), get(), 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
@@ -1,7 +1,7 @@
/**
* ownCloud Android client application
*
* Copyright (C) 2022 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -22,9 +22,8 @@ import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.owncloud.android.domain.capabilities.usecases.GetStoredCapabilitiesUseCase
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
Expand All @@ -35,15 +34,14 @@ import kotlinx.coroutines.launch
class ReceiveExternalFilesViewModel(
private val synchronizeFolderUseCase: SynchronizeFolderUseCase,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
private val getPersonalSpaceForAccountUseCase: GetPersonalSpaceForAccountUseCase,
private val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase,
) : 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

private val _spacesAreAllowed = MutableLiveData<Boolean>()
val spacesAreAllowed: LiveData<Boolean> = _spacesAreAllowed

fun refreshFolderUseCase(
folderToSync: OCFile,
Expand All @@ -60,16 +58,12 @@ class ReceiveExternalFilesViewModel(
)
)

fun getPersonalSpaceForAccount(accountName: String) {
fun areSpacesAllowed(accountName: String) {
viewModelScope.launch(coroutinesDispatcherProvider.io) {
val result = getPersonalSpaceForAccountUseCase(
GetPersonalSpaceForAccountUseCase.Params(
accountName = accountName
)
)
_personalSpaceLiveData.postValue(result)
val capabilities = getStoredCapabilitiesUseCase(GetStoredCapabilitiesUseCase.Params(accountName))
val spacesAvailableForAccount = capabilities?.isSpacesAllowed() == true
_spacesAreAllowed.postValue(spacesAvailableForAccount)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author Abel García de Prada
* @author John Kalimeris
* @author Aitor Ballesteros Pavón
* @author Jorge Aguado Recio
*
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2024 ownCloud GmbH.
Expand Down Expand Up @@ -179,7 +180,7 @@ public class ReceiveExternalFilesActivity extends FileActivity

private boolean showHiddenFiles;
private OCSharedPreferencesProvider sharedPreferencesProvider;
private OCSpace personalSpace;
private boolean areSpacesAllowed;


Pattern pattern = Pattern.compile("[/\\\\]");
Expand Down Expand Up @@ -228,10 +229,11 @@ protected void onCreate(Bundle savedInstanceState) {

}
private void subscribeToViewModels() {
mReceiveExternalFilesViewModel.getPersonalSpaceLiveData().observe(this, ocSpace -> {
personalSpace = ocSpace;
mReceiveExternalFilesViewModel.areSpacesAllowed(getAccount().name);
mReceiveExternalFilesViewModel.getSpacesAreAllowed().observe(this, spaces -> {
areSpacesAllowed = spaces;

if (personalSpace == null) { // OC10 Server
if (!areSpacesAllowed) { // OC10 Server
showListOfFiles();
showRetainerFragment();
updateDirectoryList();
Expand Down Expand Up @@ -337,7 +339,7 @@ protected void setAccount(Account account, boolean savedAccount) {
@Override
protected void onAccountSet(boolean stateWasRecovered) {
super.onAccountSet(mAccountWasRestored);
mReceiveExternalFilesViewModel.getPersonalSpaceForAccount(getAccount().name);
mReceiveExternalFilesViewModel.areSpacesAllowed(getAccount().name);
initTargetFolder();

mReceiveExternalFilesViewModel.getSyncFolderLiveData().observe(this, eventUiResult -> {
Expand All @@ -360,7 +362,7 @@ protected void onAccountSet(boolean stateWasRecovered) {
} else if (uiResult instanceof UIResult.Success) {
mSyncInProgress = false;
updateDirectoryList();
if (mParents.size() == 1 && personalSpace == null) {
if (mParents.size() == 1) {
updateToolbar(getString(R.string.uploader_top_message));
}
if(fragmentContainer.getVisibility() == View.VISIBLE) {
Expand Down Expand Up @@ -433,7 +435,7 @@ public void onClick(DialogInterface dialog, int which) {
onAccountSet(mAccountWasRestored);
dialog.dismiss();
PreferenceManager.setLastUploadPath("/", this);
mReceiveExternalFilesViewModel.getPersonalSpaceForAccount(getAccount().name);
mReceiveExternalFilesViewModel.areSpacesAllowed(getAccount().name);
mAccountSelected = true;
mAccountSelectionShowing = false;
});
Expand All @@ -458,7 +460,7 @@ public void onBackPressed() {
String full_path = generatePath(mParents);
startSyncFolderOperation(getStorageManager().getFileByPath(full_path, currentSpaceId));
updateDirectoryList();
if (mParents.size() <= 1 && personalSpace == null) {
if (mParents.size() <= 1) {
updateToolbar(getString(R.string.uploader_top_message));
}
}
Expand Down

0 comments on commit daa5ad4

Please sign in to comment.