mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add kibibyte and gibibyte #851
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package com.kunzisoft.keepass.utils
|
package com.kunzisoft.keepass.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -9,13 +28,24 @@ class DataByte(var number: Long, var format: ByteFormat) {
|
|||||||
fun toBetterByteFormat(): DataByte {
|
fun toBetterByteFormat(): DataByte {
|
||||||
return when (this.format) {
|
return when (this.format) {
|
||||||
ByteFormat.BYTE -> {
|
ByteFormat.BYTE -> {
|
||||||
if (this.number % MEBIBYTES == 0L) {
|
when {
|
||||||
DataByte((this.number / MEBIBYTES), ByteFormat.MEBIBYTE)
|
this.number % GIBIBYTES == 0L -> {
|
||||||
} else {
|
DataByte((this.number / GIBIBYTES), ByteFormat.GIBIBYTE)
|
||||||
DataByte(this.number, ByteFormat.BYTE)
|
}
|
||||||
|
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 {
|
fun toBytes(): Long {
|
||||||
return when (this.format) {
|
return when (this.format) {
|
||||||
ByteFormat.BYTE -> this.number
|
ByteFormat.BYTE -> this.number
|
||||||
|
ByteFormat.KIBIBYTE -> this.number * KIBIBYTES
|
||||||
ByteFormat.MEBIBYTE -> this.number * MEBIBYTES
|
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) {
|
enum class ByteFormat(@StringRes var stringId: Int) {
|
||||||
BYTE(R.string.unit_byte),
|
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 {
|
companion object {
|
||||||
|
const val KIBIBYTES = 1024L
|
||||||
const val MEBIBYTES = 1048576L
|
const val MEBIBYTES = 1048576L
|
||||||
|
const val GIBIBYTES = 1073741824L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -521,7 +521,9 @@
|
|||||||
<string name="kdf_Argon2d">Argon2d</string>
|
<string name="kdf_Argon2d">Argon2d</string>
|
||||||
<string name="kdf_Argon2id">Argon2id</string>
|
<string name="kdf_Argon2id">Argon2id</string>
|
||||||
<string name="unit_byte">B</string>
|
<string name="unit_byte">B</string>
|
||||||
|
<string name="unit_kibibyte">KiB</string>
|
||||||
<string name="unit_mebibyte">MiB</string>
|
<string name="unit_mebibyte">MiB</string>
|
||||||
|
<string name="unit_gibibyte">GiB</string>
|
||||||
<string-array name="timeout_options">
|
<string-array name="timeout_options">
|
||||||
<item>5 seconds</item>
|
<item>5 seconds</item>
|
||||||
<item>10 seconds</item>
|
<item>10 seconds</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user