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

Commit f56b1497 authored by James Kung's avatar James Kung
Browse files

Adding init state booleans for int color variables

Change-Id: I5b4eb3e4f9180df4685b9ec11c6009464a719ab5
parent 140ebd20
Loading
Loading
Loading
Loading
+46 −3
Original line number Diff line number Diff line
@@ -201,7 +201,8 @@ public class CalendarEventModel implements Serializable {
    public long mId = -1;
    public long mCalendarId = -1;
    public String mCalendarDisplayName = ""; // Make sure this is in sync with the mCalendarId
    public int mCalendarColor = 0;
    private int mCalendarColor = -1;
    private boolean mCalendarColorInitialized = false;
    public String mCalendarAccountName;
    public String mCalendarAccountType;
    public int mCalendarMaxReminders;
@@ -214,7 +215,8 @@ public class CalendarEventModel implements Serializable {
    public String mSyncAccountType = null;

    public EventColorCache mEventColorCache;
    public int mEventColor = -1;
    private int mEventColor = -1;
    private boolean mEventColorInitialized = false;

    // PROVIDER_NOTES owner account comes from the calendars table
    public String mOwnerAccount = null;
@@ -386,6 +388,12 @@ public class CalendarEventModel implements Serializable {
        mUri = null;
        mId = -1;
        mCalendarId = -1;
        mCalendarColor = -1;
        mCalendarColorInitialized = false;

        mEventColorCache = null;
        mEventColor = -1;
        mEventColorInitialized = false;

        mSyncId = null;
        mSyncAccount = null;
@@ -712,7 +720,12 @@ public class CalendarEventModel implements Serializable {
        if (mCalendarId != originalModel.mCalendarId) {
            return false;
        }

        if (mCalendarColor != originalModel.mCalendarColor) {
            return false;
        }
        if (mCalendarColorInitialized != originalModel.mCalendarColorInitialized) {
            return false;
        }
        if (mGuestsCanInviteOthers != originalModel.mGuestsCanInviteOthers) {
            return false;
        }
@@ -854,6 +867,10 @@ public class CalendarEventModel implements Serializable {
            return false;
        }

        if (mEventColorInitialized != originalModel.mEventColorInitialized) {
            return false;
        }

        return true;
    }

@@ -884,6 +901,32 @@ public class CalendarEventModel implements Serializable {
        return true;
    }

    public boolean isCalendarColorInitialized() {
        return mCalendarColorInitialized;
    }

    public boolean isEventColorInitialized() {
        return mEventColorInitialized;
    }

    public int getCalendarColor() {
        return mCalendarColor;
    }

    public int getEventColor() {
        return mEventColor;
    }

    public void setCalendarColor(int color) {
        mCalendarColor = color;
        mCalendarColorInitialized = true;
    }

    public void setEventColor(int color) {
        mEventColor = color;
        mEventColorInitialized = true;
    }

    public int[] getCalendarEventColors() {
        if (mEventColorCache != null) {
            return mEventColorCache.getColorArray(mCalendarAccountName, mCalendarAccountType);
+22 −3
Original line number Diff line number Diff line
@@ -130,8 +130,11 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
    protected static final String BUNDLE_KEY_DELETE_DIALOG_VISIBLE = "key_delete_dialog_visible";
    protected static final String BUNDLE_KEY_WINDOW_STYLE = "key_window_style";
    protected static final String BUNDLE_KEY_CALENDAR_COLOR = "key_calendar_color";
    protected static final String BUNDLE_KEY_CALENDAR_COLOR_INIT = "key_calendar_color_init";
    protected static final String BUNDLE_KEY_CURRENT_COLOR = "key_current_color";
    protected static final String BUNDLE_KEY_CURRENT_COLOR_INIT = "key_current_color_init";
    protected static final String BUNDLE_KEY_ORIGINAL_COLOR = "key_original_color";
    protected static final String BUNDLE_KEY_ORIGINAL_COLOR_INIT = "key_original_color_init";
    protected static final String BUNDLE_KEY_ATTENDEE_RESPONSE = "key_attendee_response";
    protected static final String BUNDLE_KEY_USER_SET_ATTENDEE_RESPONSE =
            "key_user_set_attendee_response";
@@ -359,8 +362,11 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
    private SparseIntArray mDisplayColorKeyMap = new SparseIntArray();
    private int[] mColors;
    private int mOriginalColor = -1;
    private boolean mOriginalColorInitialized = false;
    private int mCalendarColor = -1;
    private boolean mCalendarColorInitialized = false;
    private int mCurrentColor = -1;
    private boolean mCurrentColorInitialized = false;

    private static final int FADE_IN_TIME = 300;   // in milliseconds
    private static final int LOADING_MSG_DELAY = 600;   // in milliseconds
@@ -462,19 +468,22 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
                    activity.finish();
                    return;
                }
                if (mCalendarColor == -1) {
                if (!mCalendarColorInitialized) {
                    mCalendarColor = Utils.getDisplayColorFromColor(
                            mEventCursor.getInt(EVENT_INDEX_CALENDAR_COLOR));
                    mCalendarColorInitialized = true;
                }

                if (mOriginalColor == -1) {
                if (!mOriginalColorInitialized) {
                    mOriginalColor = mEventCursor.isNull(EVENT_INDEX_EVENT_COLOR)
                            ? mCalendarColor : Utils.getDisplayColorFromColor(
                                    mEventCursor.getInt(EVENT_INDEX_EVENT_COLOR));
                    mOriginalColorInitialized = true;
                }

                if (mCurrentColor == -1) {
                if (!mCurrentColorInitialized) {
                    mCurrentColor = mOriginalColor;
                    mCurrentColorInitialized = true;
                }

                updateEvent(mView);
@@ -842,8 +851,14 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
            mDeleteDialogVisible =
                savedInstanceState.getBoolean(BUNDLE_KEY_DELETE_DIALOG_VISIBLE,false);
            mCalendarColor = savedInstanceState.getInt(BUNDLE_KEY_CALENDAR_COLOR);
            mCalendarColorInitialized =
                    savedInstanceState.getBoolean(BUNDLE_KEY_CALENDAR_COLOR_INIT);
            mOriginalColor = savedInstanceState.getInt(BUNDLE_KEY_ORIGINAL_COLOR);
            mOriginalColorInitialized = savedInstanceState.getBoolean(
                    BUNDLE_KEY_ORIGINAL_COLOR_INIT);
            mCurrentColor = savedInstanceState.getInt(BUNDLE_KEY_CURRENT_COLOR);
            mCurrentColorInitialized = savedInstanceState.getBoolean(
                    BUNDLE_KEY_CURRENT_COLOR_INIT);

            mTentativeUserSetResponse = savedInstanceState.getInt(
                            BUNDLE_KEY_TENTATIVE_USER_RESPONSE,
@@ -1127,8 +1142,12 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
        outState.putInt(BUNDLE_KEY_WINDOW_STYLE, mWindowStyle);
        outState.putBoolean(BUNDLE_KEY_DELETE_DIALOG_VISIBLE, mDeleteDialogVisible);
        outState.putInt(BUNDLE_KEY_CALENDAR_COLOR, mCalendarColor);
        outState.putBoolean(BUNDLE_KEY_CALENDAR_COLOR_INIT, mCalendarColorInitialized);
        outState.putInt(BUNDLE_KEY_ORIGINAL_COLOR, mOriginalColor);
        outState.putBoolean(BUNDLE_KEY_ORIGINAL_COLOR_INIT, mOriginalColorInitialized);
        outState.putInt(BUNDLE_KEY_CURRENT_COLOR, mCurrentColor);
        outState.putBoolean(BUNDLE_KEY_CURRENT_COLOR_INIT, mCurrentColorInitialized);

        // We'll need the temporary response for configuration changes.
        outState.putInt(BUNDLE_KEY_TENTATIVE_USER_RESPONSE, mTentativeUserSetResponse);
        if (mTentativeUserSetResponse != Attendees.ATTENDEE_STATUS_NONE &&
+6 −2
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ public class EditEventActivity extends AbstractCalendarActivity {

    private int mEventColor;

    private boolean mEventColorInitialized;

    private EventInfo mEventInfo;

    @Override
@@ -67,8 +69,10 @@ public class EditEventActivity extends AbstractCalendarActivity {

        mEventInfo = getEventInfoFromIntent(icicle);
        mReminders = getReminderEntriesFromIntent();
        mEventColorInitialized = getIntent().hasExtra(EXTRA_EVENT_COLOR);
        mEventColor = getIntent().getIntExtra(EXTRA_EVENT_COLOR, -1);


        mEditFragment = (EditEventFragment) getFragmentManager().findFragmentById(R.id.main_frame);

        mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config);
@@ -93,8 +97,8 @@ public class EditEventActivity extends AbstractCalendarActivity {
                intent = getIntent();
            }

            mEditFragment = new EditEventFragment(mEventInfo, mReminders, mEventColor,
                    false, intent);
            mEditFragment = new EditEventFragment(mEventInfo, mReminders, mEventColorInitialized,
                    mEventColor, false, intent);

            mEditFragment.mShowModifyDialogOnLaunch = getIntent().getBooleanExtra(
                    CalendarController.EVENT_EDIT_ON_LAUNCH, false);
+18 −15
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
    private EventBundle mEventBundle;
    private ArrayList<ReminderEntry> mReminders;
    private int mEventColor;
    private boolean mEventColorInitialized = false;
    private Uri mUri;
    private long mBegin;
    private long mEnd;
@@ -186,8 +187,8 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                    mModel.mIsFirstEventInSeries = mBegin == mOriginalModel.mStart;
                    mModel.mStart = mBegin;
                    mModel.mEnd = mEnd;
                    if (mEventColor != -1) {
                        mModel.mEventColor = mEventColor;
                    if (mEventColorInitialized) {
                        mModel.setEventColor(mEventColor);
                    }
                    eventId = mModel.mId;

@@ -368,12 +369,12 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
        public void onClick(View v) {
            int[] colors = mModel.getCalendarEventColors();
            if (mDialog == null) {
                mDialog = EventColorPickerDialog.newInstance(colors, mModel.mEventColor,
                        mModel.mCalendarColor, mView.mIsMultipane);
                mDialog = EventColorPickerDialog.newInstance(colors, mModel.getEventColor(),
                        mModel.getCalendarColor(), mView.mIsMultipane);
                mDialog.setTargetFragment(EditEventFragment.this, REQUEST_CODE_COLOR_PICKER);
            } else {
                mDialog.setCalendarColor(mModel.mCalendarColor);
                mDialog.setColors(colors, mModel.mEventColor);
                mDialog.setCalendarColor(mModel.getCalendarColor());
                mDialog.setColors(colors, mModel.getEventColor());
            }
            if (!mDialog.isAdded()) {
                mDialog.show(getFragmentManager(), TAG);
@@ -403,18 +404,20 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
    }

    public EditEventFragment() {
        this(null, null, -1, false, null);
        this(null, null, false, -1, false, null);
    }

    public EditEventFragment(EventInfo event, ArrayList<ReminderEntry> reminders, int eventColor,
            boolean readOnly, Intent intent) {
    public EditEventFragment(EventInfo event, ArrayList<ReminderEntry> reminders,
            boolean eventColorInitialized, int eventColor, boolean readOnly, Intent intent) {
        mEvent = event;
        mIsReadOnly = readOnly;
        mIntent = intent;

        mReminders = reminders;
        mEventColorInitialized = eventColorInitialized;
        if (eventColorInitialized) {
            mEventColor = eventColor;

        }
        setHasOptionsMenu(true);
    }

@@ -452,8 +455,8 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
            mModel.mReminders = mReminders;
        }

        if (mEventColor != -1) {
            mModel.mEventColor = mEventColor;
        if (mEventColorInitialized) {
            mModel.setEventColor(mEventColor);
        }

        if (mBegin <= 0) {
@@ -921,8 +924,8 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor

    @Override
    public void onColorSelected(int color) {
        if (mModel.mEventColor != color) {
            mModel.mEventColor = color;
        if (!mModel.isEventColorInitialized() || mModel.getEventColor() != color) {
            mModel.setEventColor(color);
            mView.updateHeadlineColor(mModel, color);
        }
    }
+9 −8
Original line number Diff line number Diff line
@@ -1075,7 +1075,7 @@ public class EditEventHelper {
        } else {
            rawEventColor = cursor.getInt(EVENT_INDEX_EVENT_COLOR);
        }
        model.mEventColor = Utils.getDisplayColorFromColor(rawEventColor);
        model.setEventColor(Utils.getDisplayColorFromColor(rawEventColor));

        if (accessLevel > 0) {
            // For now the array contains the values 0, 2, and 3. We subtract
@@ -1133,8 +1133,8 @@ public class EditEventHelper {

            model.mCalendarAccessLevel = cursor.getInt(CALENDARS_INDEX_ACCESS_LEVEL);
            model.mCalendarDisplayName = cursor.getString(CALENDARS_INDEX_DISPLAY_NAME);
            model.mCalendarColor = Utils.getDisplayColorFromColor(
                    cursor.getInt(CALENDARS_INDEX_COLOR));
            model.setCalendarColor(Utils.getDisplayColorFromColor(
                    cursor.getInt(CALENDARS_INDEX_COLOR)));

            model.mCalendarAccountName = cursor.getString(CALENDARS_INDEX_ACCOUNT_NAME);
            model.mCalendarAccountType = cursor.getString(CALENDARS_INDEX_ACCOUNT_TYPE);
@@ -1285,12 +1285,13 @@ public class EditEventHelper {
        }
        values.put(Events.ACCESS_LEVEL, accessLevel);
        values.put(Events.STATUS, model.mEventStatus);
        if (model.mEventColor == -1 || model.mEventColor == model.mCalendarColor) {
        if (model.isEventColorInitialized()) {
            if (model.getEventColor() == model.getCalendarColor()) {
                values.put(Events.EVENT_COLOR_KEY, NO_EVENT_COLOR);
            } else {
                values.put(Events.EVENT_COLOR_KEY, model.getEventColorKey());
            }

        }
        return values;
    }

Loading