private ICursor GetQuery(DocumentTaskTypes taskType, DocumentsProvider provider, string parentDocumentId, string query) { switch (taskType) { case DocumentTaskTypes.QueryChildDocuments: return(provider.QueryChildDocuments(parentDocumentId, FileDocumentItem.DocumentProjection, (string)null)); case DocumentTaskTypes.QuerySearchDocuments: return(provider.QuerySearchDocuments(parentDocumentId, query, FileDocumentItem.DocumentProjection)); case DocumentTaskTypes.QueryDocument: return(provider.QueryDocument(parentDocumentId, FileDocumentItem.DocumentProjection)); default: throw new NotImplementedException(taskType.ToString()); } }
private FileDocumentItem[] RunInBackground(DocumentTaskTypes documentTaskType, DocumentsProvider provider, string parentDocumentId, string query, string searchMimeType, bool?isCategoryOpenable, out string parentId) { parentId = null; var result = new List <FileDocumentItem>(); var isFirstRecord = documentTaskType == DocumentTaskTypes.QuerySearchDocuments; using (var cursor = GetQuery(documentTaskType, provider, parentDocumentId, query)) { if (cursor == null || cursor.Count == 0) { return(null); } while (cursor.MoveToNext()) { if (IfCancellationRequested()) { return(null); } if (isFirstRecord) { isFirstRecord = false; var columnIndex = cursor.GetColumnIndex(Sb49DocumentsContract.Document.ColumnParentDocumentId); if (columnIndex >= 0) { parentId = cursor.GetString(columnIndex); } } var item = new FileDocumentItem(provider.Context, cursor); if (!item.IsFolder) { if (isCategoryOpenable == true && !Util.HasFlags(item.Flags, (int)DocumentContractFlags.SupportsWrite)) { continue; } if (!string.IsNullOrEmpty(searchMimeType) && !string.Equals(item.MimeType, searchMimeType, StringComparison.OrdinalIgnoreCase)) { continue; } } result.Add(item); } cursor.Close(); } if (IfCancellationRequested()) { return(null); } return(result.ToArray()); }