diff --git a/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java b/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java index 738b03e46..849c77868 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java +++ b/app/src/main/java/com/simplemobiletools/calendar/CalendarImpl.java @@ -116,6 +116,11 @@ public class CalendarImpl implements DBHelper.DBOperationsListener { } + @Override + public void eventsDeleted() { + + } + @Override public void gotEvents(List events) { mEvents = events; diff --git a/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java b/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java index d77b88726..fa4748401 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java +++ b/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java @@ -74,6 +74,19 @@ public class DBHelper extends SQLiteOpenHelper { return values; } + public void deleteEvent(int id) { + final String selection = COL_ID + " = ?"; + final String[] selectionArgs = {String.valueOf(id)}; + mDb.delete(TABLE_NAME, selection, selectionArgs); + mCallback.eventsDeleted(); + } + + public void deleteEvents(String[] ids) { + final String selection = COL_ID + " IN (?)"; + mDb.delete(TABLE_NAME, selection, ids); + mCallback.eventsDeleted(); + } + public void getEvents(int fromTS, int toTS) { final String[] projection = {COL_ID, COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION}; List events = new ArrayList<>(); @@ -101,6 +114,8 @@ public class DBHelper extends SQLiteOpenHelper { void eventUpdated(); + void eventsDeleted(); + void gotEvents(List events); } } 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 eebc640dd..33a8ecc02 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java @@ -3,7 +3,13 @@ package com.simplemobiletools.calendar.activities; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.SparseBooleanArray; +import android.view.ActionMode; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; @@ -15,18 +21,21 @@ import com.simplemobiletools.calendar.Formatter; import com.simplemobiletools.calendar.R; import com.simplemobiletools.calendar.models.Event; +import java.util.ArrayList; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -public class DayActivity extends AppCompatActivity implements DBHelper.DBOperationsListener, AdapterView.OnItemClickListener { +public class DayActivity extends AppCompatActivity + implements DBHelper.DBOperationsListener, AdapterView.OnItemClickListener, AbsListView.MultiChoiceModeListener { @BindView(R.id.day_date) TextView mDateTV; @BindView(R.id.day_events) ListView mEventsList; private static String mDayCode; private static List mEvents; + private static int mSelectedItemsCnt; @Override protected void onCreate(Bundle savedInstanceState) { @@ -75,6 +84,7 @@ public class DayActivity extends AppCompatActivity implements DBHelper.DBOperati final EventsAdapter adapter = new EventsAdapter(this, events); mEventsList.setAdapter(adapter); mEventsList.setOnItemClickListener(this); + mEventsList.setMultiChoiceModeListener(this); mEvents = events; } @@ -88,6 +98,11 @@ public class DayActivity extends AppCompatActivity implements DBHelper.DBOperati } + @Override + public void eventsDeleted() { + checkEvents(); + } + @Override public void gotEvents(List events) { updateEvents(events); @@ -97,4 +112,57 @@ public class DayActivity extends AppCompatActivity implements DBHelper.DBOperati public void onItemClick(AdapterView parent, View view, int position, long id) { editEvent(mEvents.get(position)); } + + @Override + public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { + if (checked) { + mSelectedItemsCnt++; + } else { + mSelectedItemsCnt--; + } + + mode.setTitle(String.valueOf(mSelectedItemsCnt)); + mode.invalidate(); + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + final MenuInflater inflater = mode.getMenuInflater(); + inflater.inflate(R.menu.menu_day_cab, menu); + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return true; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + switch (item.getItemId()) { + case R.id.delete: + deleteEvents(); + mode.finish(); + return true; + default: + return false; + } + } + + private void deleteEvents() { + final List eventIDs = new ArrayList<>(); + final SparseBooleanArray checked = mEventsList.getCheckedItemPositions(); + for (int i = 0; i < mEvents.size(); i++) { + if (checked.get(i)) { + final Event event = mEvents.get(i); + eventIDs.add(String.valueOf(event.getId())); + } + } + DBHelper.newInstance(getApplicationContext(), this).deleteEvents(eventIDs.toArray(new String[eventIDs.size()])); + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + mSelectedItemsCnt = 0; + } } 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 099ece5e2..cb4267058 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/EventActivity.java @@ -85,12 +85,19 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_event, menu); + final MenuItem item = menu.findItem(R.id.delete); + if (mEvent.getId() == 0) { + item.setVisible(false); + } return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.delete: + deleteEvent(); + return true; case R.id.save: saveEvent(); return true; @@ -99,6 +106,10 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera } } + private void deleteEvent() { + DBHelper.newInstance(getApplicationContext(), this).deleteEvent(mEvent.getId()); + } + private void saveEvent() { final String title = mTitleET.getText().toString().trim(); if (title.isEmpty()) { @@ -227,6 +238,11 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera finish(); } + @Override + public void eventsDeleted() { + finish(); + } + @Override public void gotEvents(List events) { diff --git a/app/src/main/res/drawable/event_item_background.xml b/app/src/main/res/drawable/event_item_background.xml new file mode 100644 index 000000000..1dc59bf98 --- /dev/null +++ b/app/src/main/res/drawable/event_item_background.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_day.xml b/app/src/main/res/layout/activity_day.xml index b36e0ca35..136add11c 100644 --- a/app/src/main/res/layout/activity_day.xml +++ b/app/src/main/res/layout/activity_day.xml @@ -17,6 +17,7 @@ android:layout_height="wrap_content" android:layout_marginBottom="@dimen/activity_margin" android:gravity="center_horizontal" + android:paddingTop="@dimen/top_padding" android:text="January 1 1970" android:textSize="@dimen/month_text_size"/> @@ -24,7 +25,8 @@ android:id="@+id/day_events" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_below="@+id/day_date"/> + android:layout_below="@+id/day_date" + android:choiceMode="multipleChoiceModal"/> + + + diff --git a/app/src/main/res/menu/menu_event.xml b/app/src/main/res/menu/menu_event.xml index 24c10c23e..bde3bb334 100644 --- a/app/src/main/res/menu/menu_event.xml +++ b/app/src/main/res/menu/menu_event.xml @@ -1,9 +1,16 @@ + + + diff --git a/app/src/main/res/mipmap-hdpi/delete.png b/app/src/main/res/mipmap-hdpi/delete.png new file mode 100644 index 000000000..f3d2e18b8 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/delete.png differ diff --git a/app/src/main/res/mipmap-mdpi/delete.png b/app/src/main/res/mipmap-mdpi/delete.png new file mode 100644 index 000000000..e66fba7e7 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/delete.png differ diff --git a/app/src/main/res/mipmap-xhdpi/delete.png b/app/src/main/res/mipmap-xhdpi/delete.png new file mode 100644 index 000000000..ca80a3b5a Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/delete.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/delete.png b/app/src/main/res/mipmap-xxhdpi/delete.png new file mode 100644 index 000000000..1595bbcc3 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/delete.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/delete.png b/app/src/main/res/mipmap-xxxhdpi/delete.png new file mode 100644 index 000000000..8d322aa9b Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/delete.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index b9451e4b0..174dbdc8f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,5 +4,5 @@ #ffe27725 @color/colorPrimary #11000000 - #fff3f3f3 + #18000000 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index c723a6d97..ccea70d9a 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -3,6 +3,7 @@ 8dp 40dp 8dp + 8dp 250dp 250dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 24c2f1941..acccfc76d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,6 +4,7 @@ Event Save + Delete Title cannot be empty The event cannot end earlier than it starts Event added successfully