Skip to content

Commit

Permalink
Merge pull request #4525 from owncloud/technical/technical_improvemen…
Browse files Browse the repository at this point in the history
…ts_for_quota

[TECHNICAL] Technical improvements for user quota
  • Loading branch information
joragua authored Jan 10, 2025
2 parents 1dfb53b + 016fc3d commit 6c9eb65
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 176 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ownCloud admins and users.
* Enhancement - Added text labels for BottomNavigationView: [#4484](https://github.com/owncloud/android/issues/4484)
* Enhancement - OCIS Light Users: [#4490](https://github.com/owncloud/android/issues/4490)
* Enhancement - Enforce OIDC auth flow via branding: [#4500](https://github.com/owncloud/android/issues/4500)
* Enhancement - Technical improvements for user quota: [#4521](https://github.com/owncloud/android/issues/4521)

## Details

Expand Down Expand Up @@ -124,6 +125,14 @@ ownCloud admins and users.
https://github.com/owncloud/android/issues/4500
https://github.com/owncloud/android/pull/4516

* Enhancement - Technical improvements for user quota: [#4521](https://github.com/owncloud/android/issues/4521)

A new use case has been added to fetch the user quota as a flow. Also, all
unnecessary calls from DrawerActivity have been removed.

https://github.com/owncloud/android/issues/4521
https://github.com/owncloud/android/pull/4525

# Changelog for ownCloud Android Client [4.4.1] (2024-10-30)

The following sections list the changes in ownCloud Android Client 4.4.1 relevant to
Expand Down
7 changes: 7 additions & 0 deletions changelog/unreleased/4525
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Technical improvements for user quota

A new use case has been added to fetch the user quota as a flow.
Also, all unnecessary calls from DrawerActivity have been removed.

https://github.com/owncloud/android/issues/4521
https://github.com/owncloud/android/pull/4525
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
* @author Aitor Ballesteros Pavón
* @author Jorge Aguado Recio
*
* Copyright (C) 2024 ownCloud GmbH.
*
Expand Down Expand Up @@ -101,6 +102,7 @@ import com.owncloud.android.domain.transfers.usecases.GetAllTransfersAsStreamUse
import com.owncloud.android.domain.transfers.usecases.GetAllTransfersUseCase
import com.owncloud.android.domain.transfers.usecases.UpdatePendingUploadsPathUseCase
import com.owncloud.android.domain.user.usecases.GetStoredQuotaUseCase
import com.owncloud.android.domain.user.usecases.GetStoredQuotaAsStreamUseCase
import com.owncloud.android.domain.user.usecases.GetUserAvatarAsyncUseCase
import com.owncloud.android.domain.user.usecases.GetUserInfoAsyncUseCase
import com.owncloud.android.domain.user.usecases.GetUserQuotasUseCase
Expand Down Expand Up @@ -252,6 +254,7 @@ val useCaseModule = module {
factoryOf(::UploadFilesFromSystemUseCase)

// User
factoryOf(::GetStoredQuotaAsStreamUseCase)
factoryOf(::GetStoredQuotaUseCase)
factoryOf(::GetUserAvatarAsyncUseCase)
factoryOf(::GetUserInfoAsyncUseCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class ManageAccountsAdapter(
}

else -> { // Limited storage. Value under 100%
if (userQuota.state == UserQuotaState.CRITICAL || userQuota.state == UserQuotaState.EXCEEDED) { // Value over 90%
if (userQuota.state == UserQuotaState.CRITICAL || userQuota.state == UserQuotaState.EXCEEDED ||
userQuota.state == UserQuotaState.NEARING) { // Value over 75%
quotaBar.apply {
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.quota_exceeded))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,65 +25,58 @@ package com.owncloud.android.presentation.common

import android.accounts.Account
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.owncloud.android.R
import com.owncloud.android.data.providers.LocalStorageProvider
import com.owncloud.android.domain.user.model.UserQuota
import com.owncloud.android.domain.user.usecases.GetStoredQuotaUseCase
import com.owncloud.android.domain.user.usecases.GetStoredQuotaAsStreamUseCase
import com.owncloud.android.domain.user.usecases.GetUserQuotasUseCase
import com.owncloud.android.domain.utils.Event
import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult
import com.owncloud.android.presentation.authentication.AccountUtils
import com.owncloud.android.providers.ContextProvider
import com.owncloud.android.providers.CoroutinesDispatcherProvider
import com.owncloud.android.usecases.accounts.RemoveAccountUseCase
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import timber.log.Timber

class DrawerViewModel(
private val getStoredQuotaUseCase: GetStoredQuotaUseCase,
private val getStoredQuotaAsStreamUseCase: GetStoredQuotaAsStreamUseCase,
private val removeAccountUseCase: RemoveAccountUseCase,
private val getUserQuotasUseCase: GetUserQuotasUseCase,
private val localStorageProvider: LocalStorageProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
private val contextProvider: ContextProvider,
) : ViewModel() {

private val _userQuota = MediatorLiveData<Event<UIResult<UserQuota?>>>()
val userQuota: LiveData<Event<UIResult<UserQuota?>>> = _userQuota
private val _userQuota = MutableStateFlow<Event<UIResult<Flow<UserQuota?>>>?>(null)
val userQuota: StateFlow<Event<UIResult<Flow<UserQuota?>>>?> = _userQuota

fun getStoredQuota(
accountName: String
) = runUseCaseWithResult(
coroutineDispatcher = coroutinesDispatcherProvider.io,
requiresConnection = false,
showLoading = true,
liveData = _userQuota,
useCase = getStoredQuotaUseCase,
useCaseParams = GetStoredQuotaUseCase.Params(accountName = accountName)
)
fun getUserQuota(accountName: String) {
runUseCaseWithResult(
coroutineDispatcher = coroutinesDispatcherProvider.io,
requiresConnection = false,
showLoading = true,
flow = _userQuota,
useCase = getStoredQuotaAsStreamUseCase,
useCaseParams = GetStoredQuotaAsStreamUseCase.Params(accountName = accountName),
)
}

fun getAccounts(context: Context): List<Account> {
return AccountUtils.getAccounts(context).asList()
}

fun getCurrentAccount(context: Context): Account? {
return AccountUtils.getCurrentOwnCloudAccount(context)
}

fun getUsernameOfAccount(accountName: String): String {
return AccountUtils.getUsernameOfAccount(accountName)
}

fun getFeedbackMail() = contextProvider.getString(R.string.mail_feedback)

fun setCurrentAccount(context: Context, accountName: String): Boolean {
return AccountUtils.setCurrentOwnCloudAccount(context, accountName)
}

fun removeAccount(context: Context) {
viewModelScope.launch(coroutinesDispatcherProvider.io) {
val loggedAccounts = AccountUtils.getAccounts(context)
Expand Down
Loading

0 comments on commit 6c9eb65

Please sign in to comment.