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

Commit 77778759 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

If user ejects a storage from details, take user to...

... the storage list view

1. Change to ExternalStorageProvider
When available volumes have changed, it now notifies on
"content://com.android.externalstorage.documents" rather than on
"content://com.android.externalstorage.documents/root/", because it'll also
affect "content://com.android.externalstorage.documents/document/*/children".

2. Change to DocumentUI
- DirectoryLoader now won't crash when a provider returns null.
- DirectoryFragment now closes itself (i.e. emulate a back press) when a load
failed.
- It now correctly reloads contents when a volume is ejected thanks to 1.

Bug 21472170

Change-Id: Icf4bbc2ebb9067313dbbb67083cd4115b0a75c58
parent a43556d5
Loading
Loading
Loading
Loading
+19 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,8 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Looper;
import android.os.OperationCanceledException;
import android.os.OperationCanceledException;
import android.os.Parcelable;
import android.os.Parcelable;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract;
@@ -135,6 +137,8 @@ public class DirectoryFragment extends Fragment {


    private final int mLoaderId = 42;
    private final int mLoaderId = 42;


    private final Handler mHandler = new Handler(Looper.getMainLooper());

    public static void showNormal(FragmentManager fm, RootInfo root, DocumentInfo doc, int anim) {
    public static void showNormal(FragmentManager fm, RootInfo root, DocumentInfo doc, int anim) {
        show(fm, TYPE_NORMAL, root, doc, null, anim);
        show(fm, TYPE_NORMAL, root, doc, null, anim);
    }
    }
@@ -297,6 +301,21 @@ public class DirectoryFragment extends Fragment {


            @Override
            @Override
            public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
            public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
                if (result == null || result.exception != null) {
                    // onBackPressed does a fragment transaction, which can't be done inside
                    // onLoadFinished
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            final Activity activity = getActivity();
                            if (activity != null) {
                                activity.onBackPressed();
                            }
                        }
                    });
                    return;
                }

                if (!isAdded()) return;
                if (!isAdded()) return;


                mAdapter.swapResult(result);
                mAdapter.swapResult(result);
+7 −0
Original line number Original line Diff line number Diff line
@@ -31,7 +31,10 @@ import android.content.Context;
import android.database.Cursor;
import android.database.Cursor;
import android.net.Uri;
import android.net.Uri;
import android.os.CancellationSignal;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Looper;
import android.os.OperationCanceledException;
import android.os.OperationCanceledException;
import android.os.RemoteException;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.provider.DocumentsContract.Document;
import android.util.Log;
import android.util.Log;
@@ -163,6 +166,10 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {


            cursor = client.query(
            cursor = client.query(
                    mUri, null, null, null, getQuerySortOrder(result.sortOrder), mSignal);
                    mUri, null, null, null, getQuerySortOrder(result.sortOrder), mSignal);
            if (cursor == null) {
                throw new RemoteException("Provider returned null");
            }

            cursor.registerContentObserver(mObserver);
            cursor.registerContentObserver(mObserver);


            cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1);
            cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1);