Skip to content

Commit

Permalink
feat: added state logic in UserQuota model instead of drawer and mana…
Browse files Browse the repository at this point in the history
…ge accounts dialog
  • Loading branch information
joragua committed Nov 5, 2024
1 parent 21b7089 commit 2f7bae6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -218,7 +218,4 @@ class ManageAccountsAdapter(
fun switchAccount(position: Int)
}

companion object {
private const val EXCEEDED_STATE = "exceeded"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ abstract class DrawerActivity : ToolbarActivity() {
open fun openDrawer() {
getDrawerLayout()?.openDrawer(GravityCompat.START)
findViewById<View>(R.id.nav_view).requestFocus()
updateQuota()
drawerViewModel.getStoredQuota(account.name)
}

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

0 comments on commit 2f7bae6

Please sign in to comment.