Skip to content

Commit

Permalink
Redraw card info when launched by a shortcut
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brarcher committed Nov 25, 2017
1 parent c733a6c commit e091557
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -79,14 +91,7 @@ protected void onCreate(Bundle savedInstanceState)
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);

Expand All @@ -109,6 +114,19 @@ protected void onCreate(Bundle savedInstanceState)
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()
{
Expand Down

0 comments on commit e091557

Please sign in to comment.