Skip to content

Commit

Permalink
refactor: moved checkUserLight method to ManageAccountsViewModel
Browse files Browse the repository at this point in the history
…and removed unnecessary check for refresh operation
  • Loading branch information
joragua committed Dec 3, 2024
1 parent 70e6e98 commit 1c13299
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)

}
Expand Down

0 comments on commit 1c13299

Please sign in to comment.