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

Commit d91a988a authored by Diksha Gohlyan's avatar Diksha Gohlyan Committed by Android (Google) Code Review
Browse files

Merge "If stale data, forceload values"

parents 52f8d4ed 6117ab1b
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -279,10 +279,11 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {

    @Override
    protected void onStartLoading() {
        if (mResult != null) {
        boolean isCursorStale = checkIfCursorStale(mResult);
        if (mResult != null && !isCursorStale) {
            deliverResult(mResult);
        }
        if (takeContentChanged() || mResult == null) {
        if (takeContentChanged() || mResult == null || isCursorStale) {
            forceLoad();
        }
    }
@@ -311,4 +312,22 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {
        FileUtils.closeQuietly(mResult);
        mResult = null;
    }

    private boolean checkIfCursorStale(DirectoryResult result) {
        if (mResult == null) {
            return true;
        }
        Cursor cursor = result.cursor;
        cursor.moveToPosition(-1);
        for (int pos = 0; pos < cursor.getCount(); ++pos) {
            try {
                if (!cursor.moveToNext()) {
                    return true;
                }
            } catch (Exception e) {
                return true;
            }
        }
        return false;
    }
}
+21 −4
Original line number Diff line number Diff line
@@ -104,8 +104,6 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
     * @param state current state
     * @param executors the executors of authorities
     * @param fileTypeMap the map of mime types and file types.
     * @param lock the selection lock
     * @param contentChangedCallback callback when content changed
     */
    public MultiRootDocumentsLoader(Context context, ProvidersAccess providers, State state,
            Lookup<String, Executor> executors, Lookup<String, String> fileTypeMap) {
@@ -304,10 +302,11 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory

    @Override
    protected void onStartLoading() {
        if (mResult != null) {
        boolean isCursorStale = checkIfCursorStale(mResult);
        if (mResult != null && !isCursorStale) {
            deliverResult(mResult);
        }
        if (takeContentChanged() || mResult == null) {
        if (takeContentChanged() || mResult == null || isCursorStale) {
            forceLoad();
        }
    }
@@ -457,4 +456,22 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
            mIsClosed = true;
        }
    }

    private boolean checkIfCursorStale(DirectoryResult result) {
        if (mResult == null) {
            return true;
        }
        Cursor cursor = result.cursor;
        cursor.moveToPosition(-1);
        for (int pos = 0; pos < cursor.getCount(); ++pos) {
            try {
                if (!cursor.moveToNext()) {
                    return true;
                }
            } catch (Exception e) {
                return true;
            }
        }
        return false;
    }
}