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

Unverified Commit 428242bc authored by Jonas Häusler's avatar Jonas Häusler Committed by Michael Bestas
Browse files

disable changing for api level below 30 for recurring events

Change-Id: I7533d5475f4f0de04efaad6d656a92acecdf868e
parent 0a58401c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public class CalendarEventModel implements Serializable {
    public String mDescription = null;
    public String mUrl = null;
    public String mRrule = null;
    public String exdate = null;
    public String mOrganizer = null;
    public String mOrganizerDisplayName = null;
    /**
+22 −2
Original line number Diff line number Diff line
@@ -752,11 +752,31 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                        setModelIfDone(TOKEN_REMINDERS);
                    }

                    // disable non-synced calendars for recurring events
                    // disable all calendars for recurring events and sdk<30
                    final String selection;
                    final String[] selectionArgs;
                    if (!TextUtils.isEmpty(mModel.mRrule)
                            && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
                        // recurring event, api level < 30. disable changing calendars.
                        selection = EditEventHelper.CALENDARS_WHERE;
                        selectionArgs = new String[] { Long.toString(mModel.mCalendarId) };
                    } else if (!TextUtils.isEmpty(mModel.mRrule)) {
                        // recurring event, api level >= 30. enable changing calendars to synced calendars.
                        selection = EditEventHelper.CALENDARS_WHERE_SYNCED_WRITEABLE_VISIBLE;
                        selectionArgs = null;
                    } else {
                        // non recurring event. enable changing calendars to all calendars.
                        selection = EditEventHelper.CALENDARS_WHERE_WRITEABLE_VISIBLE;
                        selectionArgs = null;
                    }

                    // TOKEN_CALENDARS
                    mHandler.startQuery(TOKEN_CALENDARS, null, Calendars.CONTENT_URI,
                            EditEventHelper.CALENDARS_PROJECTION,
                            EditEventHelper.CALENDARS_WHERE_WRITEABLE_VISIBLE,
                            null /* selection args */, null /* sort order */);
                            selection,
                            selectionArgs,
                            null /* sort order */);

                    // TOKEN_COLORS
                    mHandler.startQuery(TOKEN_COLORS, null, Colors.CONTENT_URI,
+13 −1
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Colors;
@@ -216,6 +218,11 @@ public class EditEventHelper {
    static final String CALENDARS_WHERE_WRITEABLE_VISIBLE = Calendars.CALENDAR_ACCESS_LEVEL + ">="
            + Calendars.CAL_ACCESS_CONTRIBUTOR + " AND " + Calendars.VISIBLE + "=1";

    static final String CALENDARS_WHERE_SYNCED_WRITEABLE_VISIBLE =
            Calendars.CALENDAR_ACCESS_LEVEL + ">=" + Calendars.CAL_ACCESS_CONTRIBUTOR
                    + " AND " + Calendars.VISIBLE + "=1"
                    + " AND " + Calendars.ACCOUNT_TYPE + "!='" + CalendarContract.ACCOUNT_TYPE_LOCAL + "'";

    static final String CALENDARS_WHERE = Calendars._ID + "=?";

    static final String[] COLORS_PROJECTION = new String[] {
@@ -654,6 +661,11 @@ public class EditEventHelper {
                    ContentUris.withAppendedId(Events.CONTENT_URI, model.mId)).build());
        }

        // moving event exceptions is currently ony supported for api level 30 and above
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
            return ops;
        }

        // retrieve events exceptions, create them in target calendar, delete them from source calendar
        try (Cursor cursor = mContextResolver.query(
                Events.CONTENT_URI,
@@ -671,7 +683,7 @@ public class EditEventHelper {

                ops.add(ContentProviderOperation.newInsert(Events.CONTENT_URI)
                        .withValues(values)
                        // TODO: Call requires API level 30
                        // note: this call requires API level 30
                        .withValueBackReference(Events.ORIGINAL_ID, eventIdIndex, Events._ID)
                        .build());