[#23] Limit input to 5 digits.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
fun String.digitCount(): Int {
|
||||
var count = 0
|
||||
this.forEach {
|
||||
if (it.isDigit()) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.domain.Tichu
|
||||
import me.zobrist.tichucounter.domain.digitCount
|
||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||
import me.zobrist.tichucounter.repository.GameRepository
|
||||
import javax.inject.Inject
|
||||
@@ -202,9 +203,12 @@ class CounterViewModel @Inject constructor(
|
||||
override fun digitClicked(digit: String) {
|
||||
focusLastInput()
|
||||
|
||||
activeValue += digit
|
||||
updateOtherScore()
|
||||
updateSubmitButton()
|
||||
if(activeValue.digitCount() < 5)
|
||||
{
|
||||
activeValue += digit
|
||||
updateOtherScore()
|
||||
updateSubmitButton()
|
||||
}
|
||||
}
|
||||
|
||||
override fun negateClicked() {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import me.zobrist.tichucounter.domain.digitCount
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class StringExtensionTest {
|
||||
@Test
|
||||
fun calculation_isCorrect() {
|
||||
assertEquals(0, "-".digitCount())
|
||||
assertEquals(0, "".digitCount())
|
||||
assertEquals(2, "-10".digitCount())
|
||||
assertEquals(2, "10".digitCount())
|
||||
assertEquals(10, "1234567890".digitCount())
|
||||
assertEquals(10, "-1234567890".digitCount())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user