diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index 1fe6bf62c079..602be092a683 100755 --- a/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -234,7 +234,7 @@ private Activity getActivity() { public void onAccountChosen(@NonNull User user) { setAccount(user.toPlatformAccount(), false); initTargetFolder(); - populateDirectoryList(); + populateDirectoryList(null); } @Override @@ -258,7 +258,7 @@ private void browseToFolderIfItExists() { final OCFile fileByPath = getStorageManager().getFileByPath(full_path); if (fileByPath != null) { startSyncFolderOperation(fileByPath); - populateDirectoryList(); + populateDirectoryList(null); } else { browseToRoot(); preferences.setLastUploadPath(OCFile.ROOT_PATH); @@ -290,7 +290,7 @@ protected void onDestroy() { public void onSortingOrderChosen(FileSortOrder newSortOrder) { preferences.setSortOrder(mFile, newSortOrder); sortButton.setText(DisplayUtils.getSortOrderStringId(newSortOrder)); - populateDirectoryList(); + populateDirectoryList(null); } @Override @@ -310,8 +310,10 @@ public void selectFile(OCFile file) { } startSyncFolderOperation(file); - mParents.push(file.getFileName()); - populateDirectoryList(); + + String filename = fileDataStorageManager.getFileNameBasedOnEncryptionStatus(file); + mParents.push(filename); + populateDirectoryList(file); } } @@ -706,7 +708,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { // account at this point // since account setup can set only one account at time setAccount(accounts[0], false); - populateDirectoryList(); + populateDirectoryList(null); } } } @@ -721,7 +723,7 @@ private void setupActionBarSubtitle() { } } - private void populateDirectoryList() { + private void populateDirectoryList(OCFile file) { setupEmptyList(); setupToolbar(); ActionBar actionBar = getSupportActionBar(); @@ -737,7 +739,11 @@ private void populateDirectoryList() { if (TextUtils.isEmpty(current_dir)) { viewThemeUtils.files.themeActionBar(this, actionBar, R.string.uploader_top_message); } else { - viewThemeUtils.files.themeActionBar(this, actionBar, current_dir); + if (file != null) { + viewThemeUtils.files.themeActionBar(this, actionBar, file.getFileName()); + } else { + viewThemeUtils.files.themeActionBar(this, actionBar, current_dir); + } } actionBar.setDisplayHomeAsUpEnabled(notRoot); @@ -748,37 +754,44 @@ private void populateDirectoryList() { Log_OC.d(TAG, "Populating view with content of : " + full_path); - mFile = getStorageManager().getFileByPath(full_path); - if (mFile != null) { - List files = getStorageManager().getFolderContent(mFile, false); + if (file != null) { + mFile = file; + } else { + mFile = getStorageManager().getFileByPath(full_path); + } - if (files.isEmpty()) { - setMessageForEmptyList(R.string.file_list_empty_headline, R.string.empty, - R.drawable.uploads); - mEmptyListContainer.setVisibility(View.VISIBLE); - binding.list.setVisibility(View.GONE); - } else { - mEmptyListContainer.setVisibility(View.GONE); - files = sortFileList(files); - setupReceiveExternalFilesAdapter(files); - } + if (mFile == null) { + return; + } - MaterialButton btnChooseFolder = binding.uploaderChooseFolder; - viewThemeUtils.material.colorMaterialButtonPrimaryFilled(btnChooseFolder); - btnChooseFolder.setOnClickListener(this); + List files = getStorageManager().getFolderContent(mFile, false); - btnChooseFolder.setEnabled(mFile.canWrite()); + if (files.isEmpty()) { + setMessageForEmptyList(R.string.file_list_empty_headline, R.string.empty, + R.drawable.uploads); + mEmptyListContainer.setVisibility(View.VISIBLE); + binding.list.setVisibility(View.GONE); + } else { + mEmptyListContainer.setVisibility(View.GONE); + files = sortFileList(files); + setupReceiveExternalFilesAdapter(files); + } - viewThemeUtils.platform.themeStatusBar(this); + MaterialButton btnChooseFolder = binding.uploaderChooseFolder; + viewThemeUtils.material.colorMaterialButtonPrimaryFilled(btnChooseFolder); + btnChooseFolder.setOnClickListener(this); - viewThemeUtils.material.colorMaterialButtonPrimaryOutlined(binding.uploaderCancel); - binding.uploaderCancel.setOnClickListener(this); + btnChooseFolder.setEnabled(mFile.canWrite()); - sortButton = binding.toolbarLayout.sortButton; - FileSortOrder sortOrder = preferences.getSortOrderByFolder(mFile); - sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder)); - sortButton.setOnClickListener(l -> openSortingOrderDialogFragment(getSupportFragmentManager(), sortOrder)); - } + viewThemeUtils.platform.themeStatusBar(this); + + viewThemeUtils.material.colorMaterialButtonPrimaryOutlined(binding.uploaderCancel); + binding.uploaderCancel.setOnClickListener(this); + + sortButton = binding.toolbarLayout.sortButton; + FileSortOrder sortOrder = preferences.getSortOrderByFolder(mFile); + sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder)); + sortButton.setOnClickListener(l -> openSortingOrderDialogFragment(getSupportFragmentManager(), sortOrder)); } private void setupReceiveExternalFilesAdapter(List files) { @@ -969,19 +982,15 @@ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationRe * @param operation Creation operation performed. * @param result Result of the creation. */ - private void onCreateFolderOperationFinish(CreateFolderOperation operation, - RemoteOperationResult result) { + private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { String remotePath = operation.getRemotePath().substring(0, operation.getRemotePath().length() - 1); String newFolder = remotePath.substring(remotePath.lastIndexOf('/') + 1); mParents.push(newFolder); - populateDirectoryList(); + populateDirectoryList(null); } else { try { - DisplayUtils.showSnackMessage( - this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()) - ); - + DisplayUtils.showSnackMessage(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())); } catch (NotFoundException e) { Log_OC.e(TAG, "Error while trying to show fail message ", e); } @@ -1033,8 +1042,10 @@ public boolean onCreateOptionsMenu(Menu menu) { setupSearchView(menu); - MenuItem newFolderMenuItem = menu.findItem(R.id.action_create_dir); - newFolderMenuItem.setEnabled(mFile.canWrite()); + if (mFile != null) { + MenuItem newFolderMenuItem = menu.findItem(R.id.action_create_dir); + newFolderMenuItem.setEnabled(mFile.canWrite()); + } return true; } @@ -1145,9 +1156,8 @@ public void onReceive(Context context, Intent intent) { } if (currentDir.getRemotePath().equals(syncFolderRemotePath)) { - populateDirectoryList(); + populateDirectoryList(currentFile); } - mFile = currentFile; } mSyncInProgress = !FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&