Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 5 #16

Merged
merged 30 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
12938e9
chore: Update dependencies
Myzel394 Jul 11, 2024
7e9d057
fix: Do not remember width and height to update correctly
Myzel394 Jul 12, 2024
084d66a
feat: Add custom keyboard depending on input unit when in base conver…
Myzel394 Jul 12, 2024
1a2ae45
fix: Add Hexadecimal as default NumberBase
Myzel394 Jul 12, 2024
792dc93
feat: Set default ordering to scale ascending
Myzel394 Jul 12, 2024
00ca88b
feat: Add animation to ConverterKeyboard.kt
Myzel394 Jul 13, 2024
38ba85a
fix: Improve animation for ConverterKeyboard.kt
Myzel394 Jul 13, 2024
b343b78
fix: Improve ConverterKeyboard.kt
Myzel394 Jul 13, 2024
2097ab5
feat: Add base calculation summary underneath converter
Myzel394 Jul 13, 2024
5a694ea
feat: Add single digit change feature for calculation summary
Myzel394 Jul 13, 2024
305744f
fix: Fix size
Myzel394 Jul 13, 2024
855f620
feat: Add information for value of 1 for conversions
Myzel394 Jul 13, 2024
ab4c8a8
feat: Add opinionated unit pairings
Myzel394 Jul 13, 2024
ad107b0
fix: Fix ConverterKeyboard.kt overflow
Myzel394 Jul 13, 2024
a07aa51
fix: Only show ValueOneSummary if value is available
Myzel394 Jul 16, 2024
f92becc
Merge pull request #13 from Myzel394/improve-keyboard-layout
Myzel394 Jul 17, 2024
1e2cc1c
chore: Fix versionName
Myzel394 Jul 19, 2024
a25e773
chore: Fix fastlane
Myzel394 Jul 19, 2024
cbf3fa5
updated french translations
Crazy-Unicooorn Jul 19, 2024
84c7660
updated french translation
Crazy-Unicooorn Jul 19, 2024
f313da7
fix(evaluator): Fix square root rounding error; Closes #18
Myzel394 Jul 21, 2024
5a9440d
fix(evaluator): Improve sin and cos threshold values
Myzel394 Jul 21, 2024
6a5efe9
tests(evaluator): Add more tests
Myzel394 Jul 21, 2024
84ddb6b
fix(evaluator)!: Throw exception when trying to do 0^0
Myzel394 Jul 21, 2024
b53a0b1
test(evaluator): Add more tests
Myzel394 Jul 21, 2024
33293a4
fix(evaluator): Fix power
Myzel394 Jul 21, 2024
cc7c719
test(evaluator): Fix incorrect character (use minus from UTF-8 Mathem…
Myzel394 Jul 21, 2024
11fe482
Merge pull request #17 from Crazy-Unicooorn/master
Myzel394 Jul 21, 2024
fc60b81
feat(ci-cd): Increase Java heap size
Myzel394 Jul 21, 2024
57ea6f1
Merge remote-tracking branch 'origin/version-5' into version-5
Myzel394 Jul 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Build and push debug app
on:
pull_request:

env:
JAVA_OPTS: -Xmx12G

jobs:
debug-builds:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release-app-github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
release:
types: [ published ]

env:
JAVA_OPTS: -Xmx12G

jobs:
release-app-github:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release-app-google-play.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
release:
types: [ published ]

env:
JAVA_OPTS: -Xmx12G

jobs:
release-app-google-play:
runs-on: ubuntu-latest
Expand Down
362 changes: 181 additions & 181 deletions core/base/src/main/res/values-fr/strings.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.foundation.layout.FlowRowScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

/**
Expand All @@ -51,8 +50,8 @@ fun KeypadFlow(
@IntRange(0, 100) verticalPadding: Int = 10,
content: @Composable FlowRowScope.(width: Float, height: Float) -> Unit,
) {
val height: Float = remember { (1f - verticalPadding / 100f) / rows }
val width: Float = remember { (1f - horizontalPadding / 100f) / columns }
val height: Float = (1f - verticalPadding / 100f) / rows
val width: Float = (1f - horizontalPadding / 100f) / columns

FlowRow(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,232 @@ class UnitsRepositoryImpl @Inject constructor(

suspend fun getPairId(id: String): String = withContext(Dispatchers.IO) {
val basedUnitPair = getUnitStats(id).pairedUnitId
if (basedUnitPair != null) return@withContext basedUnitPair
if (basedUnitPair != null) {
return@withContext basedUnitPair
}

val inMemoryUnit = inMemory.first { it.id == id }
val collection = inMemory.filter { it.group == inMemoryUnit.group }

val pair = collection
.map { getById(it.id) to getUnitStats(it.id) }
.sortedByDescending { it.second.frequency }
.firstOrNull { it.second.isFavorite }?.first ?: collection.first()

return@withContext pair.id
return@withContext when (inMemoryUnit.id) {
// === === === Length === === ===
UnitID.nanometer -> UnitID.micrometer
UnitID.micrometer -> UnitID.millimeter
UnitID.millimeter -> UnitID.centimeter

UnitID.centimeter -> UnitID.inch
UnitID.inch -> UnitID.centimeter
UnitID.decimeter -> UnitID.centimeter
UnitID.foot -> UnitID.meter
UnitID.yard -> UnitID.meter
UnitID.meter -> UnitID.foot

UnitID.kilometer -> UnitID.mile
UnitID.mile -> UnitID.kilometer
UnitID.nautical_mile -> UnitID.kilometer

UnitID.mercury_equatorial_radius -> UnitID.kilometer
UnitID.mars_equatorial_radius -> UnitID.kilometer
UnitID.venus_equatorial_radius -> UnitID.kilometer
UnitID.earth_equatorial_radius -> UnitID.kilometer
UnitID.neptune_equatorial_radius -> UnitID.kilometer
UnitID.uranus_equatorial_radius -> UnitID.kilometer
UnitID.saturn_equatorial_radius -> UnitID.kilometer
UnitID.jupiter_equatorial_radius -> UnitID.kilometer
UnitID.sun_equatorial_radius -> UnitID.kilometer

UnitID.light_year -> UnitID.kilometer

UnitID.parsec -> UnitID.light_year
UnitID.kiloparsec -> UnitID.parsec
UnitID.megaparsec -> UnitID.kiloparsec


// === === === Mass === === ===
UnitID.electron_mass_rest -> UnitID.atomic_mass_unit
UnitID.atomic_mass_unit -> UnitID.electron_mass_rest

UnitID.microgram -> UnitID.milligram
UnitID.milligram -> UnitID.gram
UnitID.grain -> UnitID.gram
UnitID.carat -> UnitID.gram

UnitID.gram -> UnitID.carat
UnitID.ounce -> UnitID.gram
UnitID.pound -> UnitID.kilogram
UnitID.kilogram -> UnitID.pound

UnitID.metric_ton -> UnitID.kilogram
UnitID.imperial_ton -> UnitID.pound

UnitID.mercury_mass -> UnitID.kilogram
UnitID.mars_mass -> UnitID.kilogram
UnitID.venus_mass -> UnitID.kilogram
UnitID.earth_mass -> UnitID.kilogram
UnitID.uranus_mass -> UnitID.kilogram
UnitID.neptune_mass -> UnitID.kilogram
UnitID.saturn_mass -> UnitID.kilogram
UnitID.jupiter_mass -> UnitID.kilogram
UnitID.sun_mass -> UnitID.kilogram


// === === === Speed === === ===
UnitID.millimeter_per_hour -> UnitID.millimeter_per_second
UnitID.millimeter_per_second -> UnitID.millimeter_per_hour
UnitID.millimeter_per_minute -> UnitID.millimeter_per_second
UnitID.centimeter_per_hour -> UnitID.centimeter_per_second
UnitID.centimeter_per_second -> UnitID.centimeter_per_hour
UnitID.centimeter_per_minute -> UnitID.centimeter_per_second
UnitID.meter_per_hour -> UnitID.meter_per_second
UnitID.meter_per_second -> UnitID.meter_per_hour
UnitID.meter_per_minute -> UnitID.meter_per_second

UnitID.kilometer_per_hour -> UnitID.mile_per_hour
UnitID.kilometer_per_second -> UnitID.mile_per_second
UnitID.kilometer_per_minute -> UnitID.kilometer_per_second
UnitID.mile_per_hour -> UnitID.kilometer_per_hour
UnitID.mile_per_second -> UnitID.kilometer_per_second
UnitID.mile_per_minute -> UnitID.mile_per_second

UnitID.foot_per_hour -> UnitID.foot_per_second
UnitID.foot_per_second -> UnitID.foot_per_hour
UnitID.foot_per_minute -> UnitID.foot_per_second
UnitID.yard_per_hour -> UnitID.yard_per_second
UnitID.yard_per_second -> UnitID.yard_per_hour
UnitID.yard_per_minute -> UnitID.yard_per_second

UnitID.knot -> UnitID.kilometer_per_hour
UnitID.mach -> UnitID.kilometer_per_hour
UnitID.velocity_of_light_in_vacuum -> UnitID.kilometer_per_hour
UnitID.earths_orbital_speed -> UnitID.kilometer_per_hour

UnitID.cosmic_velocity_first -> UnitID.kilometer_per_hour
UnitID.cosmic_velocity_second -> UnitID.kilometer_per_hour
UnitID.cosmic_velocity_third -> UnitID.kilometer_per_hour


// === === === Temperature === === ===
UnitID.celsius -> UnitID.fahrenheit
UnitID.fahrenheit -> UnitID.celsius
UnitID.kelvin -> UnitID.celsius


// === === === Area === === ===
UnitID.square_micrometer -> UnitID.square_millimeter
UnitID.square_millimeter -> UnitID.square_centimeter
UnitID.square_centimeter -> UnitID.square_meter
UnitID.square_decimeter -> UnitID.square_meter
UnitID.square_meter -> UnitID.square_kilometer

UnitID.square_kilometer -> UnitID.square_meter

UnitID.square_inch -> UnitID.square_foot
UnitID.square_foot -> UnitID.square_inch
UnitID.square_yard -> UnitID.square_meter
UnitID.square_mile -> UnitID.square_kilometer

UnitID.acre -> UnitID.square_meter
UnitID.hectare -> UnitID.square_meter
UnitID.cent -> UnitID.square_meter


// === === === Time === === ===
UnitID.attosecond -> UnitID.nanosecond
UnitID.nanosecond -> UnitID.microsecond
UnitID.microsecond -> UnitID.millisecond
UnitID.millisecond -> UnitID.second

UnitID.jiffy -> UnitID.millisecond

UnitID.second -> UnitID.millisecond
UnitID.minute -> UnitID.second
UnitID.hour -> UnitID.minute
UnitID.day -> UnitID.hour
UnitID.week -> UnitID.day


// === === === Data === === ===
// TODO: Add tibibyte, exibyte
UnitID.bit -> UnitID.byte
UnitID.byte -> UnitID.kilobyte
UnitID.kilobyte -> UnitID.megabyte
UnitID.megabyte -> UnitID.gigabyte
UnitID.gigabyte -> UnitID.terabyte
UnitID.terabyte -> UnitID.petabyte
UnitID.petabyte -> UnitID.exabyte

UnitID.kilobit -> UnitID.kilobyte
UnitID.megabit -> UnitID.megabyte
UnitID.gigabit -> UnitID.gigabyte
UnitID.terabit -> UnitID.terabyte
UnitID.petabit -> UnitID.petabyte
UnitID.exabit -> UnitID.exabyte

UnitID.kibibit -> UnitID.kilobyte
UnitID.mebibit -> UnitID.megabyte
UnitID.gibibit -> UnitID.gigabyte

UnitID.kibibyte -> UnitID.kilobyte
UnitID.mebibyte -> UnitID.megabyte
UnitID.gibibyte -> UnitID.gigabyte


// === === === Acceleration === === ===
UnitID.millimeter_per_square_second -> UnitID.centimeter_per_square_second
UnitID.centimeter_per_square_second -> UnitID.meter_per_square_second
UnitID.decimeter_per_square_second -> UnitID.meter_per_square_second
UnitID.meter_per_square_second -> UnitID.kilometer_per_square_second

UnitID.mercury_surface_gravity -> UnitID.meter_per_square_second
UnitID.mars_surface_gravity -> UnitID.meter_per_square_second
UnitID.venus_surface_gravity -> UnitID.meter_per_square_second
UnitID.uranus_surface_gravity -> UnitID.meter_per_square_second
UnitID.earth_surface_gravity -> UnitID.meter_per_square_second
UnitID.saturn_surface_gravity -> UnitID.meter_per_square_second
UnitID.neptune_surface_gravity -> UnitID.meter_per_square_second
UnitID.jupiter_surface_gravity -> UnitID.meter_per_square_second
UnitID.sun_surface_gravity -> UnitID.meter_per_square_second


// === === === Power === === ===
UnitID.attowatt -> UnitID.watt
UnitID.watt -> UnitID.kilowatt
UnitID.kilowatt -> UnitID.watt
UnitID.megawatt -> UnitID.kilowatt


// === === === Angle === === ===
UnitID.degree -> UnitID.radian
UnitID.radian -> UnitID.degree


// === === === Data Transfer === === ===
UnitID.bit_per_second -> UnitID.byte_per_second
UnitID.kilobit_per_second -> UnitID.kilobyte_per_second
UnitID.megabit_per_second -> UnitID.megabyte_per_second
UnitID.gigabit_per_second -> UnitID.gigabyte_per_second
UnitID.terabit_per_second -> UnitID.terabyte_per_second
UnitID.petabit_per_second -> UnitID.petabyte_per_second
UnitID.exabit_per_second -> UnitID.exabyte_per_second

UnitID.byte_per_second -> UnitID.kilobyte_per_second
UnitID.kilobyte_per_second -> UnitID.megabyte_per_second
UnitID.megabyte_per_second -> UnitID.gigabyte_per_second
UnitID.gigabyte_per_second -> UnitID.megabyte_per_second
UnitID.terabyte_per_second -> UnitID.gigabyte_per_second
UnitID.petabyte_per_second -> UnitID.terabyte_per_second


// === === === Fuel === === ===
UnitID.kilometer_per_liter -> UnitID.mile_us_per_liter
UnitID.mile_us_per_liter -> UnitID.kilometer_per_liter

else ->
(collection
.map { getById(it.id) to getUnitStats(it.id) }
.sortedByDescending { it.second.frequency }
.firstOrNull { it.second.isFavorite }?.first ?: collection.first()).id
}
}

suspend fun incrementCounter(id: String) = withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ import kotlin.math.asin
import kotlin.math.atan
import kotlin.math.pow

// Dirty hack to avoid -0.000000000001
val PI_THRESHOLD = BigDecimal("0.000000000000001")

internal fun BigDecimal.sin(radianMode: Boolean): BigDecimal {
val angle: Double = if (radianMode) this.toDouble() else Math.toRadians(this.toDouble())
return kotlin.math.sin(angle).toBigDecimal()

val result = kotlin.math.sin(angle).toBigDecimal()

if (result.abs() < PI_THRESHOLD) {
return BigDecimal.ZERO
}

return result
}

internal fun BigDecimal.arsin(radianMode: Boolean): BigDecimal {
Expand All @@ -38,7 +48,14 @@ internal fun BigDecimal.arsin(radianMode: Boolean): BigDecimal {

internal fun BigDecimal.cos(radianMode: Boolean): BigDecimal {
val angle: Double = if (radianMode) this.toDouble() else Math.toRadians(this.toDouble())
return kotlin.math.cos(angle).toBigDecimal()

val result = kotlin.math.cos(angle).toBigDecimal()

if (result.abs() < PI_THRESHOLD) {
return BigDecimal.ZERO
}

return result
}

internal fun BigDecimal.arcos(radianMode: Boolean): BigDecimal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ class Expression(
}

moveIfMatched(Token.Operator.divide) -> {
val divisor = parseFactor()
// Adding those `setScale` calls have been added in
// 36a931c7d175b5cad52ff3abceb7784b0bb82aac to fix #18
// I'm not sure if this is the correct way to fix it, but it
// seems to be working
val divisor = parseFactor().setScale(MAX_PRECISION)
if (divisor.compareTo(BigDecimal.ZERO) == 0) throw ExpressionException.DivideByZero()

expression = expression.divide(divisor, roundingMode)
expression = expression.setScale(MAX_PRECISION).divide(divisor, roundingMode)
}
}
}
Expand Down Expand Up @@ -166,7 +170,8 @@ class Expression(

// sin
if (moveIfMatched(Token.Func.sin)) {
expr = parseFuncParentheses().sin(radianMode)
val x = parseFuncParentheses()
expr = x.sin(radianMode)
}

// cos
Expand Down Expand Up @@ -211,7 +216,13 @@ class Expression(

// Power
if (moveIfMatched(Token.Operator.power)) {
expr = expr.pow(parseFactor())
val factor = parseFactor()

if (factor.compareTo(BigDecimal.ZERO) == 0 && expr.compareTo(BigDecimal.ZERO) == 0) {
throw ExpressionException.BadExpression()
}

expr = expr.pow(factor)
}

// Modulo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ class ExpressionComplexTest {

@Test
fun expression12() = assertExpr("2×(3+4)×(5−2)÷6", "7")

@Test
fun shouldDivideRootAndDivideInCorrectOrder() = assertExpr("(√9)÷6", "0.5")
}
Loading