Skip to content

Commit

Permalink
[WIP] Add ability to edit event status (Etar-Group#71, Etar-Group#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuSchopfer committed Nov 1, 2020
1 parent 945db67 commit be72cc6
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 17 deletions.
2 changes: 1 addition & 1 deletion external/external.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":external" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":external" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Etar-Calendar" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
Expand Down
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">
<item>Tentative</item> <!-- 0 -->
<item>Confirmed</item> <!-- 1 -->
<item>Cancelled</item> <!-- 2 -->
</string-array>

<string-array name="visibility" translatable="false">
<item>@string/visibility_default</item>
<item>@string/visibility_confidential</item>
Expand Down
2 changes: 2 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
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
11 changes: 5 additions & 6 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 Expand Up @@ -750,7 +749,7 @@ protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
while (cursor.moveToNext()) {
String name = cursor.getString(EditEventHelper.ATTENDEES_INDEX_NAME);
String email = cursor.getString(EditEventHelper.ATTENDEES_INDEX_EMAIL);
int status = cursor.getInt(EditEventHelper.ATTENDEES_INDEX_STATUS);
int attendeeStatus = cursor.getInt(EditEventHelper.ATTENDEES_INDEX_STATUS);
int relationship = cursor
.getInt(EditEventHelper.ATTENDEES_INDEX_RELATIONSHIP);
if (relationship == Attendees.RELATIONSHIP_ORGANIZER) {
Expand Down Expand Up @@ -779,14 +778,14 @@ protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
int attendeeId =
cursor.getInt(EditEventHelper.ATTENDEES_INDEX_ID);
mModel.mOwnerAttendeeId = attendeeId;
mModel.mSelfAttendeeStatus = status;
mModel.mSelfAttendeeStatus = attendeeStatus;
mOriginalModel.mOwnerAttendeeId = attendeeId;
mOriginalModel.mSelfAttendeeStatus = status;
mOriginalModel.mSelfAttendeeStatus = attendeeStatus;
continue;
}
}
Attendee attendee = new Attendee(name, email);
attendee.mStatus = status;
attendee.mStatus = attendeeStatus;
mModel.addAttendee(attendee);
mOriginalModel.addAttendee(attendee);
}
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 be72cc6

Please sign in to comment.