Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6113b08 authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '6417-r-move_event' into 'v1-r'

feat: switching calendar for any event

See merge request !70
parents 00cc857e 0da426ed
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.text.format.Time;
import android.widget.ArrayAdapter;
import android.widget.Button;

import androidx.annotation.NonNull;

import com.android.calendar.event.EditEventHelper;
import com.android.calendar.persistence.CalendarRepository;
import com.android.calendarcommon2.EventRecurrence;
@@ -120,6 +122,7 @@ public class DeleteEventHelper {
            }
        }
    };

    /**
     * This callback is used when an exception to an event is deleted
     */
@@ -136,6 +139,7 @@ public class DeleteEventHelper {
            }
        }
    };

    /**
     * This callback is used when a list item for a repeating event is selected
     */
@@ -163,7 +167,6 @@ public class DeleteEventHelper {
            }
        }
    };

    public DeleteEventHelper(Context context, Activity parentActivity, boolean exitWhenDone) {
        if (exitWhenDone && parentActivity == null) {
            throw new IllegalArgumentException("parentActivity is required to exit when done");
@@ -339,6 +342,20 @@ public class DeleteEventHelper {
        }
    }

    public void delete(@NonNull CalendarEventModel model) {
        deleteStarted();
        long id = model.mId;

        boolean isLocal = model.mSyncAccountType.equals(CalendarContract.ACCOUNT_TYPE_LOCAL);
        Uri deleteContentUri = isLocal ? CalendarRepository.asLocalCalendarSyncAdapter(mModel.mSyncAccountName, Events.CONTENT_URI) : Events.CONTENT_URI;

        Uri uri = ContentUris.withAppendedId(deleteContentUri, id);
        mService.startDelete(mService.getNextToken(), null, uri, null, null, Utils.UNDO_DELAY);
        if (mCallback != null) {
            mCallback.run();
        }
    }

    private void deleteExceptionEvent() {
        long id = mModel.mId; // mCursor.getInt(mEventIndexId);

+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ public class CreateEventDialogFragment extends DialogFragment implements TextWat
        mModel.mCalendarId = mCalendarId;
        mModel.mOwnerAccount = mCalendarOwner;

        if (mEditEventHelper.saveEvent(mModel, null, 0)) {
        if (mEditEventHelper.saveEvent(mModel, null, 0, null)) {
            Toast.makeText(getActivity(), R.string.creating_event, Toast.LENGTH_SHORT).show();
        }
    }
+15 −16
Original line number Diff line number Diff line
@@ -748,12 +748,10 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                    }

                    // TOKEN_CALENDARS
                    String[] selArgs = {
                            Long.toString(mModel.mCalendarId)
                    };
                    mHandler.startQuery(TOKEN_CALENDARS, null, Calendars.CONTENT_URI,
                            EditEventHelper.CALENDARS_PROJECTION, EditEventHelper.CALENDARS_WHERE,
                            selArgs /* selection args */, null /* sort order */);
                            EditEventHelper.CALENDARS_PROJECTION,
                            EditEventHelper.CALENDARS_WHERE_WRITEABLE_VISIBLE, null /* selection args */,
                            null /* sort order */);

                    // TOKEN_COLORS
                    mHandler.startQuery(TOKEN_COLORS, null, Colors.CONTENT_URI,
@@ -835,16 +833,17 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                    break;
                case TOKEN_CALENDARS:
                    try {
                        if (mModel.mId == -1) {
                            // Populate Calendar spinner only if no event id is set.
                        MatrixCursor matrixCursor = Utils.matrixCursorFromCursor(cursor);
                        if (DEBUG) {
                            Log.d(TAG, "onQueryComplete: setting cursor with "
                                    + matrixCursor.getCount() + " calendars");
                        }

                        long selectedCalendarId = mModel.mCalendarId == -1 ? mCalendarId : mModel.mCalendarId;
                        mView.setCalendarsCursor(matrixCursor, isAdded() && isResumed(),
                                    mCalendarId);
                        } else {
                                selectedCalendarId);

                        if (mModel.mId != -1) {
                            // Populate model for an existing event
                            EditEventHelper.setModelFromCalendarCursor(mModel, cursor);
                            EditEventHelper.setModelFromCalendarCursor(mOriginalModel, cursor);
@@ -921,7 +920,7 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                    && mView.prepareForSave()
                    && !isEmptyNewEvent()
                    && mModel.normalizeReminders()
                    && mHelper.saveEvent(mModel, mOriginalModel, mModification)) {
                    && mHelper.saveEvent(mModel, mOriginalModel, mModification, mActivity)) {
                int stringResource;
                if (!mModel.mAttendeesList.isEmpty()) {
                    if (mModel.mUri != null) {
+8 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.calendar.event;

import android.app.Activity;
import android.content.ContentProviderOperation;
import android.content.ContentUris;
import android.content.ContentValues;
@@ -267,10 +268,13 @@ public class EditEventHelper {
     * @param model The event model to save
     * @param originalModel A model of the original event if it exists
     * @param modifyWhich For recurring events which type of series modification to use
     * @param activity is used to handle moving any event to a different calendar
     * @return true if the event was successfully queued for saving
     */
    public boolean saveEvent(CalendarEventModel model, CalendarEventModel originalModel,
            int modifyWhich) {
    public boolean saveEvent(CalendarEventModel model,
                             CalendarEventModel originalModel,
                             int modifyWhich,
                             Activity activity) {
        boolean forceSaveReminders = false;

        if (DEBUG) {
@@ -303,6 +307,8 @@ public class EditEventHelper {
            return false;
        }

        MoveEventHelper.handleMoveEvent(originalModel, model, activity);

        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        int eventIdIndex = -1;

@@ -803,9 +809,6 @@ public class EditEventHelper {
            return true;
        }

        if (model.mCalendarId != originalModel.mCalendarId) {
            return false;
        }
        if (model.mId != originalModel.mId) {
            return false;
        }
+11 −27
Original line number Diff line number Diff line
@@ -629,9 +629,11 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
            mEmailValidator.setRemoveInvalid(false);
        }

        // If this was a new event we need to fill in the Calendar information
        if (mModel.mUri == null) {
            mModel.mCalendarId = mCalendarsSpinner.getSelectedItemId();
        long oldCalendarId = mModel.mCalendarId;
        long selectedCalendar = mCalendarsSpinner.getSelectedItemId();
        // If calendar is changed, we need to fill in the Calendar information
        if (mModel.mUri == null || oldCalendarId != selectedCalendar) {
            mModel.mCalendarId = selectedCalendar;
            int calendarCursorPosition = mCalendarsSpinner.getSelectedItemPosition();
            if (mCalendarsCursor.moveToPosition(calendarCursorPosition)) {
                String calendarOwner = mCalendarsCursor.getString(
@@ -937,21 +939,6 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
            mResponseGroup.setVisibility(View.GONE);
        }

        if (model.mUri != null) {
            // This is an existing event so hide the calendar spinner
            // since we can't change the calendar.
            View calendarGroup = mView.findViewById(R.id.calendar_selector_group);
            calendarGroup.setVisibility(View.VISIBLE);
            TextView tv = (TextView) mView.findViewById(R.id.calendar_textview);
            tv.setText(model.mCalendarDisplayName);
            tv = (TextView) mView.findViewById(R.id.calendar_textview_secondary);
            if (tv != null) {
                tv.setText(model.mOwnerAccount);
            }
        } else {
            View calendarGroup = mView.findViewById(R.id.calendar_group);
            calendarGroup.setVisibility(View.GONE);
        }
        if (model.isEventColorInitialized()) {
            updateHeadlineColor(model.getEventColor());
        }
@@ -1145,8 +1132,8 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
                v.setEnabled(false);
                v.setBackgroundDrawable(null);
            }
            mCalendarSelectorGroup.setVisibility(View.GONE);
            mCalendarStaticGroup.setVisibility(View.VISIBLE);
            mCalendarSelectorGroup.setVisibility(View.VISIBLE);
            mCalendarStaticGroup.setVisibility(View.GONE);
            mRruleButton.setEnabled(false);
            if (EditEventHelper.canAddReminders(mModel)) {
                mRemindersGroup.setVisibility(View.VISIBLE);
@@ -1174,13 +1161,10 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
                            mOriginalPadding[3]);
                }
            }
            if (mModel.mUri == null) {

            mCalendarSelectorGroup.setVisibility(View.VISIBLE);
            mCalendarStaticGroup.setVisibility(View.GONE);
            } else {
                mCalendarSelectorGroup.setVisibility(View.GONE);
                mCalendarStaticGroup.setVisibility(View.VISIBLE);
            }

            if (mModel.mOriginalSyncId == null) {
                mRruleButton.setEnabled(true);
            } else {
Loading