From 6c2d881dfeb0c256290a5638cf76f68078334f2f Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Sun, 30 Apr 2017 12:14:39 +0200 Subject: [PATCH] - search view shows data again - no crash while rotation during search view is populated --- .../android/datamodel/FileDataStorageManager.java | 14 +++++++------- .../android/ui/adapter/FileListListAdapter.java | 4 ++-- .../android/ui/fragment/OCFileListFragment.java | 14 ++------------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index 4706e3d6f0..57d779c7c5 100644 --- a/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -251,7 +251,7 @@ public class FileDataStorageManager { return overriden; } - public long saveFileWithParent(OCFile file, Context context) { + public OCFile saveFileWithParent(OCFile file, Context context) { if (file.getParentId() != 0 || file.getRemotePath().equals("/")) { saveFile(file); @@ -261,7 +261,7 @@ public class FileDataStorageManager { OCFile parentFile = getFileByPath(parentPath); - long fileId; + OCFile returnFile; if (parentFile == null) { // remote request ReadRemoteFileOperation operation = new ReadRemoteFileOperation(parentPath); @@ -269,20 +269,20 @@ public class FileDataStorageManager { if (result.isSuccess()) { OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0)); - fileId = saveFileWithParent(remoteFolder, context); + returnFile = saveFileWithParent(remoteFolder, context); } else { - fileId = -1; + returnFile = null; Log_OC.e(TAG, "Error during saving file with parents: " + file.getRemotePath()); } } else { - fileId = saveFileWithParent(parentFile, context); + returnFile = saveFileWithParent(parentFile, context); } - file.setParentId(fileId); + file.setParentId(returnFile.getFileId()); saveFile(file); } - return getFileByPath(file.getRemotePath()).getFileId(); + return file; } public void saveNewFile(OCFile newFile) { diff --git a/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java index ca9473f71f..099df3d284 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -561,8 +561,8 @@ public class FileListListAdapter extends BaseAdapter { for (int i = 0; i < objects.size(); i++) { OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i)); searchForLocalFileInDefaultPath(ocFile); - mStorageManager.saveFileWithParent(ocFile, mContext); - mStorageManager.saveVirtual(type, mStorageManager.getFileByPath(ocFile.getRemotePath())); + ocFile = mStorageManager.saveFileWithParent(ocFile, mContext); + mStorageManager.saveVirtual(type, ocFile); } mFiles.addAll(mStorageManager.getVirtualFolderContent(type, onlyImages)); diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index f60160f157..dca7d33a23 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -251,10 +251,6 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi public void onResume() { super.onResume(); - if (remoteOperationAsyncTask != null) { - remoteOperationAsyncTask.cancel(true); - } - if (getActivity() != null) { AnalyticsUtils.setCurrentScreenName(getActivity(), SCREEN_NAME, TAG); } @@ -322,7 +318,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi } searchEvent = Parcels.unwrap(getArguments().getParcelable(OCFileListFragment.SEARCH_EVENT)); - if (searchEvent != null) { + if (searchEvent != null && searchFragment) { onMessageEvent(searchEvent); } } @@ -964,10 +960,6 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi public void refreshDirectory() { searchFragment = false; - if (remoteOperationAsyncTask != null) { - remoteOperationAsyncTask.cancel(true); - } - setFabEnabled(true); listDirectory(getCurrentFile(), MainApp.isOnlyOnDevice(), false); } @@ -1449,8 +1441,6 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi } else { new Handler(Looper.getMainLooper()).post(switchViewsRunnable); } - - searchEvent = null; } private void setTitle(@StringRes int title) { @@ -1474,7 +1464,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi public void onRefresh() { super.onRefresh(); - if (searchEvent != null) { + if (searchEvent != null && searchFragment) { onMessageEvent(searchEvent); } }