• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.documentsui;
18 
19 import androidx.recyclerview.selection.DefaultSelectionTracker;
20 import androidx.recyclerview.selection.SelectionPredicates;
21 import androidx.recyclerview.selection.SelectionTracker.SelectionPredicate;
22 import androidx.recyclerview.selection.StorageStrategy;
23 
24 import com.android.documentsui.testing.TestStableIdProvider;
25 
26 import java.util.Collections;
27 import java.util.List;
28 
29 public class SelectionHelpers {
30 
31     public static final SelectionPredicate<String> CAN_SET_ANYTHING =
32             SelectionPredicates.createSelectAnything();
33 
SelectionHelpers()34     private SelectionHelpers() {}
35 
createTestInstance()36     public static DocsSelectionHelper createTestInstance() {
37         return createTestInstance(Collections.emptyList());
38     }
39 
createTestInstance(List<String> docs)40     public static DocsSelectionHelper createTestInstance(List<String> docs) {
41         DocsSelectionHelper manager = new DocsSelectionHelper(
42                 new DocsSelectionHelper.DelegateFactory());
43 
44         manager.reset(new DefaultSelectionTracker<String>(
45                 Integer.toHexString(System.identityHashCode(docs)),
46                 new TestStableIdProvider(docs),
47                 CAN_SET_ANYTHING,
48                 StorageStrategy.createStringStorage()));
49         return manager;
50     }
51 }
52