Skip to content

Commit

Permalink
Merge pull request #39 from davidmigloz/hotfix/max-amount-formatting
Browse files Browse the repository at this point in the history
Fix max amount formatting with correct separator, Add initialAmount support
  • Loading branch information
delacrixmorgan authored Mar 6, 2024
2 parents 23156e2 + 21f5659 commit 16c383f
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## Version 4.0.3 *(XX/03/2024)*

- Fix max amount formatting with correct separator
- Add initialAmount support and cleanup unused ExperimentalLayoutApi warnings

## Version 4.0.2 *(03/11/2023)*

- Fix JitPack build
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ NumberKeyboard(

##### Attribute

- `initialAmount` - Double (default: 0.0): Initial amount for `NumberKeyboard` output
- `maxAllowedAmount` - Double (default: 10_000.0): Maximum amount allowed for the `NumberKeyboard` output
- `maxAllowedDecimals` - Int (default: 2): Maximum decimal points allowed for the `NumberKeyboard` output
- `currencySymbol` - String (default: "$"): Currency symbol for the `NumberKeyboardData` currency format output
Expand Down
4 changes: 2 additions & 2 deletions configurations.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ext {
javaVersion = JavaVersion.VERSION_18
jvmToolchainVersion = 18
javaVersion = JavaVersion.VERSION_20
jvmToolchainVersion = 20

androidConfig = [
minSdkVersion : 21,
Expand Down
10 changes: 5 additions & 5 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ ext {
//----------------------------------------------------------------------------------------------

// Android Plugin for Gradle : https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google | https://developer.android.com/studio/releases/gradle-plugin.html#updating-plugin
androidGradle = '8.1.2'
androidGradle = '8.3.0'
// Kotlin : https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin
// Kotlin Compose Compatibility Map : https://developer.android.com/jetpack/androidx/releases/compose-kotlin
kotlin = '1.9.10'
kotlin = '1.9.22'
// Compose Compiler : https://developer.android.com/jetpack/androidx/releases/compose-compiler
composeCompiler = '1.5.3'
composeCompiler = '1.5.10'

//----------------------------------------------------------------------------------------------
// App Dependencies
//----------------------------------------------------------------------------------------------

// Compose Bill of Materials : https://mvnrepository.com/artifact/androidx.compose/compose-bom
composeBoM = "2023.10.01"
composeBoM = "2024.02.01"
// Compose Navigation : https://developer.android.com/jetpack/compose/navigation
composeNav = '2.7.5'
composeNav = '2.7.7'
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
ext {
versionMajor = 4 // API Changes, adding big new feature, redesign the App
versionMinor = 0 // New features in a backwards-compatible manner
versionPatch = 0 // Backwards-compatible bug fixes
versionPatch = 3 // Backwards-compatible bug fixes
versionClassifier = null // Pre-releases (alpha, beta, rc, SNAPSHOT...)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import androidx.compose.ui.unit.dp
import com.davidmiguel.numberkeyboard.data.NumberKeyboardData
import com.davidmiguel.numberkeyboard.listener.NumberKeyboardClickedListener
import com.davidmiguel.numberkeyboard.listener.NumberKeyboardListener
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.NumberFormat

@Composable
fun NumberKeyboard(
initialAmount: Double = 0.0,
maxAllowedAmount: Double = 10_000.0,
maxAllowedDecimals: Int = 2,
currencySymbol: String = "$",
Expand All @@ -34,7 +34,7 @@ fun NumberKeyboard(
groupingSeparator: Char = (NumberFormat.getNumberInstance() as DecimalFormat).decimalFormatSymbols.groupingSeparator,
listener: NumberKeyboardListener? = null
) {
var amount by remember { mutableStateOf("") }
var amount by remember { mutableStateOf(if (initialAmount != 0.0) initialAmount.toInt().toString() else "") }

val firstRow: List<Int>
val secondRow: List<Int>
Expand Down Expand Up @@ -63,7 +63,7 @@ fun NumberKeyboard(
if (standardisedAmount in 0.0..maxAllowedAmount) {
amount += number
} else {
amount = if (roundUpToMax) maxAllowedAmount.toBigDecimal().setScale(maxAllowedDecimals, RoundingMode.UP).toString() else amount
amount = if (roundUpToMax) maxAllowedAmount.toString().replace('.', decimalSeparator) else amount
}
listener?.onUpdated(NumberKeyboardData(amount, decimalSeparator, groupingSeparator, currencySymbol))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.davidmiguel.numberkeyboard.NumberKeyboardButton
import com.davidmiguel.numberkeyboard.data.NumberKeyboardData
import com.davidmiguel.numberkeyboard.listener.NumberKeyboardListener

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun BiometricScreen(innerPadding: PaddingValues, context: Context = LocalContext.current) {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.davidmiguel.numberkeyboard.listener.NumberKeyboardListener
import java.text.DecimalFormat
import java.text.NumberFormat

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun CustomScreen(innerPadding: PaddingValues) {
val currencySymbol = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.davidmiguel.numberkeyboard.listener.NumberKeyboardListener
import java.text.DecimalFormat
import java.text.NumberFormat

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun DecimalScreen(innerPadding: PaddingValues) {
val currencySymbol = "$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.davidmiguel.numberkeyboard.NumberKeyboardButton
import com.davidmiguel.numberkeyboard.data.NumberKeyboardData
import com.davidmiguel.numberkeyboard.listener.NumberKeyboardListener

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun IntegerScreen(innerPadding: PaddingValues) {
Column(
Expand Down

0 comments on commit 16c383f

Please sign in to comment.