diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsViewModel.kt index 88fd5a64d8f..283918cc137 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsViewModel.kt @@ -29,6 +29,7 @@ import androidx.lifecycle.viewModelScope import com.owncloud.android.domain.user.model.UserQuota import com.owncloud.android.domain.automaticuploads.model.AutomaticUploadsConfiguration import com.owncloud.android.domain.automaticuploads.usecases.GetAutomaticUploadsConfigurationUseCase +import com.owncloud.android.domain.user.usecases.GetStoredQuotaUseCase import com.owncloud.android.domain.user.usecases.GetUserQuotasAsStreamUseCase import com.owncloud.android.domain.utils.Event import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult @@ -40,11 +41,14 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext class ManageAccountsViewModel( private val accountProvider: AccountProvider, private val removeLocalFilesForAccountUseCase: RemoveLocalFilesForAccountUseCase, private val getAutomaticUploadsConfigurationUseCase: GetAutomaticUploadsConfigurationUseCase, + private val getStoredQuotaUseCase: GetStoredQuotaUseCase, getUserQuotasAsStreamUseCase: GetUserQuotasAsStreamUseCase, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, ) : ViewModel() { @@ -84,4 +88,11 @@ class ManageAccountsViewModel( return accountName == automaticUploadsConfiguration?.pictureUploadsConfiguration?.accountName || accountName == automaticUploadsConfiguration?.videoUploadsConfiguration?.accountName } + + fun checkUserLight(accountName: String): Boolean = runBlocking(CoroutinesDispatcherProvider().io) { + val quota = withContext(CoroutinesDispatcherProvider().io) { + getStoredQuotaUseCase(GetStoredQuotaUseCase.Params(accountName)) + } + quota.getDataOrNull()?.available == -4L + } } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/common/DrawerViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/common/DrawerViewModel.kt index d942a3add09..87650242790 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/common/DrawerViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/common/DrawerViewModel.kt @@ -110,11 +110,4 @@ class DrawerViewModel( } } - fun checkUserLight(accountName: String): Boolean = runBlocking(CoroutinesDispatcherProvider().io) { - val quota = withContext(CoroutinesDispatcherProvider().io) { - getStoredQuotaUseCase(GetStoredQuotaUseCase.Params(accountName)) - } - quota.getDataOrNull()?.available == -4L - } - } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt index d4ce9415082..ee9abe69faf 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt @@ -316,11 +316,7 @@ class MainFileListFragment : Fragment(), // Observe the current folder displayed collectLatestLifecycleFlow(mainFileListViewModel.currentFolderDisplayed) { currentFolderDisplayed: OCFile -> fileActions?.onCurrentFolderUpdated(currentFolderDisplayed, mainFileListViewModel.getSpace()) - val fileListOption = if (isPickingAFolder()) { - mainFileListViewModel.fileListOption.value - } else { - (requireActivity() as FileDisplayActivity).fileListOption - } + val fileListOption = mainFileListViewModel.fileListOption.value val refreshFolderNeeded = fileListOption.isAllFiles() || (!fileListOption.isAllFiles() && currentFolderDisplayed.remotePath != ROOT_PATH && !fileListOption.isAvailableOffline()) if (refreshFolderNeeded) { @@ -814,9 +810,9 @@ class MainFileListFragment : Fragment(), } fun updateFileListOption(newFileListOption: FileListOption, file: OCFile) { - mainFileListViewModel.updateFolderToDisplay(file) mainFileListViewModel.updateFileListOption(newFileListOption) binding.swipeRefreshMainFileList.isEnabled = newFileListOption != FileListOption.AV_OFFLINE + mainFileListViewModel.updateFolderToDisplay(file) showOrHideFab(newFileListOption, file) } 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 797399ff93d..ef9ad591db4 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 @@ -92,6 +92,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode import com.owncloud.android.lib.resources.status.OwnCloudVersion import com.owncloud.android.operations.SyncProfileOperation +import com.owncloud.android.presentation.accounts.ManageAccountsViewModel import com.owncloud.android.presentation.authentication.AccountUtils.getCurrentOwnCloudAccount import com.owncloud.android.presentation.capabilities.CapabilityViewModel import com.owncloud.android.presentation.common.DrawerViewModel @@ -187,7 +188,7 @@ class FileDisplayActivity : FileActivity(), private val fileOperationsViewModel: FileOperationsViewModel by viewModel() private val transfersViewModel: TransfersViewModel by viewModel() private lateinit var spacesListViewModel: SpacesListViewModel - private val drawerViewModel: DrawerViewModel by viewModel() + private val manageAccountsViewModel: ManageAccountsViewModel by viewModel() private val sharedPreferences: SharedPreferencesProvider by inject() @@ -323,7 +324,7 @@ class FileDisplayActivity : FileActivity(), capabilitiesViewModel.capabilities.observe(this, Event.EventObserver { onCapabilitiesOperationFinish(it) }) - isLightUser = drawerViewModel.checkUserLight(account.name) + isLightUser = manageAccountsViewModel.checkUserLight(account.name) navigateTo(fileListOption, initialState = true) }