blob: 728b70c2deddb9b24e02fda2e5b9fb456fb10fcc [file] [log] [blame]
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.documentsui.picker;
import android.app.Activity;
import com.android.documentsui.AbstractActionHandler.CommonAddons;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.PairedTask;
import com.android.documentsui.base.State;
import com.android.documentsui.roots.RootsAccess;
import java.util.function.Consumer;
import javax.annotation.Nullable;
/**
* Loads the last used path (stack) from Recents (history).
* The path selected is based on the calling package name. So the last
* path for an app like Gmail can be different than the last path
* for an app like DropBox.
*/
final class LoadLastAccessedStackTask<T extends Activity & CommonAddons>
extends PairedTask<T, Void, DocumentStack> {
private final LastAccessedStorage mLastAccessed;
private final State mState;
private final RootsAccess mRoots;
private final Consumer<DocumentStack> mCallback;
LoadLastAccessedStackTask(
T activity,
LastAccessedStorage lastAccessed,
State state,
RootsAccess roots,
Consumer<DocumentStack> callback) {
super(activity);
mLastAccessed = lastAccessed;
mRoots = roots;
mState = state;
mCallback = callback;
}
@Override
protected DocumentStack run(Void... params) {
return mLastAccessed.getLastAccessed(mOwner, mRoots, mState);
}
@Override
protected void finish(@Nullable DocumentStack stack) {
mCallback.accept(stack);
}
}