Skip to content

Commit

Permalink
Add a confirmation before deleting card
Browse files Browse the repository at this point in the history
  • Loading branch information
Branden Archer authored and Branden Archer committed Jul 20, 2016
1 parent a32415b commit 04b0d50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
32 changes: 28 additions & 4 deletions app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@


import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
Expand Down Expand Up @@ -275,11 +277,33 @@ public boolean onOptionsItemSelected(MenuItem item)
break;

case R.id.action_delete:
Log.e(TAG, "Deleting card: " + loyaltyCardId);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.delete);
builder.setMessage(R.string.deleteConfirmation);
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Log.e(TAG, "Deleting card: " + loyaltyCardId);

DBHelper db = new DBHelper(LoyaltyCardViewActivity.this);
db.deleteLoyaltyCard(loyaltyCardId);
finish();
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();

DBHelper db = new DBHelper(this);
db.deleteLoyaltyCard(loyaltyCardId);
finish();
return true;
case R.id.action_edit:
Intent intent = new Intent(getApplicationContext(), LoyaltyCardViewActivity.class);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="enterCard">Enter Card</string>
<string name="edit">Edit</string>
<string name="delete">Delete</string>
<string name="deleteConfirmation">Are you sure you want to delete the loyalty card?</string>
<string name="ok">OK</string>
<string name="copy_to_clipboard">Copy ID to clipboard</string>

Expand Down

0 comments on commit 04b0d50

Please sign in to comment.