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 Dec 1, 2020
1 parent ded9895 commit 1d92106
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 7 deletions.
14 changes: 14 additions & 0 deletions res/drawable/ic_outline_verified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M23,11.99l-2.44,-2.79l0.34,-3.69l-3.61,-0.82L15.4,1.5L12,2.96L8.6,1.5L6.71,4.69L3.1,5.5L3.44,9.2L1,11.99l2.44,2.79l-0.34,3.7l3.61,0.82L8.6,22.5l3.4,-1.47l3.4,1.46l1.89,-3.19l3.61,-0.82l-0.34,-3.69L23,11.99zM19.05,13.47l-0.56,0.65l0.08,0.85l0.18,1.95l-1.9,0.43l-0.84,0.19l-0.44,0.74l-0.99,1.68l-1.78,-0.77L12,18.85l-0.79,0.34l-1.78,0.77l-0.99,-1.67l-0.44,-0.74l-0.84,-0.19l-1.9,-0.43l0.18,-1.96l0.08,-0.85l-0.56,-0.65l-1.29,-1.47l1.29,-1.48l0.56,-0.65L5.43,9.01L5.25,7.07l1.9,-0.43l0.84,-0.19l0.44,-0.74l0.99,-1.68l1.78,0.77L12,5.14l0.79,-0.34l1.78,-0.77l0.99,1.68l0.44,0.74l0.84,0.19l1.9,0.43l-0.18,1.95l-0.08,0.85l0.56,0.65l1.29,1.47L19.05,13.47z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M10.09,13.75l-2.32,-2.33l-1.48,1.49l3.8,3.81l7.34,-7.36l-1.48,-1.49z"/>
</vector>
35 changes: 34 additions & 1 deletion res/layout/edit_event_all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand All @@ -627,6 +626,40 @@
app:layout_constraintStart_toEndOf="@+id/visibility_icon"
app:layout_constraintTop_toTopOf="@+id/visibility_icon" />

<View
android:id="@+id/view8"
style="@style/EditEventSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/visibility_icon" />

<!-- Event status -->
<ImageView
android:id="@+id/event_status_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:src="@drawable/ic_outline_verified"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view8"
app:layout_constraintBottom_toBottomOf="parent" />
<Spinner
android:id="@+id/event_status"
style="@style/TextAppearance.EditEvent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="32dp"
android:contentDescription="@string/accessibility_event_status"
android:entries="@array/event_status"
android:prompt="@string/edit_event_status_label"
app:layout_constraintStart_toEndOf="@+id/event_status_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/event_status_icon"
app:layout_constraintBottom_toBottomOf="@+id/event_status_icon" />

</androidx.constraintlayout.widget.ConstraintLayout>

<!-- WHEN - Read-only textview version of FROM/TO (below) -->
Expand Down
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
9 changes: 9 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@
<skip/>
<!-- 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 @@ -609,6 +611,8 @@
<!-- Mark this event as an "all day event" [CHAR LIMIT = NONE]-->
<string name="accessibility_all_day">All day event</string>
<!-- Refresh the data in the calendar [CHAR LIMIT = NONE]-->
<!-- Set an event status (tentative, confirmed, or cancelled) -->
<string name="accessibility_event_status">Event status</string>

<!-- Choose the type of repetition for the event (daily, weekly, etc.[CHAR LIMIT = NONE]-->
<!-- Set the time for the reminder[CHAR LIMIT = NONE]-->
Expand Down Expand Up @@ -708,6 +712,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
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
22 changes: 22 additions & 0 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 @@ -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<String> mEventStatusLabels;
private ArrayAdapter<String> mEventStatusAdapter;
private int mDefaultReminderMinutes;
private boolean mSaveAfterQueryComplete = false;
private TimeZonePickerUtils mTzPickerUtils;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<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 @@ -876,6 +896,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

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

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

0 comments on commit 1d92106

Please sign in to comment.