blob: f9eacaa0afb568ff98bdc30f419b62756d3ae954 [file] [log] [blame]
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -07001/*
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
17package com.android.documentsui;
18
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070019import android.content.Context;
20import android.database.Cursor;
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070021import android.net.Uri;
22import android.provider.DocumentsContract;
Jeff Sharkey9656a532013-09-13 13:42:19 -070023import android.provider.DocumentsContract.Document;
Jeff Sharkey9dd02622013-09-27 16:44:11 -070024import android.text.format.DateUtils;
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070025
Garfield Tan2e81db62017-04-27 15:06:49 -070026import com.android.documentsui.base.Lookup;
Steve McKayd0805062016-09-15 14:30:38 -070027import com.android.documentsui.base.RootInfo;
Steve McKayd9caa6a2016-09-15 16:36:45 -070028import com.android.documentsui.base.State;
Jon Mann9bd40992017-03-24 12:34:34 -070029import com.android.documentsui.roots.ProvidersAccess;
Steve McKayd9caa6a2016-09-15 16:36:45 -070030import com.android.documentsui.roots.RootCursorWrapper;
Steve McKay1aeb3952016-02-18 09:48:39 -080031
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070032import java.util.List;
Garfield Tan2e81db62017-04-27 15:06:49 -070033import java.util.concurrent.Executor;
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070034
Ivan Chiang282baa42018-08-08 18:54:14 +080035public class RecentsLoader extends MultiRootDocumentsLoader {
Jeff Sharkey9dd02622013-09-27 16:44:11 -070036
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 Chiang282baa42018-08-08 18:54:14 +080041 private static final String[] REJECT_MIMES = new String[]{Document.MIME_TYPE_DIR};
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070042
Ivan Chiang282baa42018-08-08 18:54:14 +080043 /** Maximum documents from a single root. */
44 private static final int MAX_DOCS_FROM_ROOT = 64;
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070045
Ivan Chiang282baa42018-08-08 18:54:14 +080046 public RecentsLoader(Context context, ProvidersAccess providers, State state,
Garfield Tanb47b4b52017-05-16 12:48:53 -070047 Lookup<String, Executor> executors, Lookup<String, String> fileTypeMap) {
Ivan Chiang282baa42018-08-08 18:54:14 +080048 super(context, providers, state, executors, fileTypeMap);
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070049 }
50
51 @Override
Ivan Chiang282baa42018-08-08 18:54:14 +080052 protected long getRejectBeforeTime() {
53 return System.currentTimeMillis() - REJECT_OLDER_THAN;
Ben Lin1427c602016-09-22 14:12:19 -070054 }
55
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070056 @Override
Ivan Chiang282baa42018-08-08 18:54:14 +080057 protected String[] getRejectMimes() {
58 return REJECT_MIMES;
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070059 }
60
61 @Override
Ivan Chiang282baa42018-08-08 18:54:14 +080062 protected boolean shouldIgnoreRoot(RootInfo root) {
63 // only query the root is local only and support recents
64 return !root.isLocalOnly() || !root.supportsRecents();
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070065 }
66
67 @Override
Ivan Chiang282baa42018-08-08 18:54:14 +080068 protected QueryTask getQueryTask(String authority, List<RootInfo> rootInfos) {
69 return new RecentsTask(authority, rootInfos);
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070070 }
71
Ivan Chiang282baa42018-08-08 18:54:14 +080072 private class RecentsTask extends QueryTask {
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070073
Ivan Chiang282baa42018-08-08 18:54:14 +080074 public RecentsTask(String authority, List<RootInfo> rootInfos) {
75 super(authority, rootInfos);
Steve McKay1aeb3952016-02-18 09:48:39 -080076 }
77
78 @Override
Ivan Chiang282baa42018-08-08 18:54:14 +080079 protected Uri getQueryUri(RootInfo rootInfo) {
80 return DocumentsContract.buildRecentDocumentsUri(authority, rootInfo.rootId);
Steve McKay1aeb3952016-02-18 09:48:39 -080081 }
82
83 @Override
Ivan Chiang282baa42018-08-08 18:54:14 +080084 protected RootCursorWrapper generateResultCursor(RootInfo rootInfo, Cursor oriCursor) {
85 return new RootCursorWrapper(authority, rootInfo.rootId, oriCursor, MAX_DOCS_FROM_ROOT);
Garfield Tan2e81db62017-04-27 15:06:49 -070086 }
87 }
Jeff Sharkeyd82b26b2013-09-02 15:07:28 -070088}