diff --git a/app/src/main/java/pl/lebihan/authnkey/CredentialBottomSheet.kt b/app/src/main/java/pl/lebihan/authnkey/CredentialBottomSheet.kt index 738b333..ca635e8 100644 --- a/app/src/main/java/pl/lebihan/authnkey/CredentialBottomSheet.kt +++ b/app/src/main/java/pl/lebihan/authnkey/CredentialBottomSheet.kt @@ -3,6 +3,7 @@ package pl.lebihan.authnkey import android.animation.ObjectAnimator import android.content.Context import android.content.DialogInterface +import android.content.res.ColorStateList import android.os.Bundle import android.text.InputType import android.view.LayoutInflater @@ -14,6 +15,7 @@ import android.view.inputmethod.InputMethodManager import android.widget.ImageView import android.widget.ProgressBar import android.widget.TextView +import androidx.core.content.ContextCompat import androidx.core.content.edit import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -33,6 +35,7 @@ class CredentialBottomSheet : BottomSheetDialogFragment() { PIN, ACCOUNT_SELECT, SUCCESS, + TAG_LOST, ERROR } @@ -221,20 +224,28 @@ class CredentialBottomSheet : BottomSheetDialogFragment() { State.PIN -> R.drawable.lock_24 State.ACCOUNT_SELECT -> R.drawable.account_circle_24 State.SUCCESS -> R.drawable.check_circle_24 + State.TAG_LOST -> R.drawable.sensors_24 State.ERROR -> R.drawable.error_24 } iconStatus.setImageResource(iconRes) + iconBackground.backgroundTintList = null when (state) { State.WAITING, State.TOUCH -> startPulse() + State.TAG_LOST -> { + iconBackground.backgroundTintList = ColorStateList.valueOf( + ContextCompat.getColor(requireContext(), R.color.warning_container) + ) + startPulse(750) + } else -> {} } } - private fun startPulse() { + private fun startPulse(durationMs: Long = 1000) { pulseAnimator = ObjectAnimator.ofFloat(iconBackground, View.ALPHA, 1f, 0.3f).apply { - duration = 1000 + duration = durationMs repeatCount = ObjectAnimator.INFINITE repeatMode = ObjectAnimator.REVERSE interpolator = AccelerateDecelerateInterpolator() diff --git a/app/src/main/java/pl/lebihan/authnkey/CredentialProviderActivity.kt b/app/src/main/java/pl/lebihan/authnkey/CredentialProviderActivity.kt index 3df3810..9e23d36 100644 --- a/app/src/main/java/pl/lebihan/authnkey/CredentialProviderActivity.kt +++ b/app/src/main/java/pl/lebihan/authnkey/CredentialProviderActivity.kt @@ -387,9 +387,14 @@ class CredentialProviderActivity : AppCompatActivity() { } catch (e: Exception) { Log.e(TAG, "NFC error", e) - setInstruction(getString(R.string.error_retry_format, e.toUserMessage(this@CredentialProviderActivity))) - setState(CredentialBottomSheet.State.ERROR) showProgress(false) + if (e is android.nfc.TagLostException) { + setInstruction(getString(R.string.instruction_tag_lost)) + setState(CredentialBottomSheet.State.TAG_LOST) + } else { + setInstruction(getString(R.string.error_retry_format, e.toUserMessage(this@CredentialProviderActivity))) + setState(CredentialBottomSheet.State.ERROR) + } } } } @@ -1074,8 +1079,13 @@ class CredentialProviderActivity : AppCompatActivity() { private fun handleError(e: Exception) { runOnUiThread { showProgress(false) - setInstruction(getString(R.string.error_format, e.toUserMessage(this))) - setState(CredentialBottomSheet.State.ERROR) + if (e is android.nfc.TagLostException) { + setInstruction(getString(R.string.instruction_tag_lost)) + setState(CredentialBottomSheet.State.TAG_LOST) + } else { + setInstruction(getString(R.string.error_format, e.toUserMessage(this))) + setState(CredentialBottomSheet.State.ERROR) + } } } diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index fa2952d..465f6e4 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -7,4 +7,7 @@ #BF360C #FFCC80 + + + #7C2D12 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 13b5f22..fd49fa1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,7 @@ #FFF3E0 #E65100 + + + #FED7AA diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 89ac5b4..79b23f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,6 +27,7 @@ Initializing… Verifying… Verifying PIN… + Lost contact with the security key\n\nReposition and hold until completion Security Key PIN