diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/AboutActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/AboutActivity.java index 68dac0a7a..e3c06daf0 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/AboutActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/AboutActivity.java @@ -26,6 +26,7 @@ public class AboutActivity extends AppCompatActivity { @BindView(R.id.about_version) TextView mVersion; @BindView(R.id.about_email) TextView mEmailTV; @BindView(R.id.about_rate_us) View mRateUs; + private static Resources mRes; @Override diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java index 3c9444977..922d3fd93 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java @@ -38,6 +38,9 @@ public class DayActivity extends AppCompatActivity @BindView(R.id.day_events) ListView mEventsList; @BindView(R.id.day_coordinator) CoordinatorLayout mCoordinatorLayout; + private static final int EDIT_EVENT = 1; + public static final String DELETED_ID = "deleted_id"; + private static String mDayCode; private static List mEvents; private static int mSelectedItemsCnt; @@ -85,7 +88,7 @@ public class DayActivity extends AppCompatActivity private void editEvent(Event event) { final Intent intent = new Intent(getApplicationContext(), EventActivity.class); intent.putExtra(Constants.EVENT, event); - startActivity(intent); + startActivityForResult(intent, EDIT_EVENT); } private void checkEvents() { @@ -96,17 +99,33 @@ public class DayActivity extends AppCompatActivity private void updateEvents(List events) { mEvents = new ArrayList<>(events); + final List eventsToShow = getEventsToShow(events); + final EventsAdapter adapter = new EventsAdapter(this, eventsToShow); + mEventsList.setAdapter(adapter); + mEventsList.setOnItemClickListener(this); + mEventsList.setMultiChoiceModeListener(this); + } + + private List getEventsToShow(List events) { final int cnt = events.size(); for (int i = cnt - 1; i >= 0; i--) { if (mToBeDeleted.contains(events.get(i).getId())) { events.remove(i); } } + return events; + } - final EventsAdapter adapter = new EventsAdapter(this, events); - mEventsList.setAdapter(adapter); - mEventsList.setOnItemClickListener(this); - mEventsList.setMultiChoiceModeListener(this); + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == EDIT_EVENT && resultCode == RESULT_OK && data != null) { + final int deletedId = data.getIntExtra(DELETED_ID, -1); + if (deletedId != -1) { + mToBeDeleted.clear(); + mToBeDeleted.add(deletedId); + notifyEventDeletion(1); + } + } } @Override @@ -166,7 +185,7 @@ public class DayActivity extends AppCompatActivity @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - editEvent(mEvents.get(position)); + editEvent(getEventsToShow(mEvents).get(position)); } @Override diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java index 674b9b1df..2acb897bc 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java @@ -38,9 +38,9 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera @BindView(R.id.event_title) EditText mTitleET; @BindView(R.id.event_description) EditText mDescriptionET; - private DateTime mEventStartDateTime; - private DateTime mEventEndDateTime; - private Event mEvent; + private static DateTime mEventStartDateTime; + private static DateTime mEventEndDateTime; + private static Event mEvent; @Override protected void onCreate(Bundle savedInstanceState) { @@ -113,7 +113,10 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera } private void deleteEvent() { - DBHelper.newInstance(getApplicationContext(), this).deleteEvent(mEvent.getId()); + final Intent intent = new Intent(); + intent.putExtra(DayActivity.DELETED_ID, mEvent.getId()); + setResult(RESULT_OK, intent); + finish(); } private void saveEvent() { @@ -246,7 +249,7 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera @Override public void eventsDeleted(int cnt) { - finish(); + } @Override