diff options
author | binsky08 <timo@binsky.org> | 2022-08-27 03:10:53 +0300 |
---|---|---|
committer | binsky08 <timo@binsky.org> | 2022-08-27 03:10:53 +0300 |
commit | 20b029b151b11cf9e2549060b4821db484d38bb3 (patch) | |
tree | acb4fe6e27ecfd32229c2cc8f48ced9383f405f8 | |
parent | 9a0ef6d1dd9c87a8c79537ba7e79f374faf74336 (diff) |
fix otp generation in credential display after scanning qr code
Signed-off-by: binsky08 <timo@binsky.org>
-rw-r--r-- | app/src/main/java/es/wolfi/app/passman/fragments/CredentialDisplayFragment.java | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/app/src/main/java/es/wolfi/app/passman/fragments/CredentialDisplayFragment.java b/app/src/main/java/es/wolfi/app/passman/fragments/CredentialDisplayFragment.java index 96b32bc..30f5ee1 100644 --- a/app/src/main/java/es/wolfi/app/passman/fragments/CredentialDisplayFragment.java +++ b/app/src/main/java/es/wolfi/app/passman/fragments/CredentialDisplayFragment.java @@ -132,6 +132,7 @@ public class CredentialDisplayFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + handler = new Handler(); reloadCredentialFromActiveVaultIfPossible(); @@ -195,6 +196,11 @@ public class CredentialDisplayFragment extends Fragment { public void updateViewContent() { if (credential != null) { + if (fragmentView == null) { + Log.d("updateViewContent", "fragmentView is null (due to a previous activity unload)"); + return; + } + FloatingActionButton editCredentialButton = fragmentView.findViewById(R.id.editCredentialButton); editCredentialButton.setOnClickListener(new View.OnClickListener() { @Override @@ -238,30 +244,27 @@ public class CredentialDisplayFragment extends Fragment { url.setModeURL(); } - if (otp_refresh == null) { - otp_progress.setProgress(0); - - handler = new Handler(); - try { - JSONObject otpObj = new JSONObject(credential.getOtp()); - if (otpObj.has("secret") && otpObj.getString("secret").length() > 4) { - String otpSecret = otpObj.getString("secret"); - int otpDigits = 6; - if (otpObj.has("digits")) { - otpDigits = otpObj.getInt("digits"); - } - int otpPeriod = 30; - if (otpObj.has("period")) { - otpPeriod = otpObj.getInt("period"); - } - - int finalOtpDigits = otpDigits; - int finalOtpPeriod = otpPeriod; - otp_refresh = TOTPHelper.run(handler, otp_progress, otp.getTextView(), finalOtpDigits, finalOtpPeriod, otpSecret); + otp_progress.setProgress(0); + + try { + JSONObject otpObj = new JSONObject(credential.getOtp()); + if (otpObj.has("secret") && otpObj.getString("secret").length() > 4) { + String otpSecret = otpObj.getString("secret"); + int otpDigits = 6; + if (otpObj.has("digits")) { + otpDigits = otpObj.getInt("digits"); } - } catch (JSONException e) { - e.printStackTrace(); + int otpPeriod = 30; + if (otpObj.has("period")) { + otpPeriod = otpObj.getInt("period"); + } + + int finalOtpDigits = otpDigits; + int finalOtpPeriod = otpPeriod; + otp_refresh = TOTPHelper.run(handler, otp_progress, otp.getTextView(), finalOtpDigits, finalOtpPeriod, otpSecret); } + } catch (JSONException e) { + e.printStackTrace(); } } } |