From b6ba9b800ce0b3996ed19a1de832c6149fff0db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 13 Sep 2023 12:16:37 +0200 Subject: [PATCH] Add background behind unit symbols --- .../helpers/converters/AreaConverter.kt | 30 +-- .../calculator/helpers/converters/Base.kt | 6 +- .../helpers/converters/LengthConverter.kt | 52 ++-- .../helpers/converters/MassConverter.kt | 32 +-- .../converters/TemperatureConverter.kt | 22 +- .../helpers/converters/TimeConverter.kt | 48 ++-- .../helpers/converters/VolumeConverter.kt | 64 ++--- .../calculator/views/ConverterView.kt | 81 +++--- app/src/main/res/layout/view_converter.xml | 65 ++++- app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/donottranslate.xml | 232 +++++++++--------- 11 files changed, 335 insertions(+), 298 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/AreaConverter.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/AreaConverter.kt index c056b1eb..7f001109 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/AreaConverter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/AreaConverter.kt @@ -6,88 +6,88 @@ object AreaConverter : Converter { override val nameResId: Int = R.string.unit_area override val imageResId: Int = R.drawable.ic_box_vector - sealed class Unit(nameResId: Int, formatResId: Int, factor: Double) : Converter.Unit(nameResId, formatResId, factor) { + sealed class Unit(nameResId: Int, symbolResId: Int, factor: Double) : Converter.Unit(nameResId, symbolResId, factor) { data object SquareKilometer : Unit( nameResId = R.string.unit_area_square_kilometer, - formatResId = R.string.unit_area_square_kilometer_format, + symbolResId = R.string.unit_area_square_kilometer_symbol, factor = 1000000.0 ) data object SquareMeter : Unit( nameResId = R.string.unit_area_square_meter, - formatResId = R.string.unit_area_square_meter_format, + symbolResId = R.string.unit_area_square_meter_symbol, factor = 1.0 ) data object SquareCentimeter : Unit( nameResId = R.string.unit_area_square_centimeter, - formatResId = R.string.unit_area_square_centimeter_format, + symbolResId = R.string.unit_area_square_centimeter_symbol, factor = 0.0001 ) data object SquareMillimeter : Unit( nameResId = R.string.unit_area_square_millimeter, - formatResId = R.string.unit_area_square_millimeter_format, + symbolResId = R.string.unit_area_square_millimeter_symbol, factor = 0.000001 ) data object SquareMile : Unit( nameResId = R.string.unit_area_square_mile, - formatResId = R.string.unit_area_square_mile_format, + symbolResId = R.string.unit_area_square_mile_symbol, factor = 2_589_988.110336 ) data object SquareYard : Unit( nameResId = R.string.unit_area_square_yard, - formatResId = R.string.unit_area_square_yard_format, + symbolResId = R.string.unit_area_square_yard_symbol, factor = 0.83612736 ) data object SquareFoot : Unit( nameResId = R.string.unit_area_square_foot, - formatResId = R.string.unit_area_square_foot_format, + symbolResId = R.string.unit_area_square_foot_symbol, factor = 0.09290304 ) data object SquareInch : Unit( nameResId = R.string.unit_area_square_inch, - formatResId = R.string.unit_area_square_inch_format, + symbolResId = R.string.unit_area_square_inch_symbol, factor = 0.00064516 ) data object SquareMil : Unit( nameResId = R.string.unit_area_square_mil, - formatResId = R.string.unit_area_square_mil_format, + symbolResId = R.string.unit_area_square_mil_symbol, factor = 0.00000000064516 ) data object SquareRod : Unit( nameResId = R.string.unit_area_square_rod, - formatResId = R.string.unit_area_square_rod_format, + symbolResId = R.string.unit_area_square_rod_symbol, factor = 25.29285264 ) data object Acre : Unit( nameResId = R.string.unit_area_acre, - formatResId = R.string.unit_area_acre_format, + symbolResId = R.string.unit_area_acre_symbol, factor = 4_046.8564224 ) data object Are : Unit( nameResId = R.string.unit_area_are, - formatResId = R.string.unit_area_are_format, + symbolResId = R.string.unit_area_are_symbol, factor = 100.0 ) data object Dunam : Unit( nameResId = R.string.unit_area_dunam, - formatResId = R.string.unit_area_dunam_format, + symbolResId = R.string.unit_area_dunam_symbol, factor = 1000.0 ) data object Hectare : Unit( nameResId = R.string.unit_area_hectare, - formatResId = R.string.unit_area_hectare_format, + symbolResId = R.string.unit_area_hectare_symbol, factor = 10_000.0 ) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/Base.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/Base.kt index c4842285..e53aeef8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/Base.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/Base.kt @@ -27,7 +27,7 @@ interface Converter { open class Unit( val nameResId: Int, - val formatResId: Int, + val symbolResId: Int, val factor: Double ) { @@ -37,12 +37,10 @@ interface Converter { fun withValue(value: Double) = ValueWithUnit(value, this) - fun format(context: Context, value: String) = context.getString(formatResId, value) - fun getNameWithSymbol(context: Context) = context.getString( R.string.unit_name_with_symbol_format, context.getString(nameResId), - format(context, "").trim() + context.getString(symbolResId) ) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/LengthConverter.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/LengthConverter.kt index bd672f5a..c01acb73 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/LengthConverter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/LengthConverter.kt @@ -6,154 +6,154 @@ object LengthConverter : Converter { override val nameResId: Int = R.string.unit_length override val imageResId: Int = R.drawable.ic_height_vector - sealed class Unit(nameResId: Int, formatResId: Int, factor: Double) : Converter.Unit(nameResId, formatResId, factor) { + sealed class Unit(nameResId: Int, symbolResId: Int, factor: Double) : Converter.Unit(nameResId, symbolResId, factor) { data object Kilometer : Unit( nameResId = R.string.unit_length_kilometer, - formatResId = R.string.unit_length_kilometer_format, + symbolResId = R.string.unit_length_kilometer_symbol, factor = 1000.0 ) data object Hectometer : Unit( nameResId = R.string.unit_length_hectometer, - formatResId = R.string.unit_length_hectometer_format, + symbolResId = R.string.unit_length_hectometer_symbol, factor = 100.0 ) data object Decameter : Unit( nameResId = R.string.unit_length_decameter, - formatResId = R.string.unit_length_decameter_format, + symbolResId = R.string.unit_length_decameter_symbol, factor = 10.0 ) data object Meter : Unit( nameResId = R.string.unit_length_meter, - formatResId = R.string.unit_length_meter_format, + symbolResId = R.string.unit_length_meter_symbol, factor = 1.0 ) data object Decimeter : Unit( nameResId = R.string.unit_length_decimeter, - formatResId = R.string.unit_length_decimeter_format, + symbolResId = R.string.unit_length_decimeter_symbol, factor = 0.1 ) data object Centimeter : Unit( nameResId = R.string.unit_length_centimeter, - formatResId = R.string.unit_length_centimeter_format, + symbolResId = R.string.unit_length_centimeter_symbol, factor = 0.01 ) data object Millimeter : Unit( nameResId = R.string.unit_length_millimeter, - formatResId = R.string.unit_length_millimeter_format, + symbolResId = R.string.unit_length_millimeter_symbol, factor = 0.001 ) data object Micrometer : Unit( nameResId = R.string.unit_length_micrometer, - formatResId = R.string.unit_length_micrometer_format, + symbolResId = R.string.unit_length_micrometer_symbol, factor = 0.000001 ) data object Nanometer : Unit( nameResId = R.string.unit_length_nanometer, - formatResId = R.string.unit_length_nanometer_format, + symbolResId = R.string.unit_length_nanometer_symbol, factor = 0.000000001 ) data object Picometer : Unit( nameResId = R.string.unit_length_picometer, - formatResId = R.string.unit_length_picometer_format, + symbolResId = R.string.unit_length_picometer_symbol, factor = 0.000000000001 ) data object Angstrom : Unit( nameResId = R.string.unit_length_angstrom, - formatResId = R.string.unit_length_angstrom_format, + symbolResId = R.string.unit_length_angstrom_symbol, factor = 1e-10 ) data object Mile : Unit( nameResId = R.string.unit_length_mile, - formatResId = R.string.unit_length_mile_format, + symbolResId = R.string.unit_length_mile_symbol, factor = 1_609.344 ) data object Chain : Unit( nameResId = R.string.unit_length_chain, - formatResId = R.string.unit_length_chain_format, + symbolResId = R.string.unit_length_chain_symbol, factor = 20.1168 ) data object Yard : Unit( nameResId = R.string.unit_length_yard, - formatResId = R.string.unit_length_yard_format, + symbolResId = R.string.unit_length_yard_symbol, factor = 0.9144 ) data object Foot : Unit( nameResId = R.string.unit_length_foot, - formatResId = R.string.unit_length_foot_format, + symbolResId = R.string.unit_length_foot_symbol, factor = 0.3048 ) data object Mil : Unit( nameResId = R.string.unit_length_mil, - formatResId = R.string.unit_length_mil_format, + symbolResId = R.string.unit_length_mil_symbol, factor = 0.0000254 ) data object Inch : Unit( nameResId = R.string.unit_length_inch, - formatResId = R.string.unit_length_inch_format, + symbolResId = R.string.unit_length_inch_symbol, factor = 0.0254 ) data object Fathom : Unit( nameResId = R.string.unit_length_fathom, - formatResId = R.string.unit_length_fathom_format, + symbolResId = R.string.unit_length_fathom_symbol, factor = 1.852 ) data object Cable : Unit( nameResId = R.string.unit_length_cable, - formatResId = R.string.unit_length_cable_format, + symbolResId = R.string.unit_length_cable_symbol, factor = 185.2 ) data object NauticalMile : Unit( nameResId = R.string.unit_length_nautical_mile, - formatResId = R.string.unit_length_nautical_mile_format, + symbolResId = R.string.unit_length_nautical_mile_symbol, factor = 1_852.0 ) data object Link : Unit( nameResId = R.string.unit_length_link, - formatResId = R.string.unit_length_link_format, + symbolResId = R.string.unit_length_link_symbol, factor = 0.201168 ) data object Rod : Unit( nameResId = R.string.unit_length_rod, - formatResId = R.string.unit_length_rod_format, + symbolResId = R.string.unit_length_rod_symbol, factor = 5.0292 ) data object AstronomicalUnit : Unit( nameResId = R.string.unit_length_astronomical_unit, - formatResId = R.string.unit_length_astronomical_unit_format, + symbolResId = R.string.unit_length_astronomical_unit_symbol, factor = 1.495979e+11 ) data object Parsec : Unit( nameResId = R.string.unit_length_parsec, - formatResId = R.string.unit_length_parsec_format, + symbolResId = R.string.unit_length_parsec_symbol, factor = 3.0857e+16 ) data object LightYear : Unit( nameResId = R.string.unit_length_light_year, - formatResId = R.string.unit_length_light_year_format, + symbolResId = R.string.unit_length_light_year_symbol, factor = 9.4607e+15 ) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/MassConverter.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/MassConverter.kt index 643a7879..c12c8074 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/MassConverter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/MassConverter.kt @@ -6,88 +6,88 @@ object MassConverter : Converter { override val nameResId: Int = R.string.unit_mass override val imageResId: Int = R.drawable.ic_scale_vector - sealed class Unit(nameResId: Int, formatResId: Int, factor: Double) : Converter.Unit(nameResId, formatResId, factor) { + sealed class Unit(nameResId: Int, symbolResId: Int, factor: Double) : Converter.Unit(nameResId, symbolResId, factor) { data object Gram : Unit( nameResId = R.string.unit_mass_gram, - formatResId = R.string.unit_mass_gram_format, + symbolResId = R.string.unit_mass_gram_symbol, factor = 0.001 ) data object Kilogram : Unit( nameResId = R.string.unit_mass_kilogram, - formatResId = R.string.unit_mass_kilogram_format, + symbolResId = R.string.unit_mass_kilogram_symbol, factor = 1.0 ) data object Milligram : Unit( nameResId = R.string.unit_mass_milligram, - formatResId = R.string.unit_mass_milligram_format, + symbolResId = R.string.unit_mass_milligram_symbol, factor = 0.000001 ) data object Microgram : Unit( nameResId = R.string.unit_mass_microgram, - formatResId = R.string.unit_mass_microgram_format, + symbolResId = R.string.unit_mass_microgram_symbol, factor = 0.000000001 ) data object Tonne : Unit( nameResId = R.string.unit_mass_tonne, - formatResId = R.string.unit_mass_tonne_format, + symbolResId = R.string.unit_mass_tonne_symbol, factor = 1_000.0 ) data object Pound : Unit( nameResId = R.string.unit_mass_pound, - formatResId = R.string.unit_mass_pound_format, - factor = 0.45359237 + symbolResId = R.string.unit_mass_pound_symbol, + factor = 0.45359237 ) data object Ounce : Unit( nameResId = R.string.unit_mass_ounce, - formatResId = R.string.unit_mass_ounce_format, + symbolResId = R.string.unit_mass_ounce_symbol, factor = 0.028349523125 ) data object Grain : Unit( nameResId = R.string.unit_mass_grain, - formatResId = R.string.unit_mass_grain_format, + symbolResId = R.string.unit_mass_grain_symbol, factor = 0.00006479891 ) data object Dram : Unit( nameResId = R.string.unit_mass_dram, - formatResId = R.string.unit_mass_dram_format, + symbolResId = R.string.unit_mass_dram_symbol, factor = 0.0017718451953125 ) data object Stone : Unit( nameResId = R.string.unit_mass_stone, - formatResId = R.string.unit_mass_stone_format, + symbolResId = R.string.unit_mass_stone_symbol, factor = 6.35029318 ) data object LongTon : Unit( nameResId = R.string.unit_mass_long_ton, - formatResId = R.string.unit_mass_long_ton_format, + symbolResId = R.string.unit_mass_long_ton_symbol, factor = 1_016.0469088 ) data object ShortTon : Unit( nameResId = R.string.unit_mass_short_ton, - formatResId = R.string.unit_mass_short_ton_format, + symbolResId = R.string.unit_mass_short_ton_symbol, factor = 907.18474 ) data object Carat : Unit( nameResId = R.string.unit_mass_carat, - formatResId = R.string.unit_mass_carat_format, + symbolResId = R.string.unit_mass_carat_symbol, factor = 0.0002051965483 ) data object CaratMetric : Unit( nameResId = R.string.unit_mass_carat_metric, - formatResId = R.string.unit_mass_carat_metric_format, + symbolResId = R.string.unit_mass_carat_metric_symbol, factor = 0.0002 ) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TemperatureConverter.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TemperatureConverter.kt index 34afea20..edbcf022 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TemperatureConverter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TemperatureConverter.kt @@ -6,11 +6,11 @@ object TemperatureConverter : Converter { override val nameResId: Int = R.string.unit_temperature override val imageResId: Int = R.drawable.ic_thermostat_vector - sealed class Unit(nameResId: Int, formatResId: Int, factor: Double) : Converter.Unit(nameResId, formatResId, factor) { + sealed class Unit(nameResId: Int, symbolResId: Int, factor: Double) : Converter.Unit(nameResId, symbolResId, factor) { data object Celsius : Unit( nameResId = R.string.unit_temperature_celsius, - formatResId = R.string.unit_temperature_celsius_format, + symbolResId = R.string.unit_temperature_celsius_symbol, factor = 1.0 ) { const val KELVIN_OFFSET = 273.15 @@ -21,7 +21,7 @@ object TemperatureConverter : Converter { data object Delisle : Unit( nameResId = R.string.unit_temperature_delisle, - formatResId = R.string.unit_temperature_delisle_format, + symbolResId = R.string.unit_temperature_delisle_symbol, factor = 2.0 / 3 ) { private const val KELVIN_OFFSET = 373.15 @@ -33,7 +33,7 @@ object TemperatureConverter : Converter { data object Fahrenheit : Unit( nameResId = R.string.unit_temperature_fahrenheit, - formatResId = R.string.unit_temperature_fahrenheit_format, + symbolResId = R.string.unit_temperature_fahrenheit_symbol, factor = 9.0 / 5 ) { private const val CELSIUS_OFFSET = 32 @@ -45,7 +45,7 @@ object TemperatureConverter : Converter { data object Newton : Unit( nameResId = R.string.unit_temperature_newton, - formatResId = R.string.unit_temperature_newton_format, + symbolResId = R.string.unit_temperature_newton_symbol, factor = 100.0 / 33 ) { private const val KELVIN_OFFSET = Celsius.KELVIN_OFFSET @@ -57,14 +57,14 @@ object TemperatureConverter : Converter { data object Rankine : Unit( nameResId = R.string.unit_temperature_rankine, - formatResId = R.string.unit_temperature_rankine_format, + symbolResId = R.string.unit_temperature_rankine_symbol, factor = 5.0 / 9 ) data object Reaumur : Unit( nameResId = R.string.unit_temperature_reaumur, - formatResId = R.string.unit_temperature_reaumur_format, - factor = 5.0 / 4 + symbolResId = R.string.unit_temperature_reaumur_symbol, + factor = 5.0 / 4 ) { private const val KELVIN_OFFSET = Celsius.KELVIN_OFFSET @@ -75,7 +75,7 @@ object TemperatureConverter : Converter { data object Romer : Unit( nameResId = R.string.unit_temperature_romer, - formatResId = R.string.unit_temperature_romer_format, + symbolResId = R.string.unit_temperature_romer_symbol, factor = 40.0 / 21 ) { private const val KELVIN_OFFSET = Celsius.KELVIN_OFFSET @@ -88,7 +88,7 @@ object TemperatureConverter : Converter { data object GasMark : Unit( nameResId = R.string.unit_temperature_gas_mark, - formatResId = R.string.unit_temperature_gas_mark_format, + symbolResId = R.string.unit_temperature_gas_mark_symbol, factor = 25.0 ) { private const val FAHRENHEIT_OFFSET = 250 @@ -100,7 +100,7 @@ object TemperatureConverter : Converter { data object Kelvin : Unit( nameResId = R.string.unit_temperature_kelvin, - formatResId = R.string.unit_temperature_kelvin_format, + symbolResId = R.string.unit_temperature_kelvin_symbol, factor = 1.0 ) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TimeConverter.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TimeConverter.kt index 93eb87d1..fd240bad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TimeConverter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/TimeConverter.kt @@ -6,7 +6,7 @@ object TimeConverter : Converter { override val nameResId: Int = R.string.unit_time override val imageResId: Int = com.simplemobiletools.commons.R.drawable.ic_clock_vector - sealed class Unit(nameResId: Int, formatResId: Int, factor: Double) : Converter.Unit(nameResId, formatResId, factor) { + sealed class Unit(nameResId: Int, symbolResId: Int, factor: Double) : Converter.Unit(nameResId, symbolResId, factor) { companion object { private const val MINUTE = 60.0 private const val HOUR = 60.0 * MINUTE @@ -16,139 +16,139 @@ object TimeConverter : Converter { data object Hour : Unit( nameResId = R.string.unit_time_hour, - formatResId = R.string.unit_time_hour_format, + symbolResId = R.string.unit_time_hour_symbol, factor = HOUR ) data object Minute : Unit( nameResId = R.string.unit_time_minute, - formatResId = R.string.unit_time_minute_format, + symbolResId = R.string.unit_time_minute_symbol, factor = MINUTE ) data object Second : Unit( nameResId = R.string.unit_time_second, - formatResId = R.string.unit_time_second_format, + symbolResId = R.string.unit_time_second_symbol, factor = 1.0 ) data object Millisecond : Unit( nameResId = R.string.unit_time_millisecond, - formatResId = R.string.unit_time_millisecond_format, + symbolResId = R.string.unit_time_millisecond_symbol, factor = 0.001 ) data object Microsecond : Unit( nameResId = R.string.unit_time_microsecond, - formatResId = R.string.unit_time_microsecond_format, + symbolResId = R.string.unit_time_microsecond_symbol, factor = 0.000001 ) data object Nanosecond : Unit( nameResId = R.string.unit_time_nanosecond, - formatResId = R.string.unit_time_nanosecond_format, + symbolResId = R.string.unit_time_nanosecond_symbol, factor = 0.000000001 ) data object Picosecond : Unit( nameResId = R.string.unit_time_picosecond, - formatResId = R.string.unit_time_picosecond_format, + symbolResId = R.string.unit_time_picosecond_symbol, factor = 0.000000000001 ) data object Day : Unit( nameResId = R.string.unit_time_day, - formatResId = R.string.unit_time_day_format, + symbolResId = R.string.unit_time_day_symbol, factor = DAY ) data object Week : Unit( nameResId = R.string.unit_time_week, - formatResId = R.string.unit_time_week_format, + symbolResId = R.string.unit_time_week_symbol, factor = DAY * 7 ) data object MonthFull : Unit( nameResId = R.string.unit_time_month_full, - formatResId = R.string.unit_time_month_full_format, + symbolResId = R.string.unit_time_month_full_symbol, factor = DAY * 30 ) data object MonthHollow : Unit( nameResId = R.string.unit_time_month_hollow, - formatResId = R.string.unit_time_month_hollow_format, + symbolResId = R.string.unit_time_month_hollow_symbol, factor = DAY * 29 ) data object MonthSynodic : Unit( nameResId = R.string.unit_time_month_synodic, - formatResId = R.string.unit_time_month_synodic_format, + symbolResId = R.string.unit_time_month_synodic_symbol, factor = DAY * 29.530589 ) data object MonthGregorianAverage : Unit( nameResId = R.string.unit_time_month_gregorian_average, - formatResId = R.string.unit_time_month_gregorian_average_format, + symbolResId = R.string.unit_time_month_gregorian_average_symbol, factor = DAY * 30.346875 ) data object YearLeap : Unit( nameResId = R.string.unit_time_year_leap, - formatResId = R.string.unit_time_year_leap_format, + symbolResId = R.string.unit_time_year_leap_symbol, factor = DAY * 366 ) data object YearGregorian : Unit( nameResId = R.string.unit_time_year_gregorian, - formatResId = R.string.unit_time_year_gregorian_format, + symbolResId = R.string.unit_time_year_gregorian_symbol, factor = GREGORIAN_YEAR ) data object YearJulian : Unit( nameResId = R.string.unit_time_year_julian, - formatResId = R.string.unit_time_year_julian_format, + symbolResId = R.string.unit_time_year_julian_symbol, factor = DAY * 365.25 ) data object Jiffy : Unit( nameResId = R.string.unit_time_jiffy, - formatResId = R.string.unit_time_jiffy_format, + symbolResId = R.string.unit_time_jiffy_symbol, factor = 1 / 60.0 ) data object Moment : Unit( nameResId = R.string.unit_time_moment, - formatResId = R.string.unit_time_moment_format, + symbolResId = R.string.unit_time_moment_symbol, factor = 90.0 ) data object Fortnight : Unit( nameResId = R.string.unit_time_fortnight, - formatResId = R.string.unit_time_fortnight_format, + symbolResId = R.string.unit_time_fortnight_symbol, factor = DAY * 7 * 2 ) data object Decade : Unit( nameResId = R.string.unit_time_decade, - formatResId = R.string.unit_time_decade_format, + symbolResId = R.string.unit_time_decade_symbol, factor = GREGORIAN_YEAR * 10 ) data object Century : Unit( nameResId = R.string.unit_time_century, - formatResId = R.string.unit_time_century_format, + symbolResId = R.string.unit_time_century_symbol, factor = GREGORIAN_YEAR * 100 ) data object Millennium : Unit( nameResId = R.string.unit_time_millennium, - formatResId = R.string.unit_time_millennium_format, + symbolResId = R.string.unit_time_millennium_symbol, factor = GREGORIAN_YEAR * 1000 ) data object AtomicUnit : Unit( nameResId = R.string.unit_time_atomic_unit, - formatResId = R.string.unit_time_atomic_unit_format, + symbolResId = R.string.unit_time_atomic_unit_symbol, factor = 0.00000000000000002418884254 ) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/VolumeConverter.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/VolumeConverter.kt index d50f183a..b7244ca3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/VolumeConverter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/converters/VolumeConverter.kt @@ -6,190 +6,190 @@ object VolumeConverter : Converter { override val nameResId: Int = R.string.unit_volume override val imageResId: Int = R.drawable.ic_drop_vector - sealed class Unit(nameResId: Int, formatResId: Int, factor: Double) : Converter.Unit(nameResId, formatResId, factor) { + sealed class Unit(nameResId: Int, symbolResId: Int, factor: Double) : Converter.Unit(nameResId, symbolResId, factor) { data object CubicMeter : Unit( nameResId = R.string.unit_volume_cubic_meter, - formatResId = R.string.unit_volume_cubic_meter_format, + symbolResId = R.string.unit_volume_cubic_meter_symbol, factor = 1.0 ) data object CubicDecimeter : Unit( nameResId = R.string.unit_volume_cubic_decimeter, - formatResId = R.string.unit_volume_cubic_decimeter_format, + symbolResId = R.string.unit_volume_cubic_decimeter_symbol, factor = 0.001 ) data object CubicCentimeter : Unit( nameResId = R.string.unit_volume_cubic_centimeter, - formatResId = R.string.unit_volume_cubic_centimeter_format, + symbolResId = R.string.unit_volume_cubic_centimeter_symbol, factor = 0.000001 ) data object CubicMillimeter : Unit( nameResId = R.string.unit_volume_cubic_millimeter, - formatResId = R.string.unit_volume_cubic_millimeter_format, + symbolResId = R.string.unit_volume_cubic_millimeter_symbol, factor = 0.000000001 ) data object Liter : Unit( nameResId = R.string.unit_volume_liter, - formatResId = R.string.unit_volume_liter_format, + symbolResId = R.string.unit_volume_liter_symbol, factor = 0.001 ) data object Centiliter : Unit( nameResId = R.string.unit_volume_centiliter, - formatResId = R.string.unit_volume_centiliter_format, + symbolResId = R.string.unit_volume_centiliter_symbol, factor = 0.0001 ) data object Deciliter : Unit( nameResId = R.string.unit_volume_deciliter, - formatResId = R.string.unit_volume_deciliter_format, + symbolResId = R.string.unit_volume_deciliter_symbol, factor = 0.00001 ) data object Milliliter : Unit( nameResId = R.string.unit_volume_milliliter, - formatResId = R.string.unit_volume_milliliter_format, + symbolResId = R.string.unit_volume_milliliter_symbol, factor = 0.000001 ) data object AcreFoot : Unit( nameResId = R.string.unit_volume_acre_foot, - formatResId = R.string.unit_volume_acre_foot_format, + symbolResId = R.string.unit_volume_acre_foot_symbol, factor = 1_233.48183754752 ) data object CubicYard : Unit( nameResId = R.string.unit_volume_cubic_yard, - formatResId = R.string.unit_volume_cubic_yard_format, + symbolResId = R.string.unit_volume_cubic_yard_symbol, factor = 0.764554857984 ) data object CubicFoot : Unit( nameResId = R.string.unit_volume_cubic_foot, - formatResId = R.string.unit_volume_cubic_foot_format, + symbolResId = R.string.unit_volume_cubic_foot_symbol, factor = 0.028316846592 ) data object CubicInch : Unit( nameResId = R.string.unit_volume_cubic_inch, - formatResId = R.string.unit_volume_cubic_inch_format, + symbolResId = R.string.unit_volume_cubic_inch_symbol, factor = 0.000016387064 ) data object BarrelUS : Unit( nameResId = R.string.unit_volume_barrel_us, - formatResId = R.string.unit_volume_barrel_us_format, + symbolResId = R.string.unit_volume_barrel_us_symbol, factor = 0.119240471196 ) data object GallonUS : Unit( nameResId = R.string.unit_volume_gallon_us, - formatResId = R.string.unit_volume_gallon_us_format, + symbolResId = R.string.unit_volume_gallon_us_symbol, factor = 0.003785411784 ) data object QuartUS : Unit( nameResId = R.string.unit_volume_quart_us, - formatResId = R.string.unit_volume_quart_us_format, + symbolResId = R.string.unit_volume_quart_us_symbol, factor = 0.000946352946 ) data object PintUS : Unit( nameResId = R.string.unit_volume_pint_us, - formatResId = R.string.unit_volume_pint_us_format, + symbolResId = R.string.unit_volume_pint_us_symbol, factor = 0.000473176473 ) data object GillUS : Unit( nameResId = R.string.unit_volume_gill_us, - formatResId = R.string.unit_volume_gill_us_format, + symbolResId = R.string.unit_volume_gill_us_symbol, factor = 0.00011829411825 ) data object FluidOunceUS : Unit( nameResId = R.string.unit_volume_fluid_ounce_us, - formatResId = R.string.unit_volume_fluid_ounce_us_format, + symbolResId = R.string.unit_volume_fluid_ounce_us_symbol, factor = 0.00003 ) data object DropUS : Unit( nameResId = R.string.unit_volume_drop_us, - formatResId = R.string.unit_volume_drop_us_format, + symbolResId = R.string.unit_volume_drop_us_symbol, factor = 0.00000008214869322916 ) data object TeaspoonUS : Unit( nameResId = R.string.unit_volume_teaspoon_us, - formatResId = R.string.unit_volume_teaspoon_us_format, + symbolResId = R.string.unit_volume_teaspoon_us_symbol, factor = 0.000005 ) data object TablespoonUS : Unit( nameResId = R.string.unit_volume_tablespoon_us, - formatResId = R.string.unit_volume_tablespoon_us_format, + symbolResId = R.string.unit_volume_tablespoon_us_symbol, factor = 0.000015 ) data object CupUS : Unit( nameResId = R.string.unit_volume_cup_us, - formatResId = R.string.unit_volume_cup_us_format, + symbolResId = R.string.unit_volume_cup_us_symbol, factor = 0.00024 ) data object BarrelImperial : Unit( nameResId = R.string.unit_volume_barrel_imperial, - formatResId = R.string.unit_volume_barrel_imperial_format, + symbolResId = R.string.unit_volume_barrel_imperial_symbol, factor = 0.16365924 ) data object GallonImperial : Unit( nameResId = R.string.unit_volume_gallon_imperial, - formatResId = R.string.unit_volume_gallon_imperial_format, + symbolResId = R.string.unit_volume_gallon_imperial_symbol, factor = 0.00454609 ) data object QuartImperial : Unit( nameResId = R.string.unit_volume_quart_imperial, - formatResId = R.string.unit_volume_quart_imperial_format, + symbolResId = R.string.unit_volume_quart_imperial_symbol, factor = 0.0011365225 ) data object PintImperial : Unit( nameResId = R.string.unit_volume_pint_imperial, - formatResId = R.string.unit_volume_pint_imperial_format, + symbolResId = R.string.unit_volume_pint_imperial_symbol, factor = 0.00056826125 ) data object GillImperial : Unit( nameResId = R.string.unit_volume_gill_imperial, - formatResId = R.string.unit_volume_gill_imperial_format, + symbolResId = R.string.unit_volume_gill_imperial_symbol, factor = 0.0001420653125 ) data object FluidOunceImperial : Unit( nameResId = R.string.unit_volume_fluid_ounce_imperial, - formatResId = R.string.unit_volume_fluid_ounce_imperial_format, + symbolResId = R.string.unit_volume_fluid_ounce_imperial_symbol, factor = 0.0000284130625 ) data object DropImperial : Unit( nameResId = R.string.unit_volume_drop_imperial, - formatResId = R.string.unit_volume_drop_imperial_format, + symbolResId = R.string.unit_volume_drop_imperial_symbol, factor = 0.0000000986564670138 ) data object TeaspoonImperial : Unit( nameResId = R.string.unit_volume_teaspoon_imperial, - formatResId = R.string.unit_volume_teaspoon_imperial_format, + symbolResId = R.string.unit_volume_teaspoon_imperial_symbol, factor = 0.00000591938802083 ) data object TablespoonImperial : Unit( nameResId = R.string.unit_volume_tablespoon_imperial, - formatResId = R.string.unit_volume_tablespoon_imperial_format, + symbolResId = R.string.unit_volume_tablespoon_imperial_symbol, factor = 0.0000177581640625 ) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt index 641878f2..60936ac6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt @@ -7,6 +7,7 @@ import android.util.AttributeSet import android.view.View import android.widget.LinearLayout import android.widget.TextView +import androidx.core.content.res.ResourcesCompat import androidx.core.widget.TextViewCompat import com.simplemobiletools.calculator.R import com.simplemobiletools.calculator.databinding.ViewConverterBinding @@ -14,9 +15,9 @@ import com.simplemobiletools.calculator.helpers.COMMA import com.simplemobiletools.calculator.helpers.DOT import com.simplemobiletools.calculator.helpers.NumberFormatHelper import com.simplemobiletools.calculator.helpers.converters.Converter -import com.simplemobiletools.calculator.helpers.converters.ValueWithUnit import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA_INT import com.simplemobiletools.commons.models.RadioItem import me.grantland.widget.AutofitHelper import kotlin.reflect.KMutableProperty0 @@ -43,6 +44,8 @@ class ConverterView @JvmOverloads constructor( AutofitHelper.create(binding.topUnitText) AutofitHelper.create(binding.bottomUnitText) + AutofitHelper.create(binding.topUnitSymbol) + AutofitHelper.create(binding.bottomUnitSymbol) binding.swapButton.setOnClickListener { switch() } @@ -57,32 +60,34 @@ class ConverterView @JvmOverloads constructor( topUnit = converter.defaultTopUnit bottomUnit = converter.defaultBottomUnit - binding.topUnitText.setFormattedUnitText(topUnit!!.withValue(0.0)) + binding.topUnitText.text = "0" updateBottomValue() - updateUnitLabels() + updateUnitLabelsAndSymbols() } fun updateColors() { - binding.topUnitText.setTextColor(context.getProperTextColor()) - binding.bottomUnitText.setTextColor(context.getProperTextColor()) - binding.topUnitName.setTextColor(context.getProperTextColor()) - binding.bottomUnitName.setTextColor(context.getProperTextColor()) - TextViewCompat.setCompoundDrawableTintList( - binding.topUnitName, - ColorStateList.valueOf(context.getProperPrimaryColor()) - ) - TextViewCompat.setCompoundDrawableTintList( - binding.bottomUnitName, - ColorStateList.valueOf(context.getProperPrimaryColor()) - ) - binding.topUnitHolder.setBackgroundColor(context.getProperBackgroundColor().lightenColor()) + listOf(binding.topUnitText, binding.bottomUnitText, binding.topUnitName, binding.bottomUnitName).forEach { + it.setTextColor(context.getProperTextColor()) + } + listOf(binding.topUnitName, binding.bottomUnitName).forEach { + TextViewCompat.setCompoundDrawableTintList( + it, + ColorStateList.valueOf(context.getProperPrimaryColor()) + ) + } + binding.topUnitHolder.setBackgroundColor(context.getProperBackgroundColor().lightenColor()) binding.swapButton.applyColorFilter(context.getProperPrimaryColor()) + + listOf(binding.topUnitSymbol, binding.bottomUnitSymbol).forEach { + it.background = ResourcesCompat.getDrawable(resources, com.simplemobiletools.commons.R.drawable.pill_background, context.theme) + it.background?.alpha = MEDIUM_ALPHA_INT + } } fun clear() { - binding.topUnitText.setFormattedUnitText(topUnit!!.withValue(0.0)) - binding.bottomUnitText.setFormattedUnitText(bottomUnit!!.withValue(0.0)) + binding.topUnitText.text = "0" + binding.bottomUnitText.text = "0" } fun numpadClicked(id: Int) { @@ -104,7 +109,7 @@ class ConverterView @JvmOverloads constructor( } private fun decimalClicked() { - var value = binding.topUnitText.text.removeUnit() + var value = binding.topUnitText.text.toString() if (!value.contains(decimalSeparator)) { when (value) { "0" -> value = "0$decimalSeparator" @@ -112,48 +117,45 @@ class ConverterView @JvmOverloads constructor( else -> value += decimalSeparator } - binding.topUnitText.text = topUnit?.format(context, value) + binding.topUnitText.text = value } } private fun zeroClicked() { - val value = binding.topUnitText.text.removeUnit() + val value = binding.topUnitText.text if (value != "0" || value.contains(decimalSeparator)) { addDigit(0) } } private fun addDigit(digit: Int) { - var value = binding.topUnitText.text.removeUnit() + var value = binding.topUnitText.text.toString() if (value == "0") { value = "" } value += digit value = formatter.addGroupingSeparators(value) - binding.topUnitText.text = topUnit!!.format(context, value) + binding.topUnitText.text = value } private fun switch() { ::topUnit.swapWith(::bottomUnit) - updateTopValue() updateBottomValue() - updateUnitLabels() + updateUnitLabelsAndSymbols() } - private fun updateUnitLabels() { + private fun updateUnitLabelsAndSymbols() { binding.topUnitName.text = topUnit?.nameResId?.let { context.getString(it) } binding.bottomUnitName.text = bottomUnit?.nameResId?.let { context.getString(it) } - } - - private fun updateTopValue() { - binding.topUnitText.setFormattedUnitText(topUnit!!.withValue(binding.topUnitText.getValue())) + binding.topUnitSymbol.text = topUnit?.symbolResId?.let { context.getString(it) } + binding.bottomUnitSymbol.text = bottomUnit?.symbolResId?.let { context.getString(it) } } private fun updateBottomValue() { converter?.apply { - val converted = convert(topUnit!!.withValue(binding.topUnitText.getValue()), bottomUnit!!).value - binding.bottomUnitText.setFormattedUnitText(bottomUnit!!.withValue(converted)) + val converted = convert(topUnit!!.withValue(formatter.removeGroupingSeparator(binding.topUnitText.text.toString()).toDouble()), bottomUnit!!).value + binding.bottomUnitText.text = formatter.doubleToString(converted) } } @@ -163,21 +165,15 @@ class ConverterView @JvmOverloads constructor( this.groupingSeparator = groupingSeparator formatter.decimalSeparator = decimalSeparator formatter.groupingSeparator = groupingSeparator - binding.topUnitText.setFormattedUnitText(topUnit!!.withValue(0.0)) - binding.bottomUnitText.setFormattedUnitText(bottomUnit!!.withValue(0.0)) + binding.topUnitText.text = "0" + binding.bottomUnitText.text = "0" } } - private fun TextView.setFormattedUnitText(value: ValueWithUnit<*>) { - text = value.unit.format(context, formatter.doubleToString(value.value)) - } - private fun TextView.getValue(): Double { - return formatter.removeGroupingSeparator(text.removeUnit()).toDouble() + return formatter.removeGroupingSeparator(text.toString()).toDouble() } - private fun CharSequence.removeUnit() = filter { it.isDigit() || it == '.' || it == ',' }.toString() - private fun KMutableProperty0.swapWith(other: KMutableProperty0) { this.get().also { this.set(other.get()) @@ -196,10 +192,9 @@ class ConverterView @JvmOverloads constructor( switch() } else if (unit != propertyToChange.get()) { propertyToChange.set(unit) - updateTopValue() updateBottomValue() } - updateUnitLabels() + updateUnitLabelsAndSymbols() } } } diff --git a/app/src/main/res/layout/view_converter.xml b/app/src/main/res/layout/view_converter.xml index 7bb6d803..aef41d66 100644 --- a/app/src/main/res/layout/view_converter.xml +++ b/app/src/main/res/layout/view_converter.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - + - + + + + - + - + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index d903b3d3..01422473 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -10,4 +10,5 @@ 40sp 128dp + 64dp diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 636e4d37..0ad011c6 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -3,122 +3,122 @@ com.simplemobiletools.calculator %s (%s) - %s km - %s hm - %s dam - %s m - %s dm - %s cm - %s mm - %s μm - %s nm - %s pm - %s Å - %s mi - %s ch - %s yd - %s ft - %s mil - %s in - %s fathom - %s cable - %s NM - %s lnk - %s rd - %s au - %s pc - %s ly - %s km² - %s m² - %s cm² - %s mm² - %s sq mi - %s sq yd - %s sq ft - %s sq mil - %s sq in - %s sq rd - %s ac - %s a - %s dunam - %s ha - %s m³ - %s dm³ - %s cm³ - %s mm³ - %s l - %s cl - %s dl - %s ml - %s ac ft - %s yd³ - %s ft³ - %s in³ - %s fl bl (US) - %s gal (US) - %s qt (US) - %s pt (US fl) - %s gi (US) - %s US fl oz - %s gtt - %s tsp - %s tbsp - %s c (US) - %s bl (imp) - %s gal (imp) - %s qt (imp) - %s pt (imp) - %s gi (imp) - %s fl oz (imp) - %s gtt - %s tsp - %s tbsp - %s g - %s kg - %s mg - %s μm - %s t - %s lb - %s oz - %s gr - %s dr - %s st - %s ton - %s sh tn - %s kt - %s ct - %s°C - %s°De - %s°F - %s°N - %s°R - %s°Ré - %s°Rø - %s GM - %s K - %s h - %s m - %s s - %s ms - %s µs - %s ns - %s ps - %s d - %s wk - %s mo - %s mo - %s mo - %s mo - %s y - %s y - %s y - %s j - %s moment - %s fn - %s dec - %s c - %s millennium - %s a.u. + km + hm + dam + m + dm + cm + mm + μm + nm + pm + Å + mi + ch + yd + ft + mil + in + fathom + cable + NM + lnk + rd + au + pc + ly + km² + + cm² + mm² + sq mi + sq yd + sq ft + sq mil + sq in + sq rd + ac + a + dunam + ha + + dm³ + cm³ + mm³ + l + cl + dl + ml + ac ft + yd³ + ft³ + in³ + fl bl (US) + gal (US) + qt (US) + pt (US fl) + gi (US) + US fl oz + gtt + tsp + tbsp + c (US) + bl (imp) + gal (imp) + qt (imp) + pt (imp) + gi (imp) + fl oz (imp) + gtt + tsp + tbsp + g + kg + mg + μm + t + lb + oz + gr + dr + st + ton + sh tn + kt + ct + °C + °De + °F + °N + °R + °Ré + °Rø + GM + K + h + m + s + ms + µs + ns + ps + d + wk + mo + mo + mo + mo + y + y + y + j + moment + fn + dec + c + millennium + a.u. Allow customizing the bottom navigation bar color