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

Commit 850912db authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE: Don't create DocumentInfo instances in background." into nyc-mr1-dev

parents e8e7f1b8 b818058f
Loading
Loading
Loading
Loading
+114 −149
Original line number Diff line number Diff line
@@ -753,21 +753,17 @@ public class DirectoryFragment extends Fragment
    private void openDocuments(final Selection selected) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_OPEN);

        new GetDocumentsTask() {
            @Override
            void onDocumentsReady(List<DocumentInfo> docs) {
        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.getDocuments(selected);
        // TODO: Implement support in Files activity for opening multiple docs.
        BaseActivity.get(DirectoryFragment.this).onDocumentsPicked(docs);
    }
        }.execute(selected);
    }

    private void shareDocuments(final Selection selected) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SHARE);

        new GetDocumentsTask() {
            @Override
            void onDocumentsReady(List<DocumentInfo> docs) {
        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.getDocuments(selected);
        Intent intent;

        // Filter out directories and virtual files - those can't be shared.
@@ -809,8 +805,6 @@ public class DirectoryFragment extends Fragment
        intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via));
        startActivity(intent);
    }
        }.execute(selected);
    }

    private String generateDeleteMessage(final List<DocumentInfo> docs) {
        String message;
@@ -855,9 +849,9 @@ public class DirectoryFragment extends Fragment
        assert(!selected.isEmpty());

        final DocumentInfo srcParent = getDisplayState().stack.peek();
        new GetDocumentsTask() {
            @Override
            void onDocumentsReady(final List<DocumentInfo> docs) {

        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.getDocuments(selected);

        TextView message =
                (TextView) mInflater.inflate(R.layout.dialog_delete_confirmation, null);
@@ -878,6 +872,7 @@ public class DirectoryFragment extends Fragment
            .setPositiveButton(
                 android.R.string.yes,
                 new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // Finish selection mode first which clears selection so we
                        // don't end up trying to deselect deleted documents.
@@ -900,8 +895,6 @@ public class DirectoryFragment extends Fragment
            .setNegativeButton(android.R.string.no, null)
            .show();
    }
        }.execute(selected);
    }

    private void transferDocuments(final Selection selected, final @OpType int mode) {
        if(mode == FileOperationService.OPERATION_COPY) {
@@ -934,9 +927,8 @@ public class DirectoryFragment extends Fragment
                ? R.string.menu_move : R.string.menu_copy;
        intent.putExtra(DocumentsContract.EXTRA_PROMPT, getResources().getString(drawerTitleId));

        new GetDocumentsTask() {
            @Override
            void onDocumentsReady(List<DocumentInfo> docs) {
        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.getDocuments(selected);
        // TODO: Can this move to Fragment bundle state?
        getDisplayState().selectedDocumentsForCopy = docs;

@@ -952,9 +944,6 @@ public class DirectoryFragment extends Fragment
        startActivityForResult(intent, REQUEST_COPY_DESTINATION);
    }

        }.execute(selected);
    }

    private static boolean hasDirectory(List<DocumentInfo> docs) {
        for (DocumentInfo info : docs) {
            if (Document.MIME_TYPE_DIR.equals(info.mimeType)) {
@@ -971,13 +960,10 @@ public class DirectoryFragment extends Fragment
        // Rename option is only available in menu when 1 document selected
        assert(selected.size() == 1);

        new GetDocumentsTask() {
            @Override
            void onDocumentsReady(List<DocumentInfo> docs) {
        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.getDocuments(selected);
        RenameDocumentFragment.show(getFragmentManager(), docs.get(0));
    }
        }.execute(selected);
    }

    @Override
    public void initDocumentHolder(DocumentHolder holder) {
@@ -1135,11 +1121,11 @@ public class DirectoryFragment extends Fragment
        }
    }

    void copySelectionToClipboard(Selection selection) {
        assert(!selection.isEmpty());
        new GetDocumentsTask() {
            @Override
            void onDocumentsReady(List<DocumentInfo> docs) {
    void copySelectionToClipboard(Selection selected) {
        assert(!selected.isEmpty());

        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.getDocuments(selected);
        mClipper.clipDocuments(docs);
        Activity activity = getActivity();
        Snackbars.makeSnackbar(activity,
@@ -1147,8 +1133,6 @@ public class DirectoryFragment extends Fragment
                        R.plurals.clipboard_files_clipped, docs.size(), docs.size()),
                Snackbar.LENGTH_SHORT).show();
    }
        }.execute(selection);
    }

    public void pasteFromClipboard() {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_PASTE_CLIPBOARD);
@@ -1456,25 +1440,6 @@ public class DirectoryFragment extends Fragment
            mShadowView.draw(canvas);
        }
    }
    /**
     * Abstract task providing support for loading documents *off*
     * the main thread. And if it isn't obvious, creating a list
     * of documents (especially large lists) can be pretty expensive.
     */
    private abstract class GetDocumentsTask
            extends AsyncTask<Selection, Void, List<DocumentInfo>> {
        @Override
        protected final List<DocumentInfo> doInBackground(Selection... selected) {
            return mModel.getDocuments(selected[0]);
        }

        @Override
        protected final void onPostExecute(List<DocumentInfo> docs) {
            onDocumentsReady(docs);
        }

        abstract void onDocumentsReady(List<DocumentInfo> docs);
    }

    @Override
    public boolean isSelected(String modelId) {