Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 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 | |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 17 | package com.android.documentsui.picker; |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 18 | |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 20 | |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 21 | import com.android.documentsui.AbstractActionHandler.CommonAddons; |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 22 | import com.android.documentsui.base.DocumentStack; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 23 | import com.android.documentsui.base.PairedTask; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 24 | import com.android.documentsui.base.State; |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 25 | import com.android.documentsui.roots.RootsAccess; |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 26 | |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 27 | import java.util.function.Consumer; |
| 28 | |
| 29 | import javax.annotation.Nullable; |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 30 | |
| 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 McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 37 | final class LoadLastAccessedStackTask<T extends Activity & CommonAddons> |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 38 | extends PairedTask<T, Void, DocumentStack> { |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 39 | |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 40 | private final LastAccessedStorage mLastAccessed; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 41 | private final State mState; |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 42 | private final RootsAccess mRoots; |
| 43 | private final Consumer<DocumentStack> mCallback; |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 44 | |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 45 | LoadLastAccessedStackTask( |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 46 | T activity, |
| 47 | LastAccessedStorage lastAccessed, |
| 48 | State state, |
| 49 | RootsAccess roots, |
| 50 | Consumer<DocumentStack> callback) { |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 51 | super(activity); |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 52 | mLastAccessed = lastAccessed; |
Steve McKay | 988d8a3 | 2016-09-27 09:41:17 -0700 | [diff] [blame] | 53 | mRoots = roots; |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 54 | mState = state; |
| 55 | mCallback = callback; |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 59 | protected DocumentStack run(Void... params) { |
Garfield Tan | 23ac60c | 2017-03-13 17:40:43 -0700 | [diff] [blame] | 60 | return mLastAccessed.getLastAccessed(mOwner, mRoots, mState); |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
Garfield Tan | bab2516 | 2017-03-08 18:46:25 -0800 | [diff] [blame] | 64 | protected void finish(@Nullable DocumentStack stack) { |
| 65 | mCallback.accept(stack); |
Ben Lin | 7232bf0 | 2016-08-26 14:33:03 -0700 | [diff] [blame] | 66 | } |
Steve McKay | def4868 | 2016-10-03 09:07:38 -0700 | [diff] [blame] | 67 | } |