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

Commit 3b942a1d authored by Aayush Gupta's avatar Aayush Gupta Committed by LuK1337
Browse files

MonthByWeekFragment: Don't init loader in certain cases



The new androidx LoaderManager requires to be NonNull. Strip out the cases
that currently returns null and add them as check before initializing the
LoaderManager.

Also switch to androidx methods to get the LoaderManager instance.

Change-Id: I4ea2bdb5bf196af2add4430360ec265184de0a32
Signed-off-by: default avatarAayush Gupta <aayushgupta219@gmail.com>
parent 989af1b8
Loading
Loading
Loading
Loading
+11 −13
Original line number Original line Diff line number Diff line
@@ -137,8 +137,8 @@ public class MonthByWeekFragment extends SimpleDayPickerFragment implements
        @Override
        @Override
        public void run() {
        public void run() {
            if (!mIsDetached) {
            if (!mIsDetached) {
                mLoader = (CursorLoader) getLoaderManager().initLoader(0, null,
                mLoader = (CursorLoader) LoaderManager.getInstance(MonthByWeekFragment.this)
                        MonthByWeekFragment.this);
                        .initLoader(0, null, MonthByWeekFragment.this);
            }
            }
        }
        }
    };
    };
@@ -312,10 +312,13 @@ public class MonthByWeekFragment extends SimpleDayPickerFragment implements


        // To get a smoother transition when showing this fragment, delay loading of events until
        // To get a smoother transition when showing this fragment, delay loading of events until
        // the fragment is expended fully and the calendar controls are gone.
        // the fragment is expended fully and the calendar controls are gone.
        if (!Utils.isCalendarPermissionGranted(mContext, true) && !mIsMiniMonth) {
            if (mShowCalendarControls) {
            if (mShowCalendarControls) {
                mListView.postDelayed(mLoadingRunnable, mEventsLoadingDelay);
                mListView.postDelayed(mLoadingRunnable, mEventsLoadingDelay);
            } else {
            } else {
            mLoader = (CursorLoader) getLoaderManager().initLoader(0, null, this);
                mLoader = (CursorLoader) LoaderManager.getInstance(MonthByWeekFragment.this)
                        .initLoader(0, null, this);
            }
        }
        }
        mAdapter.setListView(mListView);
        mAdapter.setListView(mListView);
    }
    }
@@ -335,11 +338,9 @@ public class MonthByWeekFragment extends SimpleDayPickerFragment implements
    }
    }


    // TODO
    // TODO
    @NonNull
    @Override
    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        if (mIsMiniMonth) {
            return null;
        }
        CursorLoader loader;
        CursorLoader loader;
        synchronized (mUpdateLoader) {
        synchronized (mUpdateLoader) {
            mFirstLoadedJulianDay =
            mFirstLoadedJulianDay =
@@ -348,11 +349,8 @@ public class MonthByWeekFragment extends SimpleDayPickerFragment implements
            mEventUri = updateUri();
            mEventUri = updateUri();
            String where = updateWhere();
            String where = updateWhere();


            if (!Utils.isCalendarPermissionGranted(mContext, true)) {
                return null;
            }
            loader = new CursorLoader(
            loader = new CursorLoader(
                    getActivity(), mEventUri, Event.EVENT_PROJECTION, where,
                    requireActivity(), mEventUri, Event.EVENT_PROJECTION, where,
                    null /* WHERE_CALENDARS_SELECTED_ARGS */, INSTANCES_SORT_ORDER);
                    null /* WHERE_CALENDARS_SELECTED_ARGS */, INSTANCES_SORT_ORDER);
            loader.setUpdateThrottle(LOADER_THROTTLE_DELAY);
            loader.setUpdateThrottle(LOADER_THROTTLE_DELAY);
        }
        }