-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TECHNICAL] Technical improvements for user quota #4525
base: master
Are you sure you want to change the base?
Changes from all commits
7324483
5525e42
8d5c35f
3a3a4e2
6ab970d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -59,6 +59,7 @@ import com.owncloud.android.domain.capabilities.model.OCCapability | |
import com.owncloud.android.domain.files.model.FileListOption | ||
import com.owncloud.android.domain.user.model.UserQuotaState | ||
import com.owncloud.android.domain.utils.Event | ||
import com.owncloud.android.extensions.collectLatestLifecycleFlow | ||
import com.owncloud.android.extensions.goToUrl | ||
import com.owncloud.android.extensions.openPrivacyPolicy | ||
import com.owncloud.android.extensions.sendEmailOrOpenFeedbackDialogAction | ||
|
@@ -82,7 +83,11 @@ import timber.log.Timber | |
*/ | ||
abstract class DrawerActivity : ToolbarActivity() { | ||
|
||
private val drawerViewModel by viewModel<DrawerViewModel>() | ||
private val drawerViewModel by viewModel<DrawerViewModel> { | ||
parametersOf( | ||
account?.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if |
||
) | ||
} | ||
private val capabilitiesViewModel by viewModel<CapabilityViewModel> { | ||
parametersOf( | ||
account?.name | ||
|
@@ -287,7 +292,6 @@ abstract class DrawerActivity : ToolbarActivity() { | |
open fun openDrawer() { | ||
getDrawerLayout()?.openDrawer(GravityCompat.START) | ||
findViewById<View>(R.id.nav_view).requestFocus() | ||
drawerViewModel.getStoredQuota(account.name) | ||
} | ||
|
||
/** | ||
|
@@ -305,115 +309,105 @@ abstract class DrawerActivity : ToolbarActivity() { | |
*/ | ||
private fun updateQuota() { | ||
Timber.d("Update Quota") | ||
val account = drawerViewModel.getCurrentAccount(this) ?: return | ||
drawerViewModel.getStoredQuota(account.name) | ||
drawerViewModel.userQuota.observe(this) { event -> | ||
when (val uiResult = event.peekContent()) { | ||
is UIResult.Success -> { | ||
uiResult.data?.let { userQuota -> | ||
when { | ||
userQuota.available == -4L -> { // Light users (oCIS) | ||
getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage) | ||
getAccountQuotaBar()?.isVisible = false | ||
getAccountQuotaStatusText()?.isVisible = false | ||
} | ||
|
||
userQuota.available < 0 -> { // Pending, unknown or unlimited free storage | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = 0 | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.color_accent)) | ||
} | ||
getAccountQuotaText()?.text = String.format( | ||
getString(R.string.drawer_unavailable_free_storage), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, this, true) | ||
) | ||
getAccountQuotaStatusText()?.visibility = View.GONE | ||
} | ||
|
||
userQuota.available == 0L -> { // Exceeded storage. The value is over 100%. | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = 100 | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.quota_exceeded)) | ||
} | ||
|
||
if (userQuota.state == UserQuotaState.EXCEEDED) { // oCIS | ||
getAccountQuotaText()?.apply { | ||
text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), | ||
userQuota.getRelative() | ||
) | ||
} | ||
getAccountQuotaStatusText()?.apply { | ||
visibility = View.VISIBLE | ||
text = getString(R.string.drawer_exceeded_quota) | ||
} | ||
} else { // oC10 | ||
getAccountQuotaText()?.text = getString(R.string.drawer_exceeded_quota) | ||
getAccountQuotaStatusText()?.visibility = View.GONE | ||
} | ||
} | ||
|
||
else -> { // Limited storage. Value under 100% | ||
if (userQuota.state == UserQuotaState.NEARING) { // Nearing storage. Value between 75% and 90% | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = userQuota.getRelative().toInt() | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.color_accent)) | ||
} | ||
getAccountQuotaText()?.apply { | ||
text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), | ||
userQuota.getRelative() | ||
) | ||
} | ||
getAccountQuotaStatusText()?.apply { | ||
visibility = View.VISIBLE | ||
text = getString(R.string.drawer_nearing_quota) | ||
} | ||
} else if (userQuota.state == UserQuotaState.CRITICAL || userQuota.state == UserQuotaState.EXCEEDED) { // Critical storage. Value over 90% | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = userQuota.getRelative().toInt() | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.quota_exceeded)) | ||
} | ||
getAccountQuotaText()?.apply { | ||
text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), | ||
userQuota.getRelative() | ||
) | ||
} | ||
getAccountQuotaStatusText()?.apply { | ||
visibility = View.VISIBLE | ||
text = getString(R.string.drawer_critical_quota) | ||
} | ||
} else { // Normal storage. Value under 75% | ||
getAccountQuotaBar()?.apply { | ||
progress = userQuota.getRelative().toInt() | ||
isVisible = true | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.color_accent)) | ||
} | ||
getAccountQuotaText()?.text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, this, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), this, true), | ||
userQuota.getRelative() | ||
) | ||
getAccountQuotaStatusText()?.visibility = View.GONE | ||
} | ||
} | ||
collectLatestLifecycleFlow(drawerViewModel.userQuota) { userQuota -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some changes in all these lines in the Detekt branch, I think just for the |
||
when { | ||
userQuota.available == -4L -> { // Light users (oCIS) | ||
getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage) | ||
getAccountQuotaBar()?.isVisible = false | ||
getAccountQuotaStatusText()?.isVisible = false | ||
} | ||
|
||
userQuota.available < 0 -> { // Pending, unknown or unlimited free storage | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = 0 | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.color_accent)) | ||
} | ||
getAccountQuotaText()?.text = String.format( | ||
getString(R.string.drawer_unavailable_free_storage), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, this, true) | ||
) | ||
getAccountQuotaStatusText()?.visibility = View.GONE | ||
} | ||
|
||
userQuota.available == 0L -> { // Exceeded storage. The value is over 100%. | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = 100 | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.quota_exceeded)) | ||
} | ||
|
||
if (userQuota.state == UserQuotaState.EXCEEDED) { // oCIS | ||
getAccountQuotaText()?.apply { | ||
text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), | ||
userQuota.getRelative() | ||
) | ||
} | ||
getAccountQuotaStatusText()?.apply { | ||
visibility = View.VISIBLE | ||
text = getString(R.string.drawer_exceeded_quota) | ||
} | ||
} else { // oC10 | ||
getAccountQuotaText()?.text = getString(R.string.drawer_exceeded_quota) | ||
getAccountQuotaStatusText()?.visibility = View.GONE | ||
} | ||
} | ||
|
||
else -> { // Limited storage. Value under 100% | ||
if (userQuota.state == UserQuotaState.NEARING) { // Nearing storage. Value between 75% and 90% | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = userQuota.getRelative().toInt() | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.color_accent)) | ||
} | ||
getAccountQuotaText()?.apply { | ||
text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), | ||
userQuota.getRelative() | ||
) | ||
} | ||
getAccountQuotaStatusText()?.apply { | ||
visibility = View.VISIBLE | ||
text = getString(R.string.drawer_nearing_quota) | ||
} | ||
} else if (userQuota.state == UserQuotaState.CRITICAL || userQuota.state == UserQuotaState.EXCEEDED) { // Critical storage. Value over 90% | ||
getAccountQuotaBar()?.apply { | ||
isVisible = true | ||
progress = userQuota.getRelative().toInt() | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.quota_exceeded)) | ||
} | ||
getAccountQuotaText()?.apply { | ||
text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), | ||
userQuota.getRelative() | ||
) | ||
} | ||
getAccountQuotaStatusText()?.apply { | ||
visibility = View.VISIBLE | ||
text = getString(R.string.drawer_critical_quota) | ||
} | ||
} else { // Normal storage. Value under 75% | ||
getAccountQuotaBar()?.apply { | ||
progress = userQuota.getRelative().toInt() | ||
isVisible = true | ||
progressTintList = ColorStateList.valueOf(resources.getColor(R.color.color_accent)) | ||
} | ||
getAccountQuotaText()?.text = String.format( | ||
getString(R.string.drawer_quota), | ||
DisplayUtils.bytesToHumanReadable(userQuota.used, this, true), | ||
DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), this, true), | ||
userQuota.getRelative() | ||
) | ||
getAccountQuotaStatusText()?.visibility = View.GONE | ||
} | ||
} | ||
is UIResult.Loading -> getAccountQuotaText()?.text = getString(R.string.drawer_loading_quota) | ||
is UIResult.Error -> getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage) | ||
Comment on lines
-415
to
-416
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're losing these 2 cases!! We shouldn't, they are so necessary |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, not sure if I like this... I think it would be better being encapsulated with a private variable. Otherwise everytime we access
userQuota
, the use case might be executed, and that's not what we want. Check for exampleSettingsPictureUploadsViewModel
to see how this is done with thepictureUploads
variable 👍