Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-08-12 10:43:15 +02:00 committed by Alper Öztürk
parent 3ce4b8b1ac
commit ec14e5e921

View file

@ -29,7 +29,6 @@ import com.owncloud.android.databinding.PasscodelockBinding
import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.ui.components.PassCodeEditText import com.owncloud.android.ui.components.PassCodeEditText
import com.owncloud.android.utils.theme.ViewThemeUtils import com.owncloud.android.utils.theme.ViewThemeUtils
import java.util.Arrays
import javax.inject.Inject import javax.inject.Inject
@Suppress("TooManyFunctions", "MagicNumber") @Suppress("TooManyFunctions", "MagicNumber")
@ -69,7 +68,7 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
private set private set
private val passCodeEditTexts = arrayOfNulls<PassCodeEditText>(4) private val passCodeEditTexts = arrayOfNulls<PassCodeEditText>(4)
private var passCodeDigits: Array<String?>? = arrayOf("", "", "", "") private var passCodeDigits: Array<String> = arrayOf("", "", "", "")
private var confirmingPassCode = false private var confirmingPassCode = false
private var changed = true // to control that only one blocks jump private var changed = true // to control that only one blocks jump
@ -117,7 +116,7 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
} else if (ACTION_REQUEST_WITH_RESULT == intent.action) { } else if (ACTION_REQUEST_WITH_RESULT == intent.action) {
if (savedInstanceState != null) { if (savedInstanceState != null) {
confirmingPassCode = savedInstanceState.getBoolean(KEY_CONFIRMING_PASSCODE) confirmingPassCode = savedInstanceState.getBoolean(KEY_CONFIRMING_PASSCODE)
passCodeDigits = savedInstanceState.getStringArray(KEY_PASSCODE_DIGITS) passCodeDigits = savedInstanceState.getStringArray(KEY_PASSCODE_DIGITS) ?: arrayOf("", "", "", "")
} }
if (confirmingPassCode) { if (confirmingPassCode) {
// the app was in the passcode confirmation // the app was in the passcode confirmation
@ -185,7 +184,7 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
passCodeEditTexts[passCodeIndex - 1]?.requestFocus() passCodeEditTexts[passCodeIndex - 1]?.requestFocus()
if (!confirmingPassCode) { if (!confirmingPassCode) {
passCodeDigits?.set(passCodeIndex - 1, "") passCodeDigits[passCodeIndex - 1] = ""
} }
passCodeEditTexts[passCodeIndex - 1]?.setText(R.string.empty) passCodeEditTexts[passCodeIndex - 1]?.setText(R.string.empty)
@ -258,8 +257,6 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
} }
private fun showErrorAndRestart(errorMessage: Int, headerMessage: Int, explanationVisibility: Int) { private fun showErrorAndRestart(errorMessage: Int, headerMessage: Int, explanationVisibility: Int) {
passCodeDigits?.let { Arrays.fill(it, null) }
Snackbar.make(findViewById(android.R.id.content), getString(errorMessage), Snackbar.LENGTH_LONG).show() Snackbar.make(findViewById(android.R.id.content), getString(errorMessage), Snackbar.LENGTH_LONG).show()
binding.header.setText(headerMessage) // TODO check if really needed binding.header.setText(headerMessage) // TODO check if really needed
binding.explanation.visibility = explanationVisibility // TODO check if really needed binding.explanation.visibility = explanationVisibility // TODO check if really needed
@ -279,14 +276,14 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
private fun checkPassCode(): Boolean { private fun checkPassCode(): Boolean {
val savedPassCodeDigits = preferences?.passCode val savedPassCodeDigits = preferences?.passCode
return passCodeDigits?.zip(savedPassCodeDigits.orEmpty()) { input, saved -> return passCodeDigits.zip(savedPassCodeDigits.orEmpty()) { input, saved ->
input != null && input == saved input == saved
}?.all { it } ?: false }.all { it }
} }
private fun confirmPassCode(): Boolean { private fun confirmPassCode(): Boolean {
return passCodeEditTexts.indices.all { i -> return passCodeEditTexts.indices.all { i ->
passCodeEditTexts[i]?.text.toString() == passCodeDigits!![i] passCodeEditTexts[i]?.text.toString() == passCodeDigits[i]
} }
} }
@ -320,7 +317,7 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
val resultIntent = Intent() val resultIntent = Intent()
resultIntent.putExtra( resultIntent.putExtra(
KEY_PASSCODE, KEY_PASSCODE,
passCodeDigits!![0] + passCodeDigits!![1] + passCodeDigits!![2] + passCodeDigits!![3] passCodeDigits[0] + passCodeDigits[1] + passCodeDigits[2] + passCodeDigits[3]
) )
setResult(RESULT_OK, resultIntent) setResult(RESULT_OK, resultIntent)
passCodeManager?.updateLockTimestamp() passCodeManager?.updateLockTimestamp()
@ -397,7 +394,7 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
val passCodeText = passCodeEditTexts[mIndex]?.text val passCodeText = passCodeEditTexts[mIndex]?.text
if (passCodeText != null) { if (passCodeText != null) {
passCodeDigits!![mIndex] = passCodeText.toString() passCodeDigits[mIndex] = passCodeText.toString()
} }
} }