From 1d9210643b03f98ef04754c79a90687c431e8262 Mon Sep 17 00:00:00 2001 From: Mathieu Schopfer Date: Sat, 16 May 2020 18:06:13 +0200 Subject: [PATCH] Add ability to edit event status (#71, #201) - Add a spinner to the `Edit Event View` to select the event status, one of `CONFIRMED`, `TENTATIVE`, or `CANCELLED`. - Set default status in `Calendar Event Model` to `CONFIRMED`. --- res/drawable/ic_outline_verified.xml | 14 ++++++++ res/layout/edit_event_all.xml | 35 ++++++++++++++++++- res/values/arrays.xml | 9 ++++- res/values/strings.xml | 9 +++++ .../android/calendar/CalendarEventModel.java | 6 ++-- .../calendar/event/EditEventHelper.java | 5 ++- .../android/calendar/event/EditEventView.java | 22 ++++++++++++ 7 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 res/drawable/ic_outline_verified.xml diff --git a/res/drawable/ic_outline_verified.xml b/res/drawable/ic_outline_verified.xml new file mode 100644 index 0000000000..055345974b --- /dev/null +++ b/res/drawable/ic_outline_verified.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/res/layout/edit_event_all.xml b/res/layout/edit_event_all.xml index 9405a86bb6..c48ba97fb5 100644 --- a/res/layout/edit_event_all.xml +++ b/res/layout/edit_event_all.xml @@ -608,7 +608,6 @@ android:layout_marginTop="20dp" android:layout_marginBottom="20dp" android:src="@drawable/ic_outline_lock" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/view6" /> @@ -627,6 +626,40 @@ app:layout_constraintStart_toEndOf="@+id/visibility_icon" app:layout_constraintTop_toTopOf="@+id/visibility_icon" /> + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 8307a7e1b5..3d11d92f3a 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -241,13 +241,20 @@ Tentative - + 0 1 2 + + + @string/event_status_tentative + @string/event_status_confirmed + @string/event_status_cancelled + + @string/visibility_default @string/visibility_confidential diff --git a/res/values/strings.xml b/res/values/strings.xml index c18c6bde3a..0f5cd3c09d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -213,6 +213,8 @@ All day + + Status Calendar @@ -609,6 +611,8 @@ All day event + + Event status @@ -708,6 +712,11 @@ Etar requires calendar read and write permissions to work properly. Please try again. Required permissions were denied, enable them from Settings app to edit events + + Tentative + Confirmed + Cancelled + Default Confidential diff --git a/src/com/android/calendar/CalendarEventModel.java b/src/com/android/calendar/CalendarEventModel.java index 18c3ed188f..c92ada0a79 100644 --- a/src/com/android/calendar/CalendarEventModel.java +++ b/src/com/android/calendar/CalendarEventModel.java @@ -109,7 +109,7 @@ public class CalendarEventModel implements Serializable { // The model can't be updated with a calendar cursor until it has been // updated with an event cursor. public boolean mModelUpdatedWithEventCursor; - public int mAccessLevel = 0; + public int mAccessLevel = Events.ACCESS_DEFAULT; public ArrayList mReminders; public ArrayList mDefaultReminders; // PROVIDER_NOTES Using EditEventHelper the owner should not be included in this @@ -175,6 +175,8 @@ public CalendarEventModel(Context context, Intent intent) { mAccessLevel = accessLevel; } + mEventStatus = intent.getIntExtra(Events.STATUS, Events.STATUS_CONFIRMED); + String rrule = intent.getStringExtra(Events.RRULE); if (!TextUtils.isEmpty(rrule)) { mRrule = rrule; @@ -266,7 +268,7 @@ public void clear() { mGuestsCanModify = false; mGuestsCanInviteOthers = false; mGuestsCanSeeGuests = false; - mAccessLevel = 0; + mAccessLevel = Events.ACCESS_DEFAULT; mEventStatus = Events.STATUS_CONFIRMED; mOrganizerCanRespond = false; mCalendarAccessLevel = Calendars.CAL_ACCESS_CONTRIBUTOR; diff --git a/src/com/android/calendar/event/EditEventHelper.java b/src/com/android/calendar/event/EditEventHelper.java index abeadb7977..34a2121c33 100644 --- a/src/com/android/calendar/event/EditEventHelper.java +++ b/src/com/android/calendar/event/EditEventHelper.java @@ -321,11 +321,11 @@ public boolean saveEvent(CalendarEventModel model, CalendarEventModel originalMo ArrayList reminders = model.mReminders; int len = reminders.size(); values.put(Events.HAS_ALARM, (len > 0) ? 1 : 0); + values.put(Events.STATUS, model.mEventStatus); if (uri == null) { // Add hasAttendeeData for a new event values.put(Events.HAS_ATTENDEE_DATA, 1); - values.put(Events.STATUS, Events.STATUS_CONFIRMED); eventIdIndex = ops.size(); ContentProviderOperation.Builder b = ContentProviderOperation.newInsert( Events.CONTENT_URI).withValues(values); @@ -1284,8 +1284,7 @@ ContentValues getContentValuesFromModel(CalendarEventModel model) { values.put(Events.AVAILABILITY, model.mAvailability); values.put(Events.HAS_ATTENDEE_DATA, model.mHasAttendeeData ? 1 : 0); - int accessLevel = model.mAccessLevel; - values.put(Events.ACCESS_LEVEL, accessLevel); + values.put(Events.ACCESS_LEVEL, model.mAccessLevel); values.put(Events.STATUS, model.mEventStatus); if (model.isEventColorInitialized()) { if (model.getEventColor() == model.getCalendarColor()) { diff --git a/src/com/android/calendar/event/EditEventView.java b/src/com/android/calendar/event/EditEventView.java index e71f5c1412..29a0020e35 100644 --- a/src/com/android/calendar/event/EditEventView.java +++ b/src/com/android/calendar/event/EditEventView.java @@ -145,6 +145,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa Spinner mCalendarsSpinner; Button mRruleButton; Spinner mAvailabilitySpinner; + Spinner mEventStatusSpinner; Spinner mAccessLevelSpinner; RadioGroup mResponseRadioGroup; TextView mTitleTextView; @@ -206,6 +207,13 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa private boolean mAvailabilityExplicitlySet; private boolean mAllDayChangingAvailability; private int mAvailabilityCurrentlySelected; + /** + * Contents of the "status" spinner. Labels indices match the three values constants + * {@link Events#STATUS_TENTATIVE}, {@link Events#STATUS_CONFIRMED}, and + * {@link Events#STATUS_CANCELED}. + */ + private ArrayList mEventStatusLabels; + private ArrayAdapter mEventStatusAdapter; private int mDefaultReminderMinutes; private boolean mSaveAfterQueryComplete = false; private TimeZonePickerUtils mTzPickerUtils; @@ -255,6 +263,7 @@ public void onClick(View v) { mAllDayCheckBox = view.findViewById(R.id.is_all_day); mRruleButton = (Button) view.findViewById(R.id.rrule); mAvailabilitySpinner = (Spinner) view.findViewById(R.id.availability); + mEventStatusSpinner = (Spinner) view.findViewById(R.id.event_status); mAccessLevelSpinner = (Spinner) view.findViewById(R.id.visibility); mCalendarSelectorGroup = view.findViewById(R.id.calendar_selector_group); mCalendarSelectorGroupBackground = view.findViewById(R.id.calendar_selector_group_background); @@ -682,6 +691,7 @@ private boolean fillModelFromUI() { // TODO set correct availability value mModel.mAvailability = mAvailabilityValues.get(mAvailabilitySpinner .getSelectedItemPosition()); + mModel.mEventStatus = mEventStatusSpinner.getSelectedItemPosition(); // rrrule // If we're making an exception we don't want it to be a repeating @@ -724,6 +734,16 @@ private void prepareAvailability() { mAvailabilitySpinner.setAdapter(mAvailabilityAdapter); } + private void prepareEventStatus() { + Resources r = mActivity.getResources(); + mEventStatusLabels = loadStringArray(r, R.array.event_status); + mEventStatusAdapter = new ArrayAdapter( + mActivity, android.R.layout.simple_spinner_item, mEventStatusLabels + ); + mEventStatusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mEventStatusSpinner.setAdapter(mEventStatusAdapter); + } + /** * Prepares the reminder UI elements. *

@@ -876,6 +896,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { prepareReminders(); prepareAvailability(); + prepareEventStatus(); prepareAccess(); View reminderAddButton = mView.findViewById(R.id.reminder_add); @@ -922,6 +943,7 @@ public void onClick(View v) { if (availIndex != -1) { mAvailabilitySpinner.setSelection(availIndex); } + mEventStatusSpinner.setSelection(model.mEventStatus); mAccessLevelSpinner.setSelection(model.mAccessLevel); View responseLabel = mView.findViewById(R.id.response_label);