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

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

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

feat: switching calendar for any event

See merge request !69
parents 5812a3fd bc261652
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.text.TextUtils;
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
@@ -205,7 +205,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();
        }
    }
+16 −17
Original line number Diff line number Diff line
@@ -753,12 +753,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,
@@ -770,7 +768,7 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                            mModel.mCalendarAccountName,
                            mModel.mCalendarAccountType
                    );
                    selArgs = new String[]{
                    String[] selArgs = new String[]{
                            Long.toString(eventId)
                    };
                    mHandler.startQuery(TOKEN_EXTENDED, null, extendedPropUri,
@@ -852,16 +850,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, activity);
                            EditEventHelper.setModelFromCalendarCursor(mOriginalModel, cursor, activity);
@@ -960,7 +959,7 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                    && mView.prepareForSave()
                    && !isEmptyNewEvent()
                    && mModel.normalizeReminders()
                    && mHelper.saveEvent(mModel, mOriginalModel, mModification)) {
                    && mHelper.saveEvent(mModel, mOriginalModel, mModification, requireActivity())) {
                int stringResource;
                if (!mModel.mAttendeesList.isEmpty()) {
                    if (mModel.mUri != null) {
+8 −6
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;
@@ -23,7 +24,6 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Colors;
@@ -281,10 +281,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) {
@@ -317,6 +320,8 @@ public class EditEventHelper {
            return false;
        }

        MoveEventHelper.handleMoveEvent(originalModel, model, activity);

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

@@ -841,9 +846,6 @@ public class EditEventHelper {
            return true;
        }

        if (model.mCalendarId != originalModel.mCalendarId) {
            return false;
        }
        if (model.mId != originalModel.mId) {
            return false;
        }
+11 −28
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.calendar.event;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
@@ -641,9 +640,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 (oldCalendarId != selectedCalendar) {
            mModel.mCalendarId = selectedCalendar;
            int calendarCursorPosition = mCalendarsSpinner.getSelectedItemPosition();
            if (mCalendarsCursor.moveToPosition(calendarCursorPosition)) {
                String calendarOwner = mCalendarsCursor.getString(
@@ -1001,21 +1002,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());
        }
@@ -1209,8 +1195,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);
@@ -1241,13 +1227,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