From 3b75ca9f3accc3bd5339174418a23420b6cd3b0a Mon Sep 17 00:00:00 2001 From: MakarovSoftware <29123861+MakarovSoftware@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:49:18 +0400 Subject: [PATCH 1/3] Added digital data converter with binary and decimal units --- .../fossify/math/helpers/converters/Base.kt | 3 +- .../math/helpers/converters/DataConverter.kt | 211 ++++++++++++++++++ app/src/main/res/drawable/ic_data_vector.xml | 3 + app/src/main/res/values/donottranslate.xml | 24 ++ app/src/main/res/values/strings.xml | 25 +++ 5 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt create mode 100644 app/src/main/res/drawable/ic_data_vector.xml diff --git a/app/src/main/kotlin/org/fossify/math/helpers/converters/Base.kt b/app/src/main/kotlin/org/fossify/math/helpers/converters/Base.kt index 71d50a0c..63760930 100644 --- a/app/src/main/kotlin/org/fossify/math/helpers/converters/Base.kt +++ b/app/src/main/kotlin/org/fossify/math/helpers/converters/Base.kt @@ -16,7 +16,8 @@ interface Converter { TimeConverter, SpeedConverter, PressureConverter, - EnergyConverter + EnergyConverter, + DataConverter ) } diff --git a/app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt b/app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt new file mode 100644 index 00000000..4077c068 --- /dev/null +++ b/app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt @@ -0,0 +1,211 @@ +package org.fossify.math.helpers.converters + +import org.fossify.math.R +import java.math.BigDecimal + +object DataConverter : Converter { + override val nameResId: Int = R.string.unit_data + override val imageResId: Int = R.drawable.ic_data_vector + override val key: String = "DataConverter" + + private val BITS_IN_BYTE = BigDecimal("8") + private val KILO = BigDecimal("1000") + private val KIBI = BigDecimal("1024") + + sealed class Unit(nameResId: Int, symbolResId: Int, factor: BigDecimal, key: String) : + Converter.Unit(nameResId, symbolResId, factor, key) { + data object Bit : Unit( + nameResId = R.string.unit_data_bit, + symbolResId = R.string.unit_data_bit_symbol, + factor = BigDecimal.ONE, + key = "Bit" + ) + + data object Nibble : Unit( + nameResId = R.string.unit_data_nibble, + symbolResId = R.string.unit_data_nibble_symbol, + factor = BigDecimal("4"), + key = "Nibble" + ) + + data object Byte : Unit( + nameResId = R.string.unit_data_byte, + symbolResId = R.string.unit_data_byte_symbol, + factor = BITS_IN_BYTE, + key = "Byte" + ) + + // Decimal Bits (1000^n) + data object Kilobit : Unit( + nameResId = R.string.unit_data_kilobit, + symbolResId = R.string.unit_data_kilobit_symbol, + factor = KILO, + key = "Kilobit" + ) + + data object Megabit : Unit( + nameResId = R.string.unit_data_megabit, + symbolResId = R.string.unit_data_megabit_symbol, + factor = KILO.pow(2), + key = "Megabit" + ) + + data object Gigabit : Unit( + nameResId = R.string.unit_data_gigabit, + symbolResId = R.string.unit_data_gigabit_symbol, + factor = KILO.pow(3), + key = "Gigabit" + ) + + data object Terabit : Unit( + nameResId = R.string.unit_data_terabit, + symbolResId = R.string.unit_data_terabit_symbol, + factor = KILO.pow(4), + key = "Terabit" + ) + + data object Petabit : Unit( + nameResId = R.string.unit_data_petabit, + symbolResId = R.string.unit_data_petabit_symbol, + factor = KILO.pow(5), + key = "Petabit" + ) + + // Binary Bits (1024^n) + data object Kibibit : Unit( + nameResId = R.string.unit_data_kibibit, + symbolResId = R.string.unit_data_kibibit_symbol, + factor = KIBI, + key = "Kibibit" + ) + + data object Mebibit : Unit( + nameResId = R.string.unit_data_mebibit, + symbolResId = R.string.unit_data_mebibit_symbol, + factor = KIBI.pow(2), + key = "Mebibit" + ) + + data object Gibibit : Unit( + nameResId = R.string.unit_data_gibibit, + symbolResId = R.string.unit_data_gibibit_symbol, + factor = KIBI.pow(3), + key = "Gibibit" + ) + + data object Tebibit : Unit( + nameResId = R.string.unit_data_tebibit, + symbolResId = R.string.unit_data_tebibit_symbol, + factor = KIBI.pow(4), + key = "Tebibit" + ) + + data object Pebibit : Unit( + nameResId = R.string.unit_data_pebibit, + symbolResId = R.string.unit_data_pebibit_symbol, + factor = KIBI.pow(5), + key = "Pebibit" + ) + + // Decimal Bytes (8 * 1000^n) + data object Kilobyte : Unit( + nameResId = R.string.unit_data_kilobyte, + symbolResId = R.string.unit_data_kilobyte_symbol, + factor = BITS_IN_BYTE.multiply(KILO), + key = "Kilobyte" + ) + + data object Megabyte : Unit( + nameResId = R.string.unit_data_megabyte, + symbolResId = R.string.unit_data_megabyte_symbol, + factor = BITS_IN_BYTE.multiply(KILO.pow(2)), + key = "Megabyte" + ) + + data object Gigabyte : Unit( + nameResId = R.string.unit_data_gigabyte, + symbolResId = R.string.unit_data_gigabyte_symbol, + factor = BITS_IN_BYTE.multiply(KILO.pow(3)), + key = "Gigabyte" + ) + + data object Terabyte : Unit( + nameResId = R.string.unit_data_terabyte, + symbolResId = R.string.unit_data_terabyte_symbol, + factor = BITS_IN_BYTE.multiply(KILO.pow(4)), + key = "Terabyte" + ) + + data object Petabyte : Unit( + nameResId = R.string.unit_data_petabyte, + symbolResId = R.string.unit_data_petabyte_symbol, + factor = BITS_IN_BYTE.multiply(KILO.pow(5)), + key = "Petabyte" + ) + + // Binary Bytes (8 * 1024^n) + data object Kibibyte : Unit( + nameResId = R.string.unit_data_kibibyte, + symbolResId = R.string.unit_data_kibibyte_symbol, + factor = BITS_IN_BYTE.multiply(KIBI), + key = "Kibibyte" + ) + + data object Mebibyte : Unit( + nameResId = R.string.unit_data_mebibyte, + symbolResId = R.string.unit_data_mebibyte_symbol, + factor = BITS_IN_BYTE.multiply(KIBI.pow(2)), + key = "Mebibyte" + ) + + data object Gibibyte : Unit( + nameResId = R.string.unit_data_gibibyte, + symbolResId = R.string.unit_data_gibibyte_symbol, + factor = BITS_IN_BYTE.multiply(KIBI.pow(3)), + key = "Gibibyte" + ) + + data object Tebibyte : Unit( + nameResId = R.string.unit_data_tebibyte, + symbolResId = R.string.unit_data_tebibyte_symbol, + factor = BITS_IN_BYTE.multiply(KIBI.pow(4)), + key = "Tebibyte" + ) + + data object Pebibyte : Unit( + nameResId = R.string.unit_data_pebibyte, + symbolResId = R.string.unit_data_pebibyte_symbol, + factor = BITS_IN_BYTE.multiply(KIBI.pow(5)), + key = "Pebibyte" + ) + } + + override val units: List = listOf( + Unit.Bit, + Unit.Nibble, + Unit.Byte, + Unit.Kilobit, + Unit.Kibibit, + Unit.Megabit, + Unit.Mebibit, + Unit.Gigabit, + Unit.Gibibit, + Unit.Terabit, + Unit.Tebibit, + Unit.Petabit, + Unit.Pebibit, + Unit.Kilobyte, + Unit.Kibibyte, + Unit.Megabyte, + Unit.Mebibyte, + Unit.Gigabyte, + Unit.Gibibyte, + Unit.Terabyte, + Unit.Tebibyte, + Unit.Petabyte, + Unit.Pebibyte, + ) + + override val defaultTopUnit: Unit = Unit.Kilobyte + override val defaultBottomUnit: Unit = Unit.Byte +} diff --git a/app/src/main/res/drawable/ic_data_vector.xml b/app/src/main/res/drawable/ic_data_vector.xml new file mode 100644 index 00000000..0095b60a --- /dev/null +++ b/app/src/main/res/drawable/ic_data_vector.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 6d7df6b7..6123a0c7 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -120,4 +120,28 @@ thm ft⋅lbf erg + + b + nib + B + kb + Kib + Mb + Mib + Gb + Gib + Tb + Tib + Pb + Pib + kB + KiB + MB + MiB + GB + GiB + TB + TiB + PB + PiB diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 779a7111..1ff52e22 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -144,6 +144,31 @@ Foot-pound Erg + Data + Bit + Nibble + Byte + Kilobit + Kibibit + Megabit + Mebibit + Gigabit + Gibibit + Terabit + Tebibit + Petabit + Pebibit + Kilobyte + Kibibyte + Megabyte + Mebibyte + Gigabyte + Gibibyte + Terabyte + Tebibyte + Petabyte + Pebibyte + How does the C (Clear) button work? Tapping on it will remove one character at a time. Long pressing it will reset all fields at once. From 859fc7b7e239193c15bbad99a778e488bda2782c Mon Sep 17 00:00:00 2001 From: MakarovSoftware <29123861+MakarovSoftware@users.noreply.github.com> Date: Thu, 19 Mar 2026 19:13:01 +0400 Subject: [PATCH 2/3] CHANGELOG.md updated --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c986d7..78ddce0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Added digital data converter with binary and decimal units ## [1.4.0] - 2026-01-30 ### Added From d3cd2353f5501a7067340cb0145802b28a303edb Mon Sep 17 00:00:00 2001 From: MakarovSoftware <29123861+MakarovSoftware@users.noreply.github.com> Date: Thu, 19 Mar 2026 19:24:07 +0400 Subject: [PATCH 3/3] pr fail fix: moved magic numbers to a constant values. --- .../math/helpers/converters/DataConverter.kt | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt b/app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt index 4077c068..9cc08163 100644 --- a/app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt +++ b/app/src/main/kotlin/org/fossify/math/helpers/converters/DataConverter.kt @@ -12,6 +12,11 @@ object DataConverter : Converter { private val KILO = BigDecimal("1000") private val KIBI = BigDecimal("1024") + private const val EXPONENT_2 = 2 + private const val EXPONENT_3 = 3 + private const val EXPONENT_4 = 4 + private const val EXPONENT_5 = 5 + sealed class Unit(nameResId: Int, symbolResId: Int, factor: BigDecimal, key: String) : Converter.Unit(nameResId, symbolResId, factor, key) { data object Bit : Unit( @@ -46,28 +51,28 @@ object DataConverter : Converter { data object Megabit : Unit( nameResId = R.string.unit_data_megabit, symbolResId = R.string.unit_data_megabit_symbol, - factor = KILO.pow(2), + factor = KILO.pow(EXPONENT_2), key = "Megabit" ) data object Gigabit : Unit( nameResId = R.string.unit_data_gigabit, symbolResId = R.string.unit_data_gigabit_symbol, - factor = KILO.pow(3), + factor = KILO.pow(EXPONENT_3), key = "Gigabit" ) data object Terabit : Unit( nameResId = R.string.unit_data_terabit, symbolResId = R.string.unit_data_terabit_symbol, - factor = KILO.pow(4), + factor = KILO.pow(EXPONENT_4), key = "Terabit" ) data object Petabit : Unit( nameResId = R.string.unit_data_petabit, symbolResId = R.string.unit_data_petabit_symbol, - factor = KILO.pow(5), + factor = KILO.pow(EXPONENT_5), key = "Petabit" ) @@ -82,28 +87,28 @@ object DataConverter : Converter { data object Mebibit : Unit( nameResId = R.string.unit_data_mebibit, symbolResId = R.string.unit_data_mebibit_symbol, - factor = KIBI.pow(2), + factor = KIBI.pow(EXPONENT_2), key = "Mebibit" ) data object Gibibit : Unit( nameResId = R.string.unit_data_gibibit, symbolResId = R.string.unit_data_gibibit_symbol, - factor = KIBI.pow(3), + factor = KIBI.pow(EXPONENT_3), key = "Gibibit" ) data object Tebibit : Unit( nameResId = R.string.unit_data_tebibit, symbolResId = R.string.unit_data_tebibit_symbol, - factor = KIBI.pow(4), + factor = KIBI.pow(EXPONENT_4), key = "Tebibit" ) data object Pebibit : Unit( nameResId = R.string.unit_data_pebibit, symbolResId = R.string.unit_data_pebibit_symbol, - factor = KIBI.pow(5), + factor = KIBI.pow(EXPONENT_5), key = "Pebibit" ) @@ -118,28 +123,28 @@ object DataConverter : Converter { data object Megabyte : Unit( nameResId = R.string.unit_data_megabyte, symbolResId = R.string.unit_data_megabyte_symbol, - factor = BITS_IN_BYTE.multiply(KILO.pow(2)), + factor = BITS_IN_BYTE.multiply(KILO.pow(EXPONENT_2)), key = "Megabyte" ) data object Gigabyte : Unit( nameResId = R.string.unit_data_gigabyte, symbolResId = R.string.unit_data_gigabyte_symbol, - factor = BITS_IN_BYTE.multiply(KILO.pow(3)), + factor = BITS_IN_BYTE.multiply(KILO.pow(EXPONENT_3)), key = "Gigabyte" ) data object Terabyte : Unit( nameResId = R.string.unit_data_terabyte, symbolResId = R.string.unit_data_terabyte_symbol, - factor = BITS_IN_BYTE.multiply(KILO.pow(4)), + factor = BITS_IN_BYTE.multiply(KILO.pow(EXPONENT_4)), key = "Terabyte" ) data object Petabyte : Unit( nameResId = R.string.unit_data_petabyte, symbolResId = R.string.unit_data_petabyte_symbol, - factor = BITS_IN_BYTE.multiply(KILO.pow(5)), + factor = BITS_IN_BYTE.multiply(KILO.pow(EXPONENT_5)), key = "Petabyte" ) @@ -154,28 +159,28 @@ object DataConverter : Converter { data object Mebibyte : Unit( nameResId = R.string.unit_data_mebibyte, symbolResId = R.string.unit_data_mebibyte_symbol, - factor = BITS_IN_BYTE.multiply(KIBI.pow(2)), + factor = BITS_IN_BYTE.multiply(KIBI.pow(EXPONENT_2)), key = "Mebibyte" ) data object Gibibyte : Unit( nameResId = R.string.unit_data_gibibyte, symbolResId = R.string.unit_data_gibibyte_symbol, - factor = BITS_IN_BYTE.multiply(KIBI.pow(3)), + factor = BITS_IN_BYTE.multiply(KIBI.pow(EXPONENT_3)), key = "Gibibyte" ) data object Tebibyte : Unit( nameResId = R.string.unit_data_tebibyte, symbolResId = R.string.unit_data_tebibyte_symbol, - factor = BITS_IN_BYTE.multiply(KIBI.pow(4)), + factor = BITS_IN_BYTE.multiply(KIBI.pow(EXPONENT_4)), key = "Tebibyte" ) data object Pebibyte : Unit( nameResId = R.string.unit_data_pebibyte, symbolResId = R.string.unit_data_pebibyte_symbol, - factor = BITS_IN_BYTE.multiply(KIBI.pow(5)), + factor = BITS_IN_BYTE.multiply(KIBI.pow(EXPONENT_5)), key = "Pebibyte" ) }