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

Commit 080405b5 authored by Stephen Bird's avatar Stephen Bird
Browse files

Refresh: stop refreshes in action

If a refresh happens while another refresh is occuring, make sure
that that old refresh is cancelled. In addition to this, remove some
old logic that conflicted with itself. Also, keep ahold of the previous directory
before running the task.

Ticket: QRDL-1002
Change-Id: Ibc1f3d468243bc124d3baf259af21464f3c03c84
parent e1fac533
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -246,11 +246,6 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
            mNewDirChecked = checkChRootedNavigation(params[0]);

            //Check that it is really necessary change the directory
            if (!mReload && NavigationView.this.mCurrentDir != null &&
                    NavigationView.this.mCurrentDir.compareTo(mNewDirChecked) == 0) {
                return null;
            }

            mHasChanged = !(NavigationView.this.mCurrentDir != null &&
                    NavigationView.this.mCurrentDir.compareTo(mNewDirChecked) == 0);
            mIsNewHistory = (NavigationView.this.mCurrentDir != null);
@@ -385,14 +380,12 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
        @Override
        protected void onPostExecute(List<FileSystemObject> files) {
            // This means an exception. This method will be recalled then
            if (files != null) {
            onPostExecuteTask(files, mAddToHistory, mIsNewHistory, mHasChanged,
                        mSearchInfo, mNewDirChecked, mScrollTo);

            // Do animation
            fadeEfect(false);
        }
        }

        /**
         * Method that performs a fade animation.
@@ -418,6 +411,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe

    private int mId;
    private String mCurrentDir;
    private String mPreviousDir;
    private NavigationLayoutMode mCurrentMode;
    /**
     * @hide
@@ -512,7 +506,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
        //Return the persistent the data
        NavigationViewInfoParcelable parcel = new NavigationViewInfoParcelable();
        parcel.setId(this.mId);
        parcel.setCurrentDir(this.mCurrentDir);
        parcel.setCurrentDir(this.mPreviousDir);
        parcel.setChRooted(this.mChRooted);
        parcel.setSelectedFiles(this.mAdapter.getSelectedItems());
        parcel.setFiles(this.mFiles);
@@ -816,10 +810,15 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
     */
    public void refresh(FileSystemObject scrollTo) {
        //Check that current directory was set
        if (this.mCurrentDir == null || this.mFiles == null || this.mNavigationTask != null) {
        if (this.mCurrentDir == null || this.mFiles == null) {
            return;
        }

        if (this.mNavigationTask != null) {
            this.mNavigationTask.cancel(true);
            this.mNavigationTask = null;
        }

        //Reload data
        changeCurrentDir(this.mCurrentDir, false, true, false, null, scrollTo);
    }
@@ -1026,9 +1025,11 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
            final String newDir, final boolean addToHistory,
            final boolean reload, final boolean useCurrent,
            final SearchInfoParcelable searchInfo, final FileSystemObject scrollTo) {
        this.mPreviousDir = this.mCurrentDir;
        this.mCurrentDir = newDir;
        mNavigationTask = new NavigationTask(useCurrent, addToHistory, reload,
                searchInfo, scrollTo, mRestrictions, mChRooted);
        mNavigationTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, newDir);
        mNavigationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, newDir);
    }

    /**
@@ -1072,6 +1073,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
        try {
            //Check that there is not errors and have some data
            if (files == null) {
                this.mCurrentDir = this.mPreviousDir;
                return;
            }

@@ -1106,19 +1108,20 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
            scrollTo(scrollTo);

            //The current directory is now the "newDir"
            this.mCurrentDir = newDir;
            if (this.mOnDirectoryChangedListener != null) {
                FileSystemObject dir = FileHelper.createFileSystemObject(new File(newDir));
                this.mOnDirectoryChangedListener.onDirectoryChanged(dir);
            }

            mNavigationTask = null;
        } finally {
            //If calling activity is search, then save the search history
            if (searchInfo != null) {
                this.mOnHistoryListener.onNewHistory(searchInfo);
            }

            this.mPreviousDir = null;
            mNavigationTask = null;

            //End of loading data
            try {
                NavigationView.this.mBreadcrumb.endLoading();