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

Commit efb4dcbc authored by Diksha Gohlyan's avatar Diksha Gohlyan Committed by Automerger Merge Worker
Browse files

Merge "If stale data, forceload values" am: d91a988a

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/DocumentsUI/+/12464895

Change-Id: Id3da95db4548b2522f71a24571fc7e8bd152c2d0
parents b247fee1 d91a988a
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;
    }
}