Skip to content

Commit

Permalink
Add ability to edit event status (#71, #201)
Browse files Browse the repository at this point in the history
 - 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`.
  • Loading branch information
MathieuSchopfer committed Nov 9, 2020
1 parent 945db67 commit dd9d8f8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 12 deletions.
29 changes: 29 additions & 0 deletions res/layout/edit_event_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dip"
android:layout_marginBottom="4dip"
android:gravity="center_vertical"
android:minHeight="24dip"
android:orientation="horizontal">
Expand All @@ -300,6 +301,33 @@
</LinearLayout>

<!-- TIME ZONE - Read-only textview version -->

<LinearLayout
android:id="@+id/event_status_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="64dip"
android:orientation="vertical">

<TextView
android:id="@+id/event_status_label"
style="@style/TextAppearance.EditEvent_LabelSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/edit_event_status_label" />

<Spinner
android:id="@+id/event_status"
style="@style/TextAppearance.EditEvent_Spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/event_status"
android:minHeight="48dip"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:spinnerMode="dropdown" />
</LinearLayout>

<LinearLayout
android:id="@+id/timezone_textview_row"
android:layout_width="match_parent"
Expand Down Expand Up @@ -338,4 +366,5 @@

<View
style="@style/EditEventSeparator"/>

</LinearLayout>
9 changes: 8 additions & 1 deletion res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,20 @@
<item>Tentative</item>
</string-array>

<!-- This maps reminder_methods_labels to internal constants. -->
<!-- This maps 'availability' to internal constants. -->
<integer-array name="availability_values" translatable="false">
<item>0</item> <!-- Busy -->
<item>1</item> <!-- Available -->
<item>2</item> <!-- Tentative -->
</integer-array>

<!-- CalendarContract.EventsColumns#STATUS -->
<string-array name="event_status" translatable="false">
<item>@string/event_status_tentative</item> <!-- 0 -->
<item>@string/event_status_confirmed</item> <!-- 1 -->
<item>@string/event_status_cancelled</item> <!-- 2 -->
</string-array>

<string-array name="visibility" translatable="false">
<item>@string/visibility_default</item>
<item>@string/visibility_confidential</item>
Expand Down
7 changes: 7 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@
<string name="edit_event_from_label">From</string>
<!-- Check box label that specifies if this is an all-day event -->
<string name="edit_event_all_day_label">All day</string>
<!-- Spinner that shows the possible event status -->
<string name="edit_event_status_label">Status</string>
<!-- Label for choosing one of the calendars -->
<string name="edit_event_calendar_label">Calendar</string>
<!-- Menu item to show all choices [CHAR LIMIT=22]-->
Expand Down Expand Up @@ -731,6 +733,11 @@
<string name="user_rejected_calendar_write_permission">Etar requires calendar read and write permissions to work properly. Please try again.</string>
<string name="calendar_permission_not_granted">Required permissions were denied, enable them from Settings app to edit events</string>

<!-- Strings describing an event status -->
<string name="event_status_tentative">Tentative</string>
<string name="event_status_confirmed">Confirmed</string>
<string name="event_status_cancelled">Cancelled</string>

<!-- Strings to describe visibility array -->
<string name="visibility_default">Default</string>
<string name="visibility_confidential">Confidential</string>
Expand Down
6 changes: 4 additions & 2 deletions src/com/android/calendar/CalendarEventModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReminderEntry> mReminders;
public ArrayList<ReminderEntry> mDefaultReminders;
// PROVIDER_NOTES Using EditEventHelper the owner should not be included in this
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/com/android/calendar/event/EditEventFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,7 @@ private static class EventBundle implements Serializable {
long end = -1;
}

// TODO turn this into a helper function in EditEventHelper for building the
// model
// TODO turn this into a helper function in EditEventHelper for building the model
private class QueryHandler extends AsyncQueryHandler {
public QueryHandler(ContentResolver cr) {
super(cr);
Expand Down
5 changes: 2 additions & 3 deletions src/com/android/calendar/event/EditEventHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ public boolean saveEvent(CalendarEventModel model, CalendarEventModel originalMo
ArrayList<ReminderEntry> 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);
Expand Down Expand Up @@ -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()) {
Expand Down
29 changes: 25 additions & 4 deletions src/com/android/calendar/event/EditEventView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,6 +209,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<String> mEventStatusLabels;
private ArrayAdapter<String> mEventStatusAdapter;
private int mDefaultReminderMinutes;
private boolean mSaveAfterQueryComplete = false;
private TimeZonePickerUtils mTzPickerUtils;
Expand Down Expand Up @@ -258,6 +266,7 @@ public void onClick(View v) {
mAllDayCheckBox = (CheckBox) 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);
mCalendarSelectorWrapper = view.findViewById(R.id.calendar_selector_wrapper);
Expand Down Expand Up @@ -309,8 +318,7 @@ public void onItemSelected(AdapterView<?> parent,
mAvailabilityCurrentlySelected = position;
}

if (mAvailabilityCurrentlySelected != position &&
!mAllDayChangingAvailability) {
if (mAvailabilityCurrentlySelected != position && !mAllDayChangingAvailability) {
mAvailabilityExplicitlySet = true;
} else {
mAvailabilityCurrentlySelected = position;
Expand Down Expand Up @@ -339,6 +347,7 @@ public void onNothingSelected(AdapterView<?> arg0) {
mViewOnlyList.add(view.findViewById(R.id.timezone_textview_row));

mEditOnlyList.add(view.findViewById(R.id.all_day_row));
mEditOnlyList.add(view.findViewById(R.id.event_status_row));
mEditOnlyList.add(view.findViewById(R.id.availability_row));
mEditOnlyList.add(view.findViewById(R.id.visibility_row));
mEditOnlyList.add(view.findViewById(R.id.from_row));
Expand Down Expand Up @@ -691,8 +700,8 @@ private boolean fillModelFromUI() {
mModel.mTimezone = mTimezone;
mModel.mAccessLevel = mAccessLevelSpinner.getSelectedItemPosition();
// TODO set correct availability value
mModel.mAvailability = mAvailabilityValues.get(mAvailabilitySpinner
.getSelectedItemPosition());
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
Expand Down Expand Up @@ -735,6 +744,16 @@ private void prepareAvailability() {
mAvailabilitySpinner.setAdapter(mAvailabilityAdapter);
}

private void prepareEventStatus() {
Resources r = mActivity.getResources();
mEventStatusLabels = loadStringArray(r, R.array.event_status);
mEventStatusAdapter = new ArrayAdapter<String>(
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.
* <p>
Expand Down Expand Up @@ -887,6 +906,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

prepareReminders();
prepareAvailability();
prepareEventStatus();
prepareAccess();

View reminderAddButton = mView.findViewById(R.id.reminder_add);
Expand Down Expand Up @@ -933,6 +953,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);
Expand Down

0 comments on commit dd9d8f8

Please sign in to comment.