Skip to content

Commit

Permalink
Fix #3035 (Calc does not work with pin numbers starting with 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Nov 16, 2023
1 parent a6e6794 commit e027747
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import android.widget.Toast
import net.bible.android.activity.databinding.CalculatorLayoutBinding
import net.bible.android.view.activity.base.ActivityBase
import net.bible.service.common.CommonUtils
import net.bible.service.common.CommonUtils.removeLeadingZeroes
import net.objecthunter.exp4j.ExpressionBuilder
import java.lang.Exception
import java.lang.NumberFormatException
Expand Down Expand Up @@ -256,7 +257,8 @@ class CalculatorActivity : ActivityBase() {
}

private fun calculate(input: String) = calculatorBinding.run {
val pin = CommonUtils.realSharedPreferences.getString("calculator_pin", "1234")
val pin = removeLeadingZeroes(CommonUtils.realSharedPreferences.getString("calculator_pin", "1234")!!)

if(input == pin || pin == "") {
Log.i(TAG, "Calculator: PIN OK!")
setResult(RESULT_OK)
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/net/bible/service/common/CommonUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,16 @@ object CommonUtils : CommonUtilsBase() {
clipboard.setPrimaryClip(clip)
ABEventBus.post(ToastEvent(application.getString(toastMessage)))
}

private val calcPinRegex = Regex("""^(0+)(\d+)$""")

fun removeLeadingZeroes(s: String): String {
val match = calcPinRegex.matchEntire(s)
if(match != null) {
return match.groupValues[2]
}
return s
}
}

const val CALC_NOTIFICATION_CHANNEL = "calc-notifications"
Expand Down

0 comments on commit e027747

Please sign in to comment.