allow Undeleting events deleted from Events screen

This commit is contained in:
tibbi 2016-07-05 12:59:50 +02:00
parent df363403d0
commit be0126dcb6
3 changed files with 34 additions and 11 deletions

View File

@ -26,6 +26,7 @@ public class AboutActivity extends AppCompatActivity {
@BindView(R.id.about_version) TextView mVersion; @BindView(R.id.about_version) TextView mVersion;
@BindView(R.id.about_email) TextView mEmailTV; @BindView(R.id.about_email) TextView mEmailTV;
@BindView(R.id.about_rate_us) View mRateUs; @BindView(R.id.about_rate_us) View mRateUs;
private static Resources mRes; private static Resources mRes;
@Override @Override

View File

@ -38,6 +38,9 @@ public class DayActivity extends AppCompatActivity
@BindView(R.id.day_events) ListView mEventsList; @BindView(R.id.day_events) ListView mEventsList;
@BindView(R.id.day_coordinator) CoordinatorLayout mCoordinatorLayout; @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 String mDayCode;
private static List<Event> mEvents; private static List<Event> mEvents;
private static int mSelectedItemsCnt; private static int mSelectedItemsCnt;
@ -85,7 +88,7 @@ public class DayActivity extends AppCompatActivity
private void editEvent(Event event) { private void editEvent(Event event) {
final Intent intent = new Intent(getApplicationContext(), EventActivity.class); final Intent intent = new Intent(getApplicationContext(), EventActivity.class);
intent.putExtra(Constants.EVENT, event); intent.putExtra(Constants.EVENT, event);
startActivity(intent); startActivityForResult(intent, EDIT_EVENT);
} }
private void checkEvents() { private void checkEvents() {
@ -96,17 +99,33 @@ public class DayActivity extends AppCompatActivity
private void updateEvents(List<Event> events) { private void updateEvents(List<Event> events) {
mEvents = new ArrayList<>(events); mEvents = new ArrayList<>(events);
final List<Event> eventsToShow = getEventsToShow(events);
final EventsAdapter adapter = new EventsAdapter(this, eventsToShow);
mEventsList.setAdapter(adapter);
mEventsList.setOnItemClickListener(this);
mEventsList.setMultiChoiceModeListener(this);
}
private List<Event> getEventsToShow(List<Event> events) {
final int cnt = events.size(); final int cnt = events.size();
for (int i = cnt - 1; i >= 0; i--) { for (int i = cnt - 1; i >= 0; i--) {
if (mToBeDeleted.contains(events.get(i).getId())) { if (mToBeDeleted.contains(events.get(i).getId())) {
events.remove(i); events.remove(i);
} }
} }
return events;
}
final EventsAdapter adapter = new EventsAdapter(this, events); @Override
mEventsList.setAdapter(adapter); protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mEventsList.setOnItemClickListener(this); if (requestCode == EDIT_EVENT && resultCode == RESULT_OK && data != null) {
mEventsList.setMultiChoiceModeListener(this); final int deletedId = data.getIntExtra(DELETED_ID, -1);
if (deletedId != -1) {
mToBeDeleted.clear();
mToBeDeleted.add(deletedId);
notifyEventDeletion(1);
}
}
} }
@Override @Override
@ -166,7 +185,7 @@ public class DayActivity extends AppCompatActivity
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
editEvent(mEvents.get(position)); editEvent(getEventsToShow(mEvents).get(position));
} }
@Override @Override

View File

@ -38,9 +38,9 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera
@BindView(R.id.event_title) EditText mTitleET; @BindView(R.id.event_title) EditText mTitleET;
@BindView(R.id.event_description) EditText mDescriptionET; @BindView(R.id.event_description) EditText mDescriptionET;
private DateTime mEventStartDateTime; private static DateTime mEventStartDateTime;
private DateTime mEventEndDateTime; private static DateTime mEventEndDateTime;
private Event mEvent; private static Event mEvent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -113,7 +113,10 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera
} }
private void deleteEvent() { 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() { private void saveEvent() {
@ -246,7 +249,7 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera
@Override @Override
public void eventsDeleted(int cnt) { public void eventsDeleted(int cnt) {
finish();
} }
@Override @Override