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.testing;
18 
19 import android.content.Intent;
20 
21 import androidx.recyclerview.selection.ItemDetailsLookup.ItemDetails;
22 
23 import com.android.documentsui.AbstractActionHandler;
24 import com.android.documentsui.TestActivity;
25 import com.android.documentsui.base.DocumentInfo;
26 import com.android.documentsui.base.RootInfo;
27 import com.android.documentsui.base.UserId;
28 
29 import java.util.function.Consumer;
30 
31 public class TestActionHandler extends AbstractActionHandler<TestActivity> {
32 
33     private final TestEnv mEnv;
34 
35     public final TestEventHandler<ItemDetails<String>> open = new TestEventHandler<>();
36     public boolean mDeleteHappened;
37     public boolean mRequestDisablingQuietModeHappened;
38 
39     public DocumentInfo nextRootDocument;
40 
TestActionHandler()41     public TestActionHandler() {
42         this(TestEnv.create());
43     }
44 
TestActionHandler(TestEnv env)45     public TestActionHandler(TestEnv env) {
46         super(
47                 TestActivity.create(env),
48                 env.state,
49                 env.providers,
50                 env.docs,
51                 env.searchViewManager,
52                 (String authority) -> null,
53                 env.injector);
54 
55         mEnv = env;
56     }
57 
58     @Override
openItem(ItemDetails<String> doc, @ViewType int type, @ViewType int fallback)59     public boolean openItem(ItemDetails<String> doc, @ViewType int type, @ViewType int fallback) {
60         return open.accept(doc);
61     }
62 
63     @Override
showDeleteDialog()64     public void showDeleteDialog() {
65         mDeleteHappened = true;
66     }
67 
68     @Override
requestQuietModeDisabled(RootInfo info, UserId userId)69     public void requestQuietModeDisabled(RootInfo info, UserId userId) {
70         mRequestDisablingQuietModeHappened = true;
71     }
72 
73     @Override
openRoot(RootInfo root)74     public void openRoot(RootInfo root) {
75         throw new UnsupportedOperationException();
76     }
77 
78     @Override
initLocation(Intent intent)79     public void initLocation(Intent intent) {
80         throw new UnsupportedOperationException();
81     }
82 
83     @Override
launchToDefaultLocation()84     protected void launchToDefaultLocation() {
85         throw new UnsupportedOperationException();
86     }
87 
88     @Override
getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback)89     public void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback) {
90         mEnv.mExecutor.submit(() -> {
91             callback.accept(nextRootDocument);
92         });
93     }
94 }
95