Home | History | Annotate | Download | only in testing
      1 /*
      2  * Copyright 2017 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 androidx.recyclerview.selection.testing;
     18 
     19 import androidx.recyclerview.selection.DefaultSelectionTracker;
     20 import androidx.recyclerview.selection.EventBridge;
     21 import androidx.recyclerview.selection.ItemKeyProvider;
     22 import androidx.recyclerview.selection.SelectionPredicates;
     23 import androidx.recyclerview.selection.SelectionTracker;
     24 import androidx.recyclerview.selection.StorageStrategy;
     25 
     26 public final class SelectionTrackers {
     27 
     28     private SelectionTrackers() {}
     29 
     30     public static SelectionTracker<String> createStringTracker(String id, int numItems) {
     31         TestAdapter<String> adapter = new TestAdapter<>(TestData.createStringData(numItems));
     32         ItemKeyProvider<String> keyProvider =
     33                 new TestItemKeyProvider<>(ItemKeyProvider.SCOPE_MAPPED, adapter);
     34         SelectionTracker<String> tracker = new DefaultSelectionTracker<>(
     35                 id,
     36                 keyProvider,
     37                 SelectionPredicates.createSelectAnything(),
     38                 StorageStrategy.createStringStorage());
     39 
     40         EventBridge.install(adapter, tracker, keyProvider);
     41 
     42         return tracker;
     43     }
     44 
     45     public static SelectionTracker<Long> createLongTracker(String id, int numItems) {
     46         TestAdapter<Long> adapter = new TestAdapter<>(TestData.createLongData(numItems));
     47         ItemKeyProvider<Long> keyProvider =
     48                 new TestItemKeyProvider<>(ItemKeyProvider.SCOPE_MAPPED, adapter);
     49         SelectionTracker<Long> tracker = new DefaultSelectionTracker<>(
     50                 id,
     51                 keyProvider,
     52                 SelectionPredicates.createSelectAnything(),
     53                 StorageStrategy.createLongStorage());
     54 
     55         EventBridge.install(adapter, tracker, keyProvider);
     56 
     57         return tracker;
     58     }
     59 }
     60