Skip to content

Commit

Permalink
Added simple calculator for image dimensions by #1581
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Jan 10, 2025
1 parent ba88a7e commit 5142459
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ dependencies {
implementation(libs.jsoup)

api(libs.capturable)
api(libs.evaluator)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Calculate
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -48,13 +49,16 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import com.github.keelar.exprk.Expressions
import ru.tech.imageresizershrinker.core.domain.image.model.ImageFormat
import ru.tech.imageresizershrinker.core.domain.image.model.ImageInfo
import ru.tech.imageresizershrinker.core.domain.model.IntegerSize
import ru.tech.imageresizershrinker.core.resources.R
import ru.tech.imageresizershrinker.core.ui.utils.helper.ImageUtils
import ru.tech.imageresizershrinker.core.ui.utils.helper.ImageUtils.restrict
import ru.tech.imageresizershrinker.core.ui.utils.provider.rememberLocalEssentials
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedAlertDialog
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedButton
import ru.tech.imageresizershrinker.core.ui.widget.enhanced.EnhancedIconButton
import ru.tech.imageresizershrinker.core.ui.widget.modifier.container
import ru.tech.imageresizershrinker.core.ui.widget.text.RoundedTextField
Expand Down Expand Up @@ -200,20 +204,49 @@ internal fun ResizeImageFieldImpl(
interactionSource = interactionSource
)

var calculatorExpression by rememberSaveable(value) {
mutableStateOf(value)
}
val essentials = rememberLocalEssentials()
EnhancedAlertDialog(
visible = showCalculator,
onDismissRequest = { showCalculator = false },
confirmButton = {

EnhancedButton(
onClick = {
runCatching {
Expressions().eval(calculatorExpression)
}.onFailure {
essentials.showFailureToast(it)
}.onSuccess {
onValueChange(it.toInt().toString())
showCalculator = false
}
}
) {
Text(stringResource(R.string.apply))
}
},
title = {

Text(
text = stringResource(R.string.calculate)
)
},
icon = {

Icon(
imageVector = Icons.Outlined.Calculate,
contentDescription = null
)
},
dismissButton = {

EnhancedButton(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
onClick = {
showCalculator = false
}
) {
Text(stringResource(R.string.close))
}
}
)
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ moshi = "1.15.2"
aboutlibraries = "11.4.0"
junit = "4.13.2"
bouncycastle = "1.79"
evaluator = "1.0.0"

[libraries]
evaluator = { module = "com.github.T8RIN:KotlinEvaluator", version.ref = "evaluator" }
aboutlibraries-m3 = { module = "com.mikepenz:aboutlibraries-compose-m3", version.ref = "aboutlibraries" }
moshi = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }
trickle = { module = "com.github.t8rin:trickle", version.ref = "trickle" }
Expand Down

0 comments on commit 5142459

Please sign in to comment.