diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsAdapter.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsAdapter.kt index 7a468ff5d20..46f301ba79a 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsAdapter.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/accounts/ManageAccountsAdapter.kt @@ -159,7 +159,7 @@ class ManageAccountsAdapter( quotaBar.visibility = View.GONE quotaText.text = DisplayUtils.bytesToHumanReadable(userQuota.used, context, false) - } else if (userQuota.state == EXCEEDED_STATE) { + } else if (userQuota.isExceeded()) { quotaBar.apply { progress = 100 progressTintList = ColorStateList.valueOf(resources.getColor(R.color.quota_exceeded)) @@ -218,7 +218,4 @@ class ManageAccountsAdapter( fun switchAccount(position: Int) } - companion object { - private const val EXCEEDED_STATE = "exceeded" - } } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt index 9aaf8526241..cf80945761e 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt @@ -286,7 +286,7 @@ abstract class DrawerActivity : ToolbarActivity() { open fun openDrawer() { getDrawerLayout()?.openDrawer(GravityCompat.START) findViewById(R.id.nav_view).requestFocus() - updateQuota() + drawerViewModel.getStoredQuota(account.name) } /** @@ -320,7 +320,7 @@ abstract class DrawerActivity : ToolbarActivity() { DisplayUtils.bytesToHumanReadable(userQuota.used, this, true) ) - } else if (userQuota.state == EXCEEDED_STATE) { + } else if (userQuota.isExceeded()) { getAccountQuotaBar()?.apply { isVisible = true progress = 100 @@ -330,7 +330,7 @@ abstract class DrawerActivity : ToolbarActivity() { text = String.format( getString(R.string.drawer_quota), DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), - DisplayUtils.bytesToHumanReadable(userQuota.total, context, true), + DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), userQuota.getRelative() ) } @@ -344,7 +344,7 @@ abstract class DrawerActivity : ToolbarActivity() { getAccountQuotaBar()?.isVisible = false getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage) - } else if (userQuota.state == NEARING_STATE) { + } else if (userQuota.isNearing()) { getAccountQuotaBar()?.apply { isVisible = true progress = userQuota.getRelative().toInt() @@ -353,7 +353,7 @@ abstract class DrawerActivity : ToolbarActivity() { text = String.format( getString(R.string.drawer_quota), DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), - DisplayUtils.bytesToHumanReadable(userQuota.total, context, true), + DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), userQuota.getRelative() ) } @@ -362,7 +362,7 @@ abstract class DrawerActivity : ToolbarActivity() { text = getString(R.string.drawer_nearing_quota) } - } else if (userQuota.state == CRITICAL_STATE) { + } else if (userQuota.isCritical()) { getAccountQuotaBar()?.apply { isVisible = true progress = userQuota.getRelative().toInt() @@ -371,7 +371,7 @@ abstract class DrawerActivity : ToolbarActivity() { text = String.format( getString(R.string.drawer_quota), DisplayUtils.bytesToHumanReadable(userQuota.used, context, true), - DisplayUtils.bytesToHumanReadable(userQuota.total, context, true), + DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), context, true), userQuota.getRelative() ) } @@ -389,7 +389,7 @@ abstract class DrawerActivity : ToolbarActivity() { getAccountQuotaText()?.text = String.format( getString(R.string.drawer_quota), DisplayUtils.bytesToHumanReadable(userQuota.used, this, true), - DisplayUtils.bytesToHumanReadable(userQuota.total, this, true), + DisplayUtils.bytesToHumanReadable(userQuota.getTotal(), this, true), userQuota.getRelative() ) } @@ -594,8 +594,5 @@ abstract class DrawerActivity : ToolbarActivity() { const val SURVEY_URL = "https://owncloud.com/android-app-feedback" private const val KEY_IS_ACCOUNT_CHOOSER_ACTIVE = "IS_ACCOUNT_CHOOSER_ACTIVE" private const val KEY_CHECKED_MENU_ITEM = "CHECKED_MENU_ITEM" - private const val EXCEEDED_STATE = "exceeded" - private const val NEARING_STATE = "nearing" - private const val CRITICAL_STATE = "critical" } } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/user/model/UserQuota.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/user/model/UserQuota.kt index 9a12564ee63..146196754c8 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/user/model/UserQuota.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/user/model/UserQuota.kt @@ -42,4 +42,16 @@ data class UserQuota( } fun getTotal(): Long = total ?: (available + used) + + fun isExceeded(): Boolean = state == EXCEEDED_STATE + + fun isCritical(): Boolean = state == CRITICAL_STATE + + fun isNearing(): Boolean = state == NEARING_STATE + + companion object { + private const val EXCEEDED_STATE = "exceeded" + private const val CRITICAL_STATE = "critical" + private const val NEARING_STATE = "nearing" + } }