• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.content.Context;
20 import android.database.Cursor;
21 import android.net.Uri;
22 import android.provider.DocumentsContract;
23 import android.provider.DocumentsContract.Document;
24 import android.text.format.DateUtils;
25 
26 import com.android.documentsui.base.Lookup;
27 import com.android.documentsui.base.RootInfo;
28 import com.android.documentsui.base.State;
29 import com.android.documentsui.roots.ProvidersAccess;
30 import com.android.documentsui.roots.RootCursorWrapper;
31 
32 import java.util.List;
33 import java.util.concurrent.Executor;
34 
35 public class RecentsLoader extends MultiRootDocumentsLoader {
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. */
41     private static final String[] REJECT_MIMES = new String[]{Document.MIME_TYPE_DIR};
42 
43     /** Maximum documents from a single root. */
44     private static final int MAX_DOCS_FROM_ROOT = 64;
45 
RecentsLoader(Context context, ProvidersAccess providers, State state, Lookup<String, Executor> executors, Lookup<String, String> fileTypeMap)46     public RecentsLoader(Context context, ProvidersAccess providers, State state,
47             Lookup<String, Executor> executors, Lookup<String, String> fileTypeMap) {
48         super(context, providers, state, executors, fileTypeMap);
49     }
50 
51     @Override
getRejectBeforeTime()52     protected long getRejectBeforeTime() {
53         return System.currentTimeMillis() - REJECT_OLDER_THAN;
54     }
55 
56     @Override
getRejectMimes()57     protected String[] getRejectMimes() {
58         return REJECT_MIMES;
59     }
60 
61     @Override
shouldIgnoreRoot(RootInfo root)62     protected boolean shouldIgnoreRoot(RootInfo root) {
63         // only query the root is local only and support recents
64         return !root.isLocalOnly() || !root.supportsRecents();
65     }
66 
67     @Override
getQueryTask(String authority, List<RootInfo> rootInfos)68     protected QueryTask getQueryTask(String authority, List<RootInfo> rootInfos) {
69         return new RecentsTask(authority, rootInfos);
70     }
71 
72     private class RecentsTask extends QueryTask {
73 
RecentsTask(String authority, List<RootInfo> rootInfos)74         public RecentsTask(String authority, List<RootInfo> rootInfos) {
75             super(authority, rootInfos);
76         }
77 
78         @Override
getQueryUri(RootInfo rootInfo)79         protected Uri getQueryUri(RootInfo rootInfo) {
80             return DocumentsContract.buildRecentDocumentsUri(authority, rootInfo.rootId);
81         }
82 
83         @Override
generateResultCursor(RootInfo rootInfo, Cursor oriCursor)84         protected RootCursorWrapper generateResultCursor(RootInfo rootInfo, Cursor oriCursor) {
85             return new RootCursorWrapper(authority, rootInfo.rootId, oriCursor, MAX_DOCS_FROM_ROOT);
86         }
87     }
88 }
89