From 7eed96e4f1970fa9ee901c5f61560d07bf0ec453 Mon Sep 17 00:00:00 2001 From: Bartosz Przybylski Date: Mon, 20 Jun 2016 18:09:56 +0200 Subject: [PATCH] Review fixes --- .../providers/DocumentsStorageProvider.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/org/nextcloud/providers/DocumentsStorageProvider.java b/src/org/nextcloud/providers/DocumentsStorageProvider.java index 8b619eecf6a7..75a907636ec3 100644 --- a/src/org/nextcloud/providers/DocumentsStorageProvider.java +++ b/src/org/nextcloud/providers/DocumentsStorageProvider.java @@ -69,7 +69,9 @@ public Cursor queryDocument(String documentId, String[] projection) throws FileN updateCurrentStorageManagerIfNeeded(docId); final FileCursor result = new FileCursor(projection); - result.addFile(mCurrentStorageManager.getFileById(docId)); + OCFile file = mCurrentStorageManager.getFileById(docId); + if (file != null) + result.addFile(file); return result; } @@ -84,8 +86,9 @@ public Cursor queryChildDocuments(String parentDocumentId, String[] projection, final FileCursor result = new FileCursor(projection); final OCFile browsedDir = mCurrentStorageManager.getFileById(folderId); - for (OCFile file : mCurrentStorageManager.getFolderContent(browsedDir)) + for (OCFile file : mCurrentStorageManager.getFolderContent(browsedDir)) { result.addFile(file); + } return result; } @@ -106,8 +109,9 @@ public ParcelFileDescriptor openDocument(String documentId, String mode, Cancell getContext().startService(i); do { - if (!waitOrGetCancelled(cancellationSignal)) + if (!waitOrGetCancelled(cancellationSignal)) { return null; + } file = mCurrentStorageManager.getFileById(docId); } while (!file.isDown()); @@ -123,7 +127,10 @@ public boolean onCreate() { } @Override - public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException { + public AssetFileDescriptor openDocumentThumbnail(String documentId, + Point sizeHint, + CancellationSignal signal) + throws FileNotFoundException { long docId = Long.parseLong(documentId); updateCurrentStorageManagerIfNeeded(docId); @@ -144,8 +151,9 @@ public Cursor querySearchDocuments(String rootId, String query, String[] project OCFile root = mCurrentStorageManager.getFileByPath("/"); FileCursor result = new FileCursor(projection); - for (OCFile f : findFiles(root, query)) + for (OCFile f : findFiles(root, query)) { result.addFile(f); + } return result; } @@ -160,8 +168,9 @@ private void updateCurrentStorageManagerIfNeeded(long docId) { private void updateCurrentStorageManagerIfNeeded(String rootId) { for (FileDataStorageManager data : mRootIdToStorageManager.values()) - if (data.getAccount().name.equals(rootId)) + if (data.getAccount().name.equals(rootId)) { mCurrentStorageManager = data; + } } private void initiateStorageMap() { @@ -186,8 +195,9 @@ private boolean waitOrGetCancelled(CancellationSignal cancellationSignal) { return false; } - if (cancellationSignal != null && cancellationSignal.isCanceled()) + if (cancellationSignal != null && cancellationSignal.isCanceled()) { return false; + } return true; } @@ -197,9 +207,8 @@ Vector findFiles(OCFile root, String query) { for (OCFile f : mCurrentStorageManager.getFolderContent(root)) { if (f.isFolder()) { result.addAll(findFiles(f, query)); - } else { - if (f.getFileName().contains(query)) - result.add(f); + } else if (f.getFileName().contains(query)) { + result.add(f); } } return result;