|
3 | 3 | import android.Manifest; |
4 | 4 | import android.app.Dialog; |
5 | 5 | import android.app.ProgressDialog; |
| 6 | +import android.content.DialogInterface; |
| 7 | +import android.support.design.widget.Snackbar; |
| 8 | +import android.support.v7.app.AlertDialog; |
6 | 9 | import android.content.Context; |
7 | 10 | import android.content.DialogInterface; |
8 | 11 | import android.content.Intent; |
@@ -583,25 +586,19 @@ public boolean onOptionsItemSelected(MenuItem item) { |
583 | 586 |
|
584 | 587 | switch (id) { |
585 | 588 | case R.id.action_delete: |
586 | | - |
587 | | - final AlertDialog dialog = new AlertDialog.Builder(this) |
588 | | - .setTitle(R.string.dialog_delete_title) |
589 | | - .setMessage(R.string.dialog_delete_msg) |
590 | | - .setPositiveButton(R.string.dialog_yes, null) |
591 | | - .setNegativeButton(R.string.dialog_no, null) |
592 | | - .create(); |
593 | | - dialog.show(); |
594 | | - |
595 | | - dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { |
596 | | - @Override |
597 | | - public void onClick(View v) { |
598 | | - dialog.dismiss(); |
599 | | - selectedTemplate.deleteItem(TemplateEditor.this, selectedPosition); |
600 | | - selectedPosition = -1; |
601 | | - restoreSelectedView(); |
602 | | - } |
603 | | - }); |
604 | | - |
| 589 | + final int restorePosition = selectedPosition; |
| 590 | + final Object object = selectedTemplate.deleteItem(TemplateEditor.this,selectedPosition); |
| 591 | + selectedPosition = -1; |
| 592 | + restoreSelectedView(); |
| 593 | + Snackbar.make(findViewById(R.id.relative_layout), |
| 594 | + R.string.snackbar_deleted_message,Snackbar.LENGTH_LONG) |
| 595 | + .setAction(R.string.snackbar_undo, new View.OnClickListener() { |
| 596 | + @Override |
| 597 | + public void onClick(View v) { |
| 598 | + selectedTemplate.restoreItem(TemplateEditor.this,restorePosition,object); |
| 599 | + Snackbar.make(v,R.string.snackbar_restored_message,Snackbar.LENGTH_LONG).show(); |
| 600 | + } |
| 601 | + }).show(); |
605 | 602 | break; |
606 | 603 | case R.id.action_edit: |
607 | 604 | selectedTemplate.editItem(this, selectedPosition); |
|
0 commit comments