diff --git a/app/src/main/java/com/kunzisoft/keepass/utils/DataByte.kt b/app/src/main/java/com/kunzisoft/keepass/utils/DataByte.kt index 309e9505d..5f3f2d008 100644 --- a/app/src/main/java/com/kunzisoft/keepass/utils/DataByte.kt +++ b/app/src/main/java/com/kunzisoft/keepass/utils/DataByte.kt @@ -1,3 +1,22 @@ +/* + * Copyright 2021 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePassDX. + * + * KeePassDX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KeePassDX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePassDX. If not, see . + * + */ package com.kunzisoft.keepass.utils import android.content.Context @@ -9,13 +28,24 @@ class DataByte(var number: Long, var format: ByteFormat) { fun toBetterByteFormat(): DataByte { return when (this.format) { ByteFormat.BYTE -> { - if (this.number % MEBIBYTES == 0L) { - DataByte((this.number / MEBIBYTES), ByteFormat.MEBIBYTE) - } else { - DataByte(this.number, ByteFormat.BYTE) + when { + this.number % GIBIBYTES == 0L -> { + DataByte((this.number / GIBIBYTES), ByteFormat.GIBIBYTE) + } + this.number % MEBIBYTES == 0L -> { + DataByte((this.number / MEBIBYTES), ByteFormat.MEBIBYTE) + } + this.number % KIBIBYTES == 0L -> { + DataByte((this.number / KIBIBYTES), ByteFormat.KIBIBYTE) + } + else -> { + DataByte(this.number, ByteFormat.BYTE) + } } } - ByteFormat.MEBIBYTE -> this + else -> { + DataByte(toBytes(), ByteFormat.BYTE).toBetterByteFormat() + } } } @@ -25,7 +55,9 @@ class DataByte(var number: Long, var format: ByteFormat) { fun toBytes(): Long { return when (this.format) { ByteFormat.BYTE -> this.number + ByteFormat.KIBIBYTE -> this.number * KIBIBYTES ByteFormat.MEBIBYTE -> this.number * MEBIBYTES + ByteFormat.GIBIBYTE -> this.number * GIBIBYTES } } @@ -39,10 +71,14 @@ class DataByte(var number: Long, var format: ByteFormat) { enum class ByteFormat(@StringRes var stringId: Int) { BYTE(R.string.unit_byte), - MEBIBYTE(R.string.unit_mebibyte) + KIBIBYTE(R.string.unit_kibibyte), + MEBIBYTE(R.string.unit_mebibyte), + GIBIBYTE(R.string.unit_gibibyte) } companion object { + const val KIBIBYTES = 1024L const val MEBIBYTES = 1048576L + const val GIBIBYTES = 1073741824L } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b6c27409e..3aaa72ef0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -521,7 +521,9 @@ Argon2d Argon2id B + KiB MiB + GiB 5 seconds 10 seconds