Skip to content

Commit

Permalink
Allow repeated digit refill with PIN user input
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Feb 27, 2023
1 parent 45b2109 commit e9956fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/src/main/kotlin/com/cyb3rko/pincredible/data/PinTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ internal class PinTable : Serializable {

fun getBackground(row: Int, column: Int) = pattern[row][column]

fun fill() {
data.forEach {
it.forEachIndexed { index, i ->
if (i == -1) {
it[index] = CryptoManager.getSecureRandom()
fun fill(ignoredIndices: Set<Int> = emptySet()) {
data.forEachIndexed { rowIndex, row ->
row.indices.forEach { columnIndex ->
if (!ignoredIndices.contains(rowIndex * 7 + columnIndex)) {
row[columnIndex] = CryptoManager.getSecureRandom()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class PinCreatorFragment : Fragment() {

private val pinTable by lazy { PinTable() }
private var clickedCell: Cell? = null
private val addedIndices by lazy { mutableSetOf<Int>() }
private val vibrator by lazy { Vibration.getVibrator(myContext) }

override fun onCreateView(
Expand Down Expand Up @@ -169,11 +170,9 @@ class PinCreatorFragment : Fragment() {
clickedCellView = it.view
clickedCellView.text = button.text
revertSelectedBackground(it)
pinTable.put(
it.row,
it.column,
clickedCellView.text.toString().toInt()
)
val number = clickedCellView.text.toString().toInt()
pinTable.put(it.row, it.column, number)
addedIndices.add(it.row * 7 + it.column)
clickedCell = null
if (pinTable.isFilled()) fab.show()
}
Expand Down Expand Up @@ -225,7 +224,7 @@ class PinCreatorFragment : Fragment() {
}

private fun fillTable() {
pinTable.fill()
pinTable.fill(addedIndices)
binding.tableLayout.table.iterate { view, row, column ->
((view[row] as TableRow)[column] as TextView).text = pinTable.get(row, column)
}
Expand All @@ -238,6 +237,7 @@ class PinCreatorFragment : Fragment() {
binding.tableLayout.table.iterate { view, row, column ->
((view[row] as TableRow)[column] as TextView).text = null
}
addedIndices.clear()
}

@Throws(EnDecryptionException::class)
Expand Down

0 comments on commit e9956fd

Please sign in to comment.