1 /*
2  * Copyright (C) 2020 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 static androidx.core.util.Preconditions.checkNotNull;
20 
21 import androidx.recyclerview.selection.SelectionTracker;
22 import androidx.recyclerview.selection.SelectionTracker.SelectionObserver;
23 
24 /**
25  * A controller that listens to selection changes and controls profile tabs behavior.
26  */
27 public class ProfileTabsController extends SelectionObserver<String> {
28 
29     private static final String TAG = "ProfileTabsController";
30 
31     private final SelectionTracker<String> mSelectionMgr;
32     private final ProfileTabsAddons mProfileTabsAddons;
33 
ProfileTabsController( SelectionTracker<String> selectionMgr, ProfileTabsAddons profileTabsAddons)34     public ProfileTabsController(
35             SelectionTracker<String> selectionMgr,
36             ProfileTabsAddons profileTabsAddons) {
37         mSelectionMgr = checkNotNull(selectionMgr);
38         mProfileTabsAddons = checkNotNull(profileTabsAddons);
39     }
40 
41     @Override
onSelectionChanged()42     public void onSelectionChanged() {
43         onSelectionUpdated();
44     }
45 
46     @Override
onSelectionRestored()47     public void onSelectionRestored() {
48         onSelectionUpdated();
49     }
50 
onSelectionUpdated()51     private void onSelectionUpdated() {
52         mProfileTabsAddons.setEnabled(mSelectionMgr.getSelection().isEmpty());
53     }
54 }
55