Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.database.Cursor; |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 21 | import android.net.Uri; |
| 22 | import android.provider.DocumentsContract; |
Jeff Sharkey | 9656a53 | 2013-09-13 13:42:19 -0700 | [diff] [blame] | 23 | import android.provider.DocumentsContract.Document; |
Jeff Sharkey | 9dd0262 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 24 | import android.text.format.DateUtils; |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 25 | |
Garfield Tan | 2e81db6 | 2017-04-27 15:06:49 -0700 | [diff] [blame] | 26 | import com.android.documentsui.base.Lookup; |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 27 | import com.android.documentsui.base.RootInfo; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 28 | import com.android.documentsui.base.State; |
Jon Mann | 9bd4099 | 2017-03-24 12:34:34 -0700 | [diff] [blame] | 29 | import com.android.documentsui.roots.ProvidersAccess; |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 30 | import com.android.documentsui.roots.RootCursorWrapper; |
Steve McKay | 1aeb395 | 2016-02-18 09:48:39 -0800 | [diff] [blame] | 31 | |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 32 | import java.util.List; |
Garfield Tan | 2e81db6 | 2017-04-27 15:06:49 -0700 | [diff] [blame] | 33 | import java.util.concurrent.Executor; |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 34 | |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 35 | public class RecentsLoader extends MultiRootDocumentsLoader { |
Jeff Sharkey | 9dd0262 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 36 | |
| 37 | /** Ignore documents older than this age. */ |
| 38 | private static final long REJECT_OLDER_THAN = 45 * DateUtils.DAY_IN_MILLIS; |
| 39 | |
| 40 | /** MIME types that should always be excluded from recents. */ |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 41 | private static final String[] REJECT_MIMES = new String[]{Document.MIME_TYPE_DIR}; |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 42 | |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 43 | /** Maximum documents from a single root. */ |
| 44 | private static final int MAX_DOCS_FROM_ROOT = 64; |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 45 | |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 46 | public RecentsLoader(Context context, ProvidersAccess providers, State state, |
Garfield Tan | b47b4b5 | 2017-05-16 12:48:53 -0700 | [diff] [blame] | 47 | Lookup<String, Executor> executors, Lookup<String, String> fileTypeMap) { |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 48 | super(context, providers, state, executors, fileTypeMap); |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 52 | protected long getRejectBeforeTime() { |
| 53 | return System.currentTimeMillis() - REJECT_OLDER_THAN; |
Ben Lin | 1427c60 | 2016-09-22 14:12:19 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 56 | @Override |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 57 | protected String[] getRejectMimes() { |
| 58 | return REJECT_MIMES; |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 62 | protected boolean shouldIgnoreRoot(RootInfo root) { |
| 63 | // only query the root is local only and support recents |
| 64 | return !root.isLocalOnly() || !root.supportsRecents(); |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 68 | protected QueryTask getQueryTask(String authority, List<RootInfo> rootInfos) { |
| 69 | return new RecentsTask(authority, rootInfos); |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 72 | private class RecentsTask extends QueryTask { |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 73 | |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 74 | public RecentsTask(String authority, List<RootInfo> rootInfos) { |
| 75 | super(authority, rootInfos); |
Steve McKay | 1aeb395 | 2016-02-18 09:48:39 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 79 | protected Uri getQueryUri(RootInfo rootInfo) { |
| 80 | return DocumentsContract.buildRecentDocumentsUri(authority, rootInfo.rootId); |
Steve McKay | 1aeb395 | 2016-02-18 09:48:39 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
Ivan Chiang | 282baa4 | 2018-08-08 18:54:14 +0800 | [diff] [blame] | 84 | protected RootCursorWrapper generateResultCursor(RootInfo rootInfo, Cursor oriCursor) { |
| 85 | return new RootCursorWrapper(authority, rootInfo.rootId, oriCursor, MAX_DOCS_FROM_ROOT); |
Garfield Tan | 2e81db6 | 2017-04-27 15:06:49 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
Jeff Sharkey | d82b26b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 88 | } |