Loading src/com/android/documentsui/ActionHandler.java +1 −1 Original line number Diff line number Diff line Loading @@ -94,5 +94,5 @@ public interface ActionHandler { * Allow action handler to be initialized in a new scope. * @return */ <T extends ActionHandler> T reset(Model model, boolean searchMode); <T extends ActionHandler> T reset(Model model); } src/com/android/documentsui/Injector.java +2 −3 Original line number Diff line number Diff line Loading @@ -89,15 +89,14 @@ public class Injector<T extends ActionHandler> { return actionModeController.reset(selectionDetails, menuItemClicker, view); } public T getActionHandler( @Nullable Model model, boolean searchMode) { public T getActionHandler(@Nullable Model model) { // provide our friend, RootsFragment, early access to this special feature! if (model == null) { return actions; } return actions.reset(model, searchMode); return actions.reset(model); } /** Loading src/com/android/documentsui/base/DocumentStack.java +0 −18 Original line number Diff line number Diff line Loading @@ -49,8 +49,6 @@ public class DocumentStack implements Durable, Parcelable { private LinkedList<DocumentInfo> mList; private @Nullable RootInfo mRoot; private boolean mInitialRootChanged; private boolean mInitialDocChanged; private boolean mStackTouched; public DocumentStack() { Loading Loading @@ -117,9 +115,6 @@ public class DocumentStack implements Durable, Parcelable { public void push(DocumentInfo info) { if (DEBUG) Log.d(TAG, "Adding doc to stack: " + info); if (!mInitialDocChanged && !isEmpty() && !info.equals(peek())) { mInitialDocChanged = true; } mList.addLast(info); mStackTouched = true; } Loading @@ -142,9 +137,6 @@ public class DocumentStack implements Durable, Parcelable { public void changeRoot(RootInfo root) { if (DEBUG) Log.d(TAG, "Root changed to: " + root); if (!mInitialRootChanged && mRoot != null && !root.equals(mRoot)) { mInitialRootChanged = true; } reset(); mRoot = root; } Loading @@ -156,10 +148,6 @@ public class DocumentStack implements Durable, Parcelable { return mStackTouched; } public boolean hasInitialLocationChanged() { return mInitialRootChanged || mInitialDocChanged; } public String getTitle() { if (mList.size() == 1 && mRoot != null) { return mRoot.title; Loading Loading @@ -212,8 +200,6 @@ public class DocumentStack implements Durable, Parcelable { + "root=" + mRoot + ", docStack=" + mList + ", stackTouched=" + mStackTouched + ", initialDocChanged=" + mInitialDocChanged + ", initialRootChanged=" + mInitialRootChanged + "}"; } Loading Loading @@ -241,8 +227,6 @@ public class DocumentStack implements Durable, Parcelable { mList.add(doc); } mStackTouched = in.readInt() != 0; mInitialRootChanged = in.readInt() != 0; mInitialDocChanged = in.readInt() != 0; break; default: throw new ProtocolException("Unknown version " + version); Loading @@ -265,8 +249,6 @@ public class DocumentStack implements Durable, Parcelable { doc.write(out); } out.writeInt(mStackTouched ? 1 : 0); out.writeInt(mInitialRootChanged ? 1 : 0); out.writeInt(mInitialDocChanged ? 1 : 0); } @Override Loading src/com/android/documentsui/dirlist/DirectoryFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -309,7 +309,7 @@ public class DirectoryFragment extends Fragment mSelectionMgr = mInjector.getSelectionManager(mAdapter, this::canSetSelectionState); mFocusManager = mInjector.getFocusManager(mRecView, mModel); mActions = mInjector.getActionHandler(mModel, mLocalState.mSearchMode); mActions = mInjector.getActionHandler(mModel); mSelectionMetadata = new SelectionMetadata(mModel::getItem); mSelectionMgr.addItemCallback(mSelectionMetadata); Loading src/com/android/documentsui/files/ActionHandler.java +14 −53 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import com.android.documentsui.base.ConfirmationCallback; import com.android.documentsui.base.ConfirmationCallback.Result; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.DocumentStack; import com.android.documentsui.base.EventListener; import com.android.documentsui.base.Lookup; import com.android.documentsui.base.MimeTypes; import com.android.documentsui.base.RootInfo; Loading @@ -50,7 +49,6 @@ import com.android.documentsui.dirlist.AnimationView; import com.android.documentsui.dirlist.DocumentDetails; import com.android.documentsui.dirlist.FocusHandler; import com.android.documentsui.dirlist.Model; import com.android.documentsui.dirlist.Model.Update; import com.android.documentsui.files.ActionHandler.Addons; import com.android.documentsui.queries.SearchViewManager; import com.android.documentsui.roots.GetRootDocumentTask; Loading Loading @@ -81,7 +79,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa private final ActivityConfig mActConfig; private final DocumentClipper mClipper; private final ClipStore mClipStore; private final ContentScope mScope; private @Nullable Model mModel; ActionHandler( T activity, Loading @@ -105,8 +103,6 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa mActConfig = tuner; mClipper = clipper; mClipStore = clipStore; mScope = new ContentScope(this::onModelLoaded); } @Override Loading @@ -125,7 +121,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa public void openSelectedInNewWindow() { Selection selection = getStableSelection(); assert(selection.size() == 1); DocumentInfo doc = mScope.model.getDocument(selection.iterator().next()); DocumentInfo doc = mModel.getDocument(selection.iterator().next()); assert(doc != null); openInNewWindow(new DocumentStack(mState.stack, doc)); } Loading Loading @@ -162,7 +158,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa @Override public boolean openDocument(DocumentDetails details) { DocumentInfo doc = mScope.model.getDocument(details.getModelId()); DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc == null) { Log.w(TAG, "Can't view item. No Document available for modeId: " + details.getModelId()); Loading @@ -179,13 +175,13 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa @Override public boolean viewDocument(DocumentDetails details) { DocumentInfo doc = mScope.model.getDocument(details.getModelId()); DocumentInfo doc = mModel.getDocument(details.getModelId()); return viewDocument(doc); } @Override public boolean previewDocument(DocumentDetails details) { DocumentInfo doc = mScope.model.getDocument(details.getModelId()); DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc.isContainer()) { return false; } Loading Loading @@ -214,7 +210,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } mSelectionMgr.clearSelection(); mClipper.clipDocumentsForCut(mScope.model::getItemUri, selection, mState.stack.peek()); mClipper.clipDocumentsForCut(mModel::getItemUri, selection, mState.stack.peek()); mDialogs.showDocumentsClipped(selection.size()); } Loading @@ -229,7 +225,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } mSelectionMgr.clearSelection(); mClipper.clipDocumentsForCopy(mScope.model::getItemUri, selection); mClipper.clipDocumentsForCopy(mModel::getItemUri, selection); mDialogs.showDocumentsClipped(selection.size()); } Loading @@ -247,7 +243,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa final @Nullable DocumentInfo srcParent = mState.stack.peek(); // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mScope.model.getDocuments(selection); List<DocumentInfo> docs = mModel.getDocuments(selection); ConfirmationCallback result = (@Result int code) -> { // share the news with our caller, be it good or bad. Loading @@ -261,7 +257,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa try { srcs = UrisSupplier.create( selection, mScope.model::getItemUri, mModel::getItemUri, mClipStore); } catch (IOException e) { throw new RuntimeException("Failed to create uri supplier.", e); Loading Loading @@ -290,7 +286,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mScope.model.loadDocuments(selection, Model.SHARABLE_FILE_FILTER); mModel.loadDocuments(selection, Model.SHARABLE_FILE_FILTER); Intent intent; Loading Loading @@ -322,7 +318,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa intent.addCategory(Intent.CATEGORY_DEFAULT); if (Shared.ENABLE_OMC_API_FEATURES && mScope.model.hasDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER)) { && mModel.hasDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER)) { intent.addCategory(Intent.CATEGORY_TYPED_OPENABLE); } Loading Loading @@ -477,7 +473,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa mActivity.getPackageManager(), mActivity.getResources(), doc, mScope.model).build(); mModel).build(); if (intent != null) { // TODO: un-work around issue b/24963914. Should be fixed soon. Loading Loading @@ -560,51 +556,16 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return intent; } private void onModelLoaded(Model.Update update) { // When launched into empty root, open drawer. if (mScope.model.isEmpty() && !mState.stack.hasInitialLocationChanged() && !mScope.searchMode && !mScope.modelLoadObserved) { // Opens the drawer *if* an openable drawer is present // else this is a no-op. mActivity.setRootsDrawerOpen(true); } mScope.modelLoadObserved = true; } @SuppressWarnings("unchecked") @Override public ActionHandler<T> reset(Model model, boolean searchMode) { public ActionHandler<T> reset(Model model) { assert(model != null); mScope.model = model; mScope.modelLoadObserved = false; mScope.searchMode = searchMode; model.addUpdateListener(mScope.modelUpdateListener); mScope.modelLoadObserved = false; mModel = model; return this; } private static final class ContentScope { @Nullable Model model; boolean searchMode; private final EventListener<Update> modelUpdateListener; // We use this to keep track of whether a model has been previously loaded or not so we can // open the drawer on empty directories on first launch private boolean modelLoadObserved; public ContentScope(EventListener<Update> modelUpdateListener) { this.modelUpdateListener = modelUpdateListener; } } public interface Addons extends CommonAddons { } } Loading
src/com/android/documentsui/ActionHandler.java +1 −1 Original line number Diff line number Diff line Loading @@ -94,5 +94,5 @@ public interface ActionHandler { * Allow action handler to be initialized in a new scope. * @return */ <T extends ActionHandler> T reset(Model model, boolean searchMode); <T extends ActionHandler> T reset(Model model); }
src/com/android/documentsui/Injector.java +2 −3 Original line number Diff line number Diff line Loading @@ -89,15 +89,14 @@ public class Injector<T extends ActionHandler> { return actionModeController.reset(selectionDetails, menuItemClicker, view); } public T getActionHandler( @Nullable Model model, boolean searchMode) { public T getActionHandler(@Nullable Model model) { // provide our friend, RootsFragment, early access to this special feature! if (model == null) { return actions; } return actions.reset(model, searchMode); return actions.reset(model); } /** Loading
src/com/android/documentsui/base/DocumentStack.java +0 −18 Original line number Diff line number Diff line Loading @@ -49,8 +49,6 @@ public class DocumentStack implements Durable, Parcelable { private LinkedList<DocumentInfo> mList; private @Nullable RootInfo mRoot; private boolean mInitialRootChanged; private boolean mInitialDocChanged; private boolean mStackTouched; public DocumentStack() { Loading Loading @@ -117,9 +115,6 @@ public class DocumentStack implements Durable, Parcelable { public void push(DocumentInfo info) { if (DEBUG) Log.d(TAG, "Adding doc to stack: " + info); if (!mInitialDocChanged && !isEmpty() && !info.equals(peek())) { mInitialDocChanged = true; } mList.addLast(info); mStackTouched = true; } Loading @@ -142,9 +137,6 @@ public class DocumentStack implements Durable, Parcelable { public void changeRoot(RootInfo root) { if (DEBUG) Log.d(TAG, "Root changed to: " + root); if (!mInitialRootChanged && mRoot != null && !root.equals(mRoot)) { mInitialRootChanged = true; } reset(); mRoot = root; } Loading @@ -156,10 +148,6 @@ public class DocumentStack implements Durable, Parcelable { return mStackTouched; } public boolean hasInitialLocationChanged() { return mInitialRootChanged || mInitialDocChanged; } public String getTitle() { if (mList.size() == 1 && mRoot != null) { return mRoot.title; Loading Loading @@ -212,8 +200,6 @@ public class DocumentStack implements Durable, Parcelable { + "root=" + mRoot + ", docStack=" + mList + ", stackTouched=" + mStackTouched + ", initialDocChanged=" + mInitialDocChanged + ", initialRootChanged=" + mInitialRootChanged + "}"; } Loading Loading @@ -241,8 +227,6 @@ public class DocumentStack implements Durable, Parcelable { mList.add(doc); } mStackTouched = in.readInt() != 0; mInitialRootChanged = in.readInt() != 0; mInitialDocChanged = in.readInt() != 0; break; default: throw new ProtocolException("Unknown version " + version); Loading @@ -265,8 +249,6 @@ public class DocumentStack implements Durable, Parcelable { doc.write(out); } out.writeInt(mStackTouched ? 1 : 0); out.writeInt(mInitialRootChanged ? 1 : 0); out.writeInt(mInitialDocChanged ? 1 : 0); } @Override Loading
src/com/android/documentsui/dirlist/DirectoryFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -309,7 +309,7 @@ public class DirectoryFragment extends Fragment mSelectionMgr = mInjector.getSelectionManager(mAdapter, this::canSetSelectionState); mFocusManager = mInjector.getFocusManager(mRecView, mModel); mActions = mInjector.getActionHandler(mModel, mLocalState.mSearchMode); mActions = mInjector.getActionHandler(mModel); mSelectionMetadata = new SelectionMetadata(mModel::getItem); mSelectionMgr.addItemCallback(mSelectionMetadata); Loading
src/com/android/documentsui/files/ActionHandler.java +14 −53 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import com.android.documentsui.base.ConfirmationCallback; import com.android.documentsui.base.ConfirmationCallback.Result; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.DocumentStack; import com.android.documentsui.base.EventListener; import com.android.documentsui.base.Lookup; import com.android.documentsui.base.MimeTypes; import com.android.documentsui.base.RootInfo; Loading @@ -50,7 +49,6 @@ import com.android.documentsui.dirlist.AnimationView; import com.android.documentsui.dirlist.DocumentDetails; import com.android.documentsui.dirlist.FocusHandler; import com.android.documentsui.dirlist.Model; import com.android.documentsui.dirlist.Model.Update; import com.android.documentsui.files.ActionHandler.Addons; import com.android.documentsui.queries.SearchViewManager; import com.android.documentsui.roots.GetRootDocumentTask; Loading Loading @@ -81,7 +79,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa private final ActivityConfig mActConfig; private final DocumentClipper mClipper; private final ClipStore mClipStore; private final ContentScope mScope; private @Nullable Model mModel; ActionHandler( T activity, Loading @@ -105,8 +103,6 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa mActConfig = tuner; mClipper = clipper; mClipStore = clipStore; mScope = new ContentScope(this::onModelLoaded); } @Override Loading @@ -125,7 +121,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa public void openSelectedInNewWindow() { Selection selection = getStableSelection(); assert(selection.size() == 1); DocumentInfo doc = mScope.model.getDocument(selection.iterator().next()); DocumentInfo doc = mModel.getDocument(selection.iterator().next()); assert(doc != null); openInNewWindow(new DocumentStack(mState.stack, doc)); } Loading Loading @@ -162,7 +158,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa @Override public boolean openDocument(DocumentDetails details) { DocumentInfo doc = mScope.model.getDocument(details.getModelId()); DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc == null) { Log.w(TAG, "Can't view item. No Document available for modeId: " + details.getModelId()); Loading @@ -179,13 +175,13 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa @Override public boolean viewDocument(DocumentDetails details) { DocumentInfo doc = mScope.model.getDocument(details.getModelId()); DocumentInfo doc = mModel.getDocument(details.getModelId()); return viewDocument(doc); } @Override public boolean previewDocument(DocumentDetails details) { DocumentInfo doc = mScope.model.getDocument(details.getModelId()); DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc.isContainer()) { return false; } Loading Loading @@ -214,7 +210,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } mSelectionMgr.clearSelection(); mClipper.clipDocumentsForCut(mScope.model::getItemUri, selection, mState.stack.peek()); mClipper.clipDocumentsForCut(mModel::getItemUri, selection, mState.stack.peek()); mDialogs.showDocumentsClipped(selection.size()); } Loading @@ -229,7 +225,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } mSelectionMgr.clearSelection(); mClipper.clipDocumentsForCopy(mScope.model::getItemUri, selection); mClipper.clipDocumentsForCopy(mModel::getItemUri, selection); mDialogs.showDocumentsClipped(selection.size()); } Loading @@ -247,7 +243,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa final @Nullable DocumentInfo srcParent = mState.stack.peek(); // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mScope.model.getDocuments(selection); List<DocumentInfo> docs = mModel.getDocuments(selection); ConfirmationCallback result = (@Result int code) -> { // share the news with our caller, be it good or bad. Loading @@ -261,7 +257,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa try { srcs = UrisSupplier.create( selection, mScope.model::getItemUri, mModel::getItemUri, mClipStore); } catch (IOException e) { throw new RuntimeException("Failed to create uri supplier.", e); Loading Loading @@ -290,7 +286,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mScope.model.loadDocuments(selection, Model.SHARABLE_FILE_FILTER); mModel.loadDocuments(selection, Model.SHARABLE_FILE_FILTER); Intent intent; Loading Loading @@ -322,7 +318,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa intent.addCategory(Intent.CATEGORY_DEFAULT); if (Shared.ENABLE_OMC_API_FEATURES && mScope.model.hasDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER)) { && mModel.hasDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER)) { intent.addCategory(Intent.CATEGORY_TYPED_OPENABLE); } Loading Loading @@ -477,7 +473,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa mActivity.getPackageManager(), mActivity.getResources(), doc, mScope.model).build(); mModel).build(); if (intent != null) { // TODO: un-work around issue b/24963914. Should be fixed soon. Loading Loading @@ -560,51 +556,16 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return intent; } private void onModelLoaded(Model.Update update) { // When launched into empty root, open drawer. if (mScope.model.isEmpty() && !mState.stack.hasInitialLocationChanged() && !mScope.searchMode && !mScope.modelLoadObserved) { // Opens the drawer *if* an openable drawer is present // else this is a no-op. mActivity.setRootsDrawerOpen(true); } mScope.modelLoadObserved = true; } @SuppressWarnings("unchecked") @Override public ActionHandler<T> reset(Model model, boolean searchMode) { public ActionHandler<T> reset(Model model) { assert(model != null); mScope.model = model; mScope.modelLoadObserved = false; mScope.searchMode = searchMode; model.addUpdateListener(mScope.modelUpdateListener); mScope.modelLoadObserved = false; mModel = model; return this; } private static final class ContentScope { @Nullable Model model; boolean searchMode; private final EventListener<Update> modelUpdateListener; // We use this to keep track of whether a model has been previously loaded or not so we can // open the drawer on empty directories on first launch private boolean modelLoadObserved; public ContentScope(EventListener<Update> modelUpdateListener) { this.modelUpdateListener = modelUpdateListener; } } public interface Addons extends CommonAddons { } }