blob: 728b70c2deddb9b24e02fda2e5b9fb456fb10fcc [file] [log] [blame]
Ben Lin7232bf02016-08-26 14:33:03 -07001/*
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
Steve McKay16e0c1f2016-09-15 12:41:13 -070017package com.android.documentsui.picker;
Ben Lin7232bf02016-08-26 14:33:03 -070018
Steve McKay988d8a32016-09-27 09:41:17 -070019import android.app.Activity;
Ben Lin7232bf02016-08-26 14:33:03 -070020
Steve McKay988d8a32016-09-27 09:41:17 -070021import com.android.documentsui.AbstractActionHandler.CommonAddons;
Garfield Tanbab25162017-03-08 18:46:25 -080022import com.android.documentsui.base.DocumentStack;
Steve McKayd0805062016-09-15 14:30:38 -070023import com.android.documentsui.base.PairedTask;
Steve McKayd9caa6a2016-09-15 16:36:45 -070024import com.android.documentsui.base.State;
Steve McKay988d8a32016-09-27 09:41:17 -070025import com.android.documentsui.roots.RootsAccess;
Ben Lin7232bf02016-08-26 14:33:03 -070026
Garfield Tanbab25162017-03-08 18:46:25 -080027import java.util.function.Consumer;
28
29import javax.annotation.Nullable;
Ben Lin7232bf02016-08-26 14:33:03 -070030
31/**
32 * Loads the last used path (stack) from Recents (history).
33 * The path selected is based on the calling package name. So the last
34 * path for an app like Gmail can be different than the last path
35 * for an app like DropBox.
36 */
Steve McKay988d8a32016-09-27 09:41:17 -070037final class LoadLastAccessedStackTask<T extends Activity & CommonAddons>
Garfield Tanbab25162017-03-08 18:46:25 -080038 extends PairedTask<T, Void, DocumentStack> {
Ben Lin7232bf02016-08-26 14:33:03 -070039
Garfield Tan23ac60c2017-03-13 17:40:43 -070040 private final LastAccessedStorage mLastAccessed;
Steve McKayd9caa6a2016-09-15 16:36:45 -070041 private final State mState;
Garfield Tanbab25162017-03-08 18:46:25 -080042 private final RootsAccess mRoots;
43 private final Consumer<DocumentStack> mCallback;
Ben Lin7232bf02016-08-26 14:33:03 -070044
Garfield Tanbab25162017-03-08 18:46:25 -080045 LoadLastAccessedStackTask(
Garfield Tan23ac60c2017-03-13 17:40:43 -070046 T activity,
47 LastAccessedStorage lastAccessed,
48 State state,
49 RootsAccess roots,
50 Consumer<DocumentStack> callback) {
Ben Lin7232bf02016-08-26 14:33:03 -070051 super(activity);
Garfield Tan23ac60c2017-03-13 17:40:43 -070052 mLastAccessed = lastAccessed;
Steve McKay988d8a32016-09-27 09:41:17 -070053 mRoots = roots;
Garfield Tanbab25162017-03-08 18:46:25 -080054 mState = state;
55 mCallback = callback;
Ben Lin7232bf02016-08-26 14:33:03 -070056 }
57
58 @Override
Garfield Tanbab25162017-03-08 18:46:25 -080059 protected DocumentStack run(Void... params) {
Garfield Tan23ac60c2017-03-13 17:40:43 -070060 return mLastAccessed.getLastAccessed(mOwner, mRoots, mState);
Ben Lin7232bf02016-08-26 14:33:03 -070061 }
62
63 @Override
Garfield Tanbab25162017-03-08 18:46:25 -080064 protected void finish(@Nullable DocumentStack stack) {
65 mCallback.accept(stack);
Ben Lin7232bf02016-08-26 14:33:03 -070066 }
Steve McKaydef48682016-10-03 09:07:38 -070067}