From dc52b2617d80acc8b1c82a96f2fcb4fb8de7885c Mon Sep 17 00:00:00 2001 From: Petru Date: Thu, 15 Aug 2013 21:19:24 +0300 Subject: [PATCH] Work on delete event to finish activity --- src/ro/ieval/unical/DeleteEventDialog.java | 13 ++++--------- src/ro/ieval/unical/DisplayEventActivity.java | 13 ++++++++++++- src/ro/ieval/unical/EventListActivity.java | 6 ++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/ro/ieval/unical/DeleteEventDialog.java b/src/ro/ieval/unical/DeleteEventDialog.java index 56e71cb..806db7e 100644 --- a/src/ro/ieval/unical/DeleteEventDialog.java +++ b/src/ro/ieval/unical/DeleteEventDialog.java @@ -10,24 +10,19 @@ import android.os.Bundle; @SuppressLint("ValidFragment") public final class DeleteEventDialog extends DialogFragment { - private final Event event; - private final Activity activity; - - public DeleteEventDialog(final Event event, final Activity activity) { - super(); - this.event=event; - this.activity=activity; - } + private Event event; + public boolean deleted=false; @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + event=getArguments().getParcelable("Event"); builder.setMessage(R.string.askdeleteevent) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { event.delete(getActivity()); - activity.finish(); + deleted=true; } }) .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { diff --git a/src/ro/ieval/unical/DisplayEventActivity.java b/src/ro/ieval/unical/DisplayEventActivity.java index 7e2e78f..906ed5c 100644 --- a/src/ro/ieval/unical/DisplayEventActivity.java +++ b/src/ro/ieval/unical/DisplayEventActivity.java @@ -16,6 +16,7 @@ import android.widget.TextView; public class DisplayEventActivity extends Activity { public static final String EXTRA_EVENT = "event"; private Event event; + private final DeleteEventDialog d=new DeleteEventDialog(); public static void displayEvent(final Context context, final Event event){ final Intent i=new Intent(context,DisplayEventActivity.class); @@ -55,6 +56,13 @@ public class DisplayEventActivity extends Activity { description.setText(event.description); } + @Override + protected void onResume () { + super.onResume(); + if(d.deleted) + finish(); + } + @Override public boolean onCreateOptionsMenu(final Menu menu) { final MenuInflater inflater = getMenuInflater(); @@ -67,8 +75,11 @@ public class DisplayEventActivity extends Activity { // Handle item selection switch (item. getItemId()) { case R.id.deleteevent: - final DeleteEventDialog d=new DeleteEventDialog(event,this); + final Bundle b=new Bundle(); + b.putParcelable("Event",event); + d.setArguments(b); d.show(getFragmentManager(), "Delete"); + return true; case R.id.eventlist: final Intent it=new Intent(this,EventListActivity.class); diff --git a/src/ro/ieval/unical/EventListActivity.java b/src/ro/ieval/unical/EventListActivity.java index 652bd78..8763aeb 100644 --- a/src/ro/ieval/unical/EventListActivity.java +++ b/src/ro/ieval/unical/EventListActivity.java @@ -74,6 +74,12 @@ public final class EventListActivity extends ListActivity { getListView().setSelectionFromTop(idx, 0); } + @Override + protected void onStart() { + super.onStart(); + displayEvents(); + } + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); -- 2.39.2