@@ -65,7 +65,7 @@ class CreateSpaceDialogFragment : DialogFragment() {
6565 updateUI()
6666 createSpaceDialogQuotaNoRestrictionLabel.isVisible = ! isChecked
6767 createSpaceDialogQuotaLayout.isVisible = isChecked
68- createSpaceDialogQuotaGbLabel .isVisible = isChecked
68+ createSpaceDialogQuotaUnitLabel .isVisible = isChecked
6969 }
7070
7171 if (isEditMode) {
@@ -78,7 +78,9 @@ class CreateSpaceDialogFragment : DialogFragment() {
7878 val totalQuota = it.quota?.total ? : 0L
7979 if (totalQuota != 0L ) {
8080 createSpaceDialogQuotaSwitch.isChecked = true
81- createSpaceDialogQuotaValue.setText(DisplayUtils .formatFromBytesToGb(totalQuota))
81+ val formattedQuota = DisplayUtils .formatFromBytes(totalQuota)
82+ createSpaceDialogQuotaValue.setText(formattedQuota.first)
83+ createSpaceDialogQuotaUnitLabel.text = formattedQuota.second
8284 }
8385 }
8486
@@ -91,7 +93,8 @@ class CreateSpaceDialogFragment : DialogFragment() {
9193 createSpaceButton.setOnClickListener {
9294 val spaceName = createSpaceDialogNameValue.text.toString()
9395 val spaceSubtitle = createSpaceDialogSubtitleValue.text.toString()
94- val spaceQuota = if (createSpaceDialogQuotaSwitch.isChecked) convertToBytes(createSpaceDialogQuotaValue.text.toString()) else 0L
96+ val spaceQuota = if (createSpaceDialogQuotaSwitch.isChecked) convertToBytes(createSpaceDialogQuotaValue.text.toString(),
97+ createSpaceDialogQuotaUnitLabel.text.toString()) else 0L
9598
9699 if (isEditMode) {
97100 currentSpace?.let {
@@ -127,15 +130,16 @@ class CreateSpaceDialogFragment : DialogFragment() {
127130
128131 return when {
129132 spaceQuota.isEmpty() -> getString(R .string.create_space_dialog_quota_empty_error)
130- spaceQuota.toDouble() == MIN_SPACE_QUOTA_GB -> getString(R .string.create_space_dialog_quota_zero_error)
131- spaceQuota.toDouble() > MAX_SPACE_QUOTA_GB -> getString(R .string.create_space_dialog_quota_too_large_error)
133+ spaceQuota.toDouble() == MIN_SPACE_QUOTA_LIMIT -> getString(R .string.create_space_dialog_quota_zero_error)
134+ spaceQuota.toDouble() > MAX_SPACE_QUOTA_LIMIT -> getString(R .string.create_space_dialog_quota_too_large_error)
132135 else -> null
133136 }
134137 }
135138
136139 private fun updateUI () {
137140 val nameError = validateName(binding.createSpaceDialogNameValue.text.toString())
138- val quotaError = validateQuota(binding.createSpaceDialogQuotaValue.text.toString())
141+ val quotaValue = convertToBytes(binding.createSpaceDialogQuotaValue.text.toString(), binding.createSpaceDialogQuotaUnitLabel.text.toString())
142+ val quotaError = validateQuota(quotaValue.toString())
139143 val noErrors = nameError == null && quotaError == null
140144
141145 val colorButton = if (noErrors) {
@@ -152,9 +156,18 @@ class CreateSpaceDialogFragment : DialogFragment() {
152156 }
153157 }
154158
155- private fun convertToBytes (spaceQuota : String ): Long {
156- val quotaNumber = spaceQuota.toDoubleOrNull() ? : return 0L
157- return (quotaNumber * 1_000_000_000L ).toLong()
159+ private fun convertToBytes (spaceQuotaValue : String , spaceQuotaUnit : String ): Long {
160+ val quotaNumber = spaceQuotaValue.toDoubleOrNull() ? : return 0L
161+ val multiplier = when (spaceQuotaUnit) {
162+ DisplayUtils .sizeSuffixes[0 ] -> B_MULTIPLIER
163+ DisplayUtils .sizeSuffixes[1 ] -> KB_MULTIPLIER
164+ DisplayUtils .sizeSuffixes[2 ] -> MB_MULTIPLIER
165+ DisplayUtils .sizeSuffixes[3 ] -> GB_MULTIPLIER
166+ DisplayUtils .sizeSuffixes[4 ] -> TB_MULTIPLIER
167+ DisplayUtils .sizeSuffixes[5 ] -> PB_MULTIPLIER
168+ else -> B_MULTIPLIER
169+ }
170+ return (quotaNumber * multiplier).toLong()
158171 }
159172
160173 interface CreateSpaceListener {
@@ -167,8 +180,14 @@ class CreateSpaceDialogFragment : DialogFragment() {
167180 private const val ARG_CAN_EDIT_SPACE_QUOTA = " CAN_EDIT_SPACE_QUOTA"
168181 private const val ARG_CURRENT_SPACE = " CURRENT_SPACE"
169182 private const val FORBIDDEN_CHARACTERS = """ [/\\.:?*"'><|]"""
170- private const val MIN_SPACE_QUOTA_GB = 0.0
171- private const val MAX_SPACE_QUOTA_GB = 1_000_000.0
183+ private const val MIN_SPACE_QUOTA_LIMIT = 0.0
184+ private const val MAX_SPACE_QUOTA_LIMIT = 1_000_000_000_000_000.0
185+ private const val B_MULTIPLIER = 1L
186+ private const val KB_MULTIPLIER = 1_000L
187+ private const val MB_MULTIPLIER = 1_000_000L
188+ private const val GB_MULTIPLIER = 1_000_000_000L
189+ private const val TB_MULTIPLIER = 1_000_000_000_000L
190+ private const val PB_MULTIPLIER = 1_000_000_000_000_000L
172191
173192 fun newInstance (
174193 isEditMode : Boolean ,
0 commit comments