From e0915578ba296d50af8936e284f045f9562ce664 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sat, 25 Nov 2017 14:23:37 -0500 Subject: [PATCH] Redraw card info when launched by a shortcut When a shortcut launches the view activity, if the activity already exists it will get onNewIntent() called. This needs to clear out the view items so the next card will be redrawn. --- .../card_locker/LoyaltyCardViewActivity.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index e594f375e..66e5b4da0 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -65,6 +65,18 @@ public class LoyaltyCardViewActivity extends AppCompatActivity DBHelper db; + private void extractIntentFields(Intent intent) + { + final Bundle b = intent.getExtras(); + loyaltyCardId = b != null ? b.getInt("id") : 0; + updateLoyaltyCard = b != null && b.getBoolean("update", false); + viewLoyaltyCard = b != null && b.getBoolean("view", false); + + Log.d(TAG, "View activity: id=" + loyaltyCardId + + ", updateLoyaltyCard=" + Boolean.toString(updateLoyaltyCard) + + ", viewLoyaltyCard=" + Boolean.toString(viewLoyaltyCard)); + } + @Override protected void onCreate(Bundle savedInstanceState) { @@ -79,14 +91,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity actionBar.setDisplayHomeAsUpEnabled(true); } - final Bundle b = getIntent().getExtras(); - loyaltyCardId = b != null ? b.getInt("id") : 0; - updateLoyaltyCard = b != null && b.getBoolean("update", false); - viewLoyaltyCard = b != null && b.getBoolean("view", false); - - Log.d(TAG, "View activity: id=" + loyaltyCardId - + ", updateLoyaltyCard=" + Boolean.toString(updateLoyaltyCard) - + ", viewLoyaltyCard=" + Boolean.toString(viewLoyaltyCard)); + extractIntentFields(getIntent()); db = new DBHelper(this); @@ -109,6 +114,19 @@ public class LoyaltyCardViewActivity extends AppCompatActivity enterButton = (Button) findViewById(R.id.enterButton); } + @Override + public void onNewIntent(Intent intent) + { + Log.i(TAG, "Received new intent"); + extractIntentFields(intent); + + // Reset these fields, so they are re-populated in onResume(). + storeFieldEdit.setText(""); + noteFieldEdit.setText(""); + cardIdFieldView.setText(""); + barcodeTypeField.setText(""); + } + @Override public void onResume() {