[#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 kotlinx.coroutines.launch
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
import me.zobrist.tichucounter.domain.Tichu
|
import me.zobrist.tichucounter.domain.Tichu
|
||||||
|
import me.zobrist.tichucounter.domain.digitCount
|
||||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||||
import me.zobrist.tichucounter.repository.GameRepository
|
import me.zobrist.tichucounter.repository.GameRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -202,10 +203,13 @@ class CounterViewModel @Inject constructor(
|
|||||||
override fun digitClicked(digit: String) {
|
override fun digitClicked(digit: String) {
|
||||||
focusLastInput()
|
focusLastInput()
|
||||||
|
|
||||||
|
if(activeValue.digitCount() < 5)
|
||||||
|
{
|
||||||
activeValue += digit
|
activeValue += digit
|
||||||
updateOtherScore()
|
updateOtherScore()
|
||||||
updateSubmitButton()
|
updateSubmitButton()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun negateClicked() {
|
override fun negateClicked() {
|
||||||
focusLastInput()
|
focusLastInput()
|
||||||
|
|||||||
@@ -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