diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.kts index 751904086..5019f547f 100644 --- a/core/ui/build.gradle.kts +++ b/core/ui/build.gradle.kts @@ -98,4 +98,5 @@ dependencies { implementation(libs.jsoup) api(libs.capturable) + api(libs.evaluator) } \ No newline at end of file diff --git a/core/ui/src/main/kotlin/ru/tech/imageresizershrinker/core/ui/widget/controls/ResizeImageField.kt b/core/ui/src/main/kotlin/ru/tech/imageresizershrinker/core/ui/widget/controls/ResizeImageField.kt index c6ef3ea70..84cf99d00 100644 --- a/core/ui/src/main/kotlin/ru/tech/imageresizershrinker/core/ui/widget/controls/ResizeImageField.kt +++ b/core/ui/src/main/kotlin/ru/tech/imageresizershrinker/core/ui/widget/controls/ResizeImageField.kt @@ -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 @@ -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 @@ -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)) + } } ) } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 27f2feced..cfc6304bc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" }