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

Commit 208945c4 authored by Garfield Tan's avatar Garfield Tan
Browse files

Refactor FragmentTuner to ActivityConfig.

* Move model listener that opens drawer to ActionHandler.
* Move showChooserForDoc() to ActionHandler.
* Statically initialize ActionHandler.
* Isolate OnDragListener to FilesActivity only.

Bug: 28315278
Change-Id: I760c8411922fca827fd08c115bd2590ab671c380
parent e13f6785
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -137,6 +137,11 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
        throw new UnsupportedOperationException("Preview not supported!");
    }

    @Override
    public void showChooserForDoc(DocumentInfo doc) {
        throw new UnsupportedOperationException("Show chooser for doc not supported!");
    }

    @Override
    public void deleteDocuments(Model model, Selection selection, ConfirmationCallback callback) {
        throw new UnsupportedOperationException("Delete not supported!");
@@ -171,5 +176,6 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons>
        void openContainerDocument(DocumentInfo doc);
        RootInfo getCurrentRoot();
        DocumentInfo getCurrentDirectory();
        void setRootsDrawerOpen(boolean open);
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.net.Uri;

import com.android.documentsui.base.BooleanConsumer;
import com.android.documentsui.base.ConfirmationCallback;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.dirlist.DocumentDetails;
@@ -35,7 +36,6 @@ public interface ActionHandler {

    /**
     * Drops documents on a root.
     * @param check The check to make sure RootsFragment is not detached from activity.
     */
    boolean dropOn(ClipData data, RootInfo root);

@@ -64,6 +64,8 @@ public interface ActionHandler {

    boolean openDocument(DocumentDetails doc);

    void showChooserForDoc(DocumentInfo doc);

    void deleteDocuments(Model model, Selection selection, ConfirmationCallback callback);

    /**
+9 −14
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -14,24 +14,25 @@
 * limitations under the License.
 */

package com.android.documentsui.dirlist;
package com.android.documentsui;

import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.State;

/**
 * Providers support for specializing the DirectoryFragment to the "host" Activity.
 * Feel free to expand the role of this class to handle other specializations.
 */
public abstract class FragmentTuner {
public abstract class ActivityConfig {

    // Subtly different from isDocumentEnabled. The reason may be illuminated as follows.
    // A folder is enabled such that it may be double clicked, even in settings
    // when the folder itself cannot be selected. This may also be true of container types.
    public boolean canSelectType(String docMimeType, int docFlags) {
    public boolean canSelectType(String docMimeType, int docFlags, State state) {
        return true;
    }

    public boolean isDocumentEnabled(String docMimeType, int docFlags) {
    public boolean isDocumentEnabled(String docMimeType, int docFlags, State state) {
        return true;
    }

@@ -39,20 +40,14 @@ public abstract class FragmentTuner {
     * When managed mode is enabled, active downloads will be visible in the UI.
     * Presumably this should only be true when in the downloads directory.
     */
    protected boolean managedModeEnabled() {
    public boolean managedModeEnabled(DocumentStack stack) {
        return false;
    }

    /**
     * Whether drag n' drop is allowed in this context
     */
    protected boolean dragAndDropEnabled() {
    public boolean dragAndDropEnabled() {
        return false;
    }

    // TODO: Move to action handler.
    @Deprecated
    protected void showChooserForDoc(DocumentInfo doc) {
        throw new UnsupportedOperationException("Show chooser not supported!");
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ import com.android.documentsui.base.State;
import com.android.documentsui.base.State.ViewMode;
import com.android.documentsui.dirlist.AnimationView;
import com.android.documentsui.dirlist.DirectoryFragment;
import com.android.documentsui.dirlist.FragmentTuner;
import com.android.documentsui.dirlist.Model;
import com.android.documentsui.dirlist.MultiSelectManager;
import com.android.documentsui.dirlist.MultiSelectManager.Selection;
@@ -120,7 +119,7 @@ public abstract class BaseActivity
     * Provides Activity a means of injection into and specialization of
     * DirectoryFragment.
     */
    public abstract FragmentTuner getFragmentTuner(Model model, boolean mSearchMode);
    public abstract ActivityConfig getActivityConfig();

    /**
     * Provides Activity a means of injection into and specialization of
@@ -144,10 +143,10 @@ public abstract class BaseActivity
     * Provides Activity a means of injection into and specialization of
     * fragment actions.
     *
     * Args can be nullable when called from a context lacking them, such as RootsFragment.
     * Args can be null when called from a context lacking fragment, such as RootsFragment.
     */
    public abstract ActionHandler getActionHandler(
            @Nullable Model model, @Nullable MultiSelectManager selectionMgr);
            @Nullable Model model, @Nullable MultiSelectManager selectionMgr, boolean searchMode);

    public BaseActivity(@LayoutRes int layoutId, String tag) {
        mLayoutId = layoutId;
@@ -168,8 +167,8 @@ public abstract class BaseActivity

        setContentView(mLayoutId);

        mDrawer = DrawerController.create(this);
        mState = getState(icicle);
        mDrawer = DrawerController.create(this, getActivityConfig());
        Metrics.logActivityLaunch(this, mState, intent);

        // we're really interested in retainining state in our very complex
@@ -216,7 +215,6 @@ public abstract class BaseActivity
        mSearchManager = new SearchViewManager(searchListener, icicle);
        mSortController = SortController.create(this, mState.derivedMode, mState.sortModel);


        // Base classes must update result in their onCreate.
        setResult(Activity.RESULT_CANCELED);
    }
@@ -284,6 +282,7 @@ public abstract class BaseActivity
        return state;
    }

    @Override
    public void setRootsDrawerOpen(boolean open) {
        mNavigator.revealRootsDrawer(open);
    }
+11 −7
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.documentsui.base.Shared.DEBUG;

import android.annotation.IntDef;
import android.app.Activity;
import android.support.annotation.ColorRes;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
@@ -76,7 +75,7 @@ public abstract class DrawerController implements DrawerListener {
    /**
     * Returns a controller suitable for {@code Layout}.
     */
    static DrawerController create(Activity activity) {
    public static DrawerController create(Activity activity, ActivityConfig activityConfig) {

        DrawerLayout layout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);

@@ -96,7 +95,7 @@ public abstract class DrawerController implements DrawerListener {
                R.string.drawer_open,
                R.string.drawer_close);

        return new RuntimeDrawerController(layout, drawer, toggle, toolbar);
        return new RuntimeDrawerController(layout, drawer, toggle, toolbar, activityConfig);
    }

    /**
@@ -131,8 +130,11 @@ public abstract class DrawerController implements DrawerListener {
        private @Trigger int mTrigger = OPENED_OTHER;

        public RuntimeDrawerController(
                DrawerLayout layout, View drawer, ActionBarDrawerToggle toggle,
                Toolbar drawerToolbar) {
                DrawerLayout layout,
                View drawer,
                ActionBarDrawerToggle toggle,
                Toolbar drawerToolbar,
                ActivityConfig activityConfig) {
            mToolbar = drawerToolbar;
            assert(layout != null);

@@ -142,9 +144,11 @@ public abstract class DrawerController implements DrawerListener {

            mLayout.setDrawerListener(this);

            if (activityConfig.dragAndDropEnabled()) {
                View edge = layout.findViewById(R.id.drawer_edge);
                edge.setOnDragListener(new ItemDragListener<>(this));
            }
        }

        @Override
        public void runOnUiThread(Runnable runnable) {
Loading