Example usage for android.provider DocumentsContract buildRecentDocumentsUri

List of usage examples for android.provider DocumentsContract buildRecentDocumentsUri

Introduction

In this page you can find the example usage for android.provider DocumentsContract buildRecentDocumentsUri.

Prototype

public static Uri buildRecentDocumentsUri(String authority, String rootId) 

Source Link

Document

Build URI representing the recently modified documents of a specific root in a document provider.

Usage

From source file:org.alfresco.mobile.android.application.providers.storage.StorageAccessDocumentsProvider.java

@Override
public Cursor queryRecentDocuments(String rootId, String[] projection) throws FileNotFoundException {
    // Log.v(TAG, "queryRecentDocuments" + rootId);

    final DocumentFolderCursor recentDocumentsCursor = new DocumentFolderCursor(
            resolveDocumentProjection(projection));
    Uri uri = DocumentsContract.buildRecentDocumentsUri(mAuthority, rootId);
    final EncodedQueryUri cUri = new EncodedQueryUri(rootId);

    Boolean active = mLoadingUris.get(uri);

    if (active != null) {
        for (Entry<String, Node> nodeEntry : nodesIndex.entrySet()) {
            addNodeRow(recentDocumentsCursor, nodeEntry.getValue());
        }/*from w  ww  .j ava  2  s  . c  om*/
        if (!active) {
            // loading request is finished and refreshed
            mLoadingUris.remove(uri);
        }
    }

    if (active == null) {
        new StorageProviderAsyncTask(uri, recentDocumentsCursor, true) {
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    checkSession(cUri);
                    GregorianCalendar calendar = new GregorianCalendar();
                    calendar.add(Calendar.DAY_OF_YEAR, -7);
                    String formatedDate = DateUtils.format(calendar);
                    List<Node> nodes = session.getServiceRegistry().getSearchService()
                            .search(String.format(QUERY_RECENT, formatedDate), SearchLanguage.CMIS);

                    for (Node node : nodes) {
                        nodesIndex.put(NodeRefUtils.getVersionIdentifier(node.getIdentifier()), node);
                    }

                } catch (Exception e) {
                    exception = null;
                    Log.w(TAG, Log.getStackTraceString(e));
                }
                return null;
            }
        }.execute();
    }
    return recentDocumentsCursor;
}