diff --git a/owncloudApp/src/main/java/com/owncloud/android/MainApp.kt b/owncloudApp/src/main/java/com/owncloud/android/MainApp.kt index 61951578c16..afc5132ab74 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/MainApp.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/MainApp.kt @@ -51,7 +51,6 @@ import com.owncloud.android.domain.capabilities.usecases.GetStoredCapabilitiesUs import com.owncloud.android.domain.spaces.model.OCSpace import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase import com.owncloud.android.domain.user.usecases.GetStoredQuotaUseCase -import com.owncloud.android.domain.user.usecases.GetUserQuotasUseCase import com.owncloud.android.extensions.createNotificationChannel import com.owncloud.android.lib.common.SingleSessionManager import com.owncloud.android.presentation.authentication.AccountUtils 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 5a5abd60001..0dbc8bd07ff 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt @@ -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) } 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 582c2d5b113..9fccbcf8eeb 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/ReceiveExternalFilesViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/ReceiveExternalFilesViewModel.kt @@ -35,6 +35,7 @@ class ReceiveExternalFilesViewModel( private val synchronizeFolderUseCase: SynchronizeFolderUseCase, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, private val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase, + private val accountName: String, ) : ViewModel() { private val _syncFolderLiveData = MediatorLiveData>>() @@ -43,6 +44,14 @@ class ReceiveExternalFilesViewModel( private val _spacesAreAllowed = MutableLiveData() val spacesAreAllowed: LiveData = _spacesAreAllowed + init { + viewModelScope.launch(coroutinesDispatcherProvider.io) { + val capabilities = getStoredCapabilitiesUseCase(GetStoredCapabilitiesUseCase.Params(accountName)) + val spacesAvailableForAccount = capabilities?.isSpacesAllowed() == true + _spacesAreAllowed.postValue(spacesAvailableForAccount) + } + } + fun refreshFolderUseCase( folderToSync: OCFile, ) = runUseCaseWithResult( @@ -58,12 +67,4 @@ class ReceiveExternalFilesViewModel( ) ) - fun areSpacesAllowed(accountName: String) { - viewModelScope.launch(coroutinesDispatcherProvider.io) { - val capabilities = getStoredCapabilitiesUseCase(GetStoredCapabilitiesUseCase.Params(accountName)) - val spacesAvailableForAccount = capabilities?.isSpacesAllowed() == true - _spacesAreAllowed.postValue(spacesAvailableForAccount) - } - } - } 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 a0795fad04c..1e8af8197b5 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 @@ -73,7 +73,6 @@ 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; @@ -118,6 +117,7 @@ import java.util.regex.Pattern; import static com.owncloud.android.presentation.settings.advanced.SettingsAdvancedFragment.PREF_SHOW_HIDDEN_FILES; +import static org.koin.core.parameter.ParametersHolderKt.parametersOf; import static org.koin.java.KoinJavaComponent.get; import static org.koin.java.KoinJavaComponent.inject; @@ -222,14 +222,11 @@ protected void onCreate(Bundle savedInstanceState) { } mSortOptionsView.setVisibility(View.GONE); - mReceiveExternalFilesViewModel = get(ReceiveExternalFilesViewModel.class); - subscribeToViewModels(); initPickerListener(); } private void subscribeToViewModels() { - mReceiveExternalFilesViewModel.areSpacesAllowed(getAccount().name); mReceiveExternalFilesViewModel.getSpacesAreAllowed().observe(this, spaces -> { areSpacesAllowed = spaces; @@ -339,7 +336,8 @@ protected void setAccount(Account account, boolean savedAccount) { @Override protected void onAccountSet(boolean stateWasRecovered) { super.onAccountSet(mAccountWasRestored); - mReceiveExternalFilesViewModel.areSpacesAllowed(getAccount().name); + mReceiveExternalFilesViewModel = get(ReceiveExternalFilesViewModel.class, null , () -> parametersOf(getAccount().name)); + subscribeToViewModels(); initTargetFolder(); mReceiveExternalFilesViewModel.getSyncFolderLiveData().observe(this, eventUiResult -> { @@ -362,7 +360,7 @@ protected void onAccountSet(boolean stateWasRecovered) { } else if (uiResult instanceof UIResult.Success) { mSyncInProgress = false; updateDirectoryList(); - if (mParents.size() == 1) { + if (mParents.size() == 1 && !areSpacesAllowed) { updateToolbar(getString(R.string.uploader_top_message)); } if(fragmentContainer.getVisibility() == View.VISIBLE) { @@ -435,7 +433,6 @@ public void onClick(DialogInterface dialog, int which) { onAccountSet(mAccountWasRestored); dialog.dismiss(); PreferenceManager.setLastUploadPath("/", this); - mReceiveExternalFilesViewModel.areSpacesAllowed(getAccount().name); mAccountSelected = true; mAccountSelectionShowing = false; }); @@ -460,7 +457,7 @@ public void onBackPressed() { String full_path = generatePath(mParents); startSyncFolderOperation(getStorageManager().getFileByPath(full_path, currentSpaceId)); updateDirectoryList(); - if (mParents.size() <= 1) { + if (mParents.size() <= 1 && !areSpacesAllowed) { updateToolbar(getString(R.string.uploader_top_message)); } }