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

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

Merge "Replace selection interfaces w/ abstract classes."

parents e966b0e7 5a620379
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -35,13 +35,13 @@ import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.Menus;
import com.android.documentsui.selection.Selection;
import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.SelectionHelper.StubSelectionObserver;
import com.android.documentsui.selection.SelectionHelper.SelectionObserver;
import com.android.documentsui.ui.MessageBuilder;

/**
 * A controller that listens to selection changes and manages life cycles of action modes.
 */
public class ActionModeController extends StubSelectionObserver
public class ActionModeController extends SelectionObserver
        implements ActionMode.Callback, ActionModeAddons {

    private static final String TAG = "ActionModeController";
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import javax.annotation.Nullable;
 * DocumentsUI SelectManager implementation that creates delegate instances
 * each time reset is called.
 */
public final class DocsSelectionHelper implements SelectionHelper {
public final class DocsSelectionHelper extends SelectionHelper {

    private final DelegateFactory mFactory;
    private final @SelectionMode int mSelectionMode;
+2 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.Features;
import com.android.documentsui.base.Lookup;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.dirlist.DocsStableIdProvider;
import com.android.documentsui.dirlist.DocumentsAdapter;
import com.android.documentsui.prefs.ScopedPreferences;
import com.android.documentsui.queries.SearchViewManager;
@@ -121,7 +122,7 @@ public class Injector<T extends ActionHandler> {

    public SelectionHelper getSelectionManager(
            DocumentsAdapter adapter, SelectionHelper.SelectionPredicate canSetState) {
        return selectionMgr.reset(adapter, adapter, canSetState);
        return selectionMgr.reset(adapter, new DocsStableIdProvider(adapter), canSetState);
    }

    public final ActionModeController getActionModeController(
+5 −7
Original line number Diff line number Diff line
@@ -91,10 +91,10 @@ import com.android.documentsui.picker.PickActivity;
import com.android.documentsui.selection.Selection;
import com.android.documentsui.selection.SelectionHelper;
import com.android.documentsui.selection.SelectionHelper.SelectionPredicate;
import com.android.documentsui.selection.addons.BandPredicate;
import com.android.documentsui.selection.addons.BandSelectionHelper;
import com.android.documentsui.selection.addons.BandSelectionHelper.BandPredicate;
import com.android.documentsui.selection.addons.BandSelectionHelper.SelectionHost;
import com.android.documentsui.selection.addons.ContentLock;
import com.android.documentsui.selection.addons.DefaultBandHost;
import com.android.documentsui.selection.addons.GestureSelectionHelper;
import com.android.documentsui.services.FileOperation;
import com.android.documentsui.services.FileOperationService;
@@ -372,12 +372,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
                }
            };

            SelectionHost host = BandSelectionHelper.createHost(
                    mRecView, R.drawable.band_select_overlay, bandPredicate);
            mBandSelector = new BandSelectionHelper(
                    host,
                    mAdapter,  // recycler view adapter.
                    mAdapter,  // stableIds provider.
                    new DefaultBandHost(mRecView, R.drawable.band_select_overlay, bandPredicate),
                    mAdapter,
                    new DocsStableIdProvider(mAdapter),
                    mSelectionMgr,
                    selectionPredicate,
                    mContentLock);
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.documentsui.dirlist;

import static android.support.v4.util.Preconditions.checkArgument;

import com.android.documentsui.selection.SelectionHelper.StableIdProvider;

import java.util.List;

/**
 * Provides RecyclerView selection code access to stable ids backed
 * by DocumentsAdapter.
 */
public final class DocsStableIdProvider extends StableIdProvider {

    private final DocumentsAdapter mAdapter;

    public DocsStableIdProvider(DocumentsAdapter adapter) {
        checkArgument(adapter != null);
        mAdapter = adapter;
    }

    @Override
    public String getStableId(int position) {
        return mAdapter.getStableId(position);
    }

    @Override
    public int getPosition(String id) {
        return mAdapter.getPosition(id);
    }

    @Override
    public List<String> getStableIds() {
        return mAdapter.getStableIds();
    }
}
Loading