allow Undeleting events deleted from Events screen
This commit is contained in:
parent
df363403d0
commit
be0126dcb6
|
@ -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
|
||||
|
|
|
@ -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<Event> 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<Event> 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();
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue