From 8f9056562e2adb84def7eee802fdd3c6c09a4fc8 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 7 Dec 2023 13:53:35 +0100 Subject: [PATCH] Simplify code Signed-off-by: alperozturk --- .../com/nextcloud/model/HTTPStatusCodes.kt | 3 +- .../ui/activity/NotificationsActivity.kt | 1 + .../ui/activity/UploadListActivity.java | 10 +- .../android/ui/adapter/UploadListAdapter.java | 91 +++++++------------ 4 files changed, 40 insertions(+), 65 deletions(-) diff --git a/app/src/main/java/com/nextcloud/model/HTTPStatusCodes.kt b/app/src/main/java/com/nextcloud/model/HTTPStatusCodes.kt index 2f7e58364d3d..a357a7e76467 100644 --- a/app/src/main/java/com/nextcloud/model/HTTPStatusCodes.kt +++ b/app/src/main/java/com/nextcloud/model/HTTPStatusCodes.kt @@ -21,6 +21,7 @@ package com.nextcloud.model +@Suppress("MagicNumber") enum class HTTPStatusCodes(val code: Int) { NOT_FOUND(404) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt index f0e5ec2cd874..82ae5bea7a98 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt @@ -128,6 +128,7 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { return } + @Suppress("NestedBlockDepth") private fun setupPushWarning() { if (!resources.getBoolean(R.bool.show_push_warning)) { return diff --git a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java index fc31cf7f824a..10cdff44fd7f 100755 --- a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java @@ -63,6 +63,7 @@ import com.owncloud.android.utils.theme.ViewThemeUtils; import java.util.ArrayList; +import java.util.Collections; import javax.inject.Inject; @@ -181,11 +182,10 @@ public void positiveAction() { @Override public void negativeAction() { - OCFile fileOnlyExistOnLocalStorage = uploadListAdapter.getSelectedOCFile(); - getFileOperationsHelper().removeFiles(new ArrayList<>() {{ - add(fileOnlyExistOnLocalStorage); - }}, false, false); - uploadListAdapter.removeUpload(uploadListAdapter.selectedOCUpload); + OCUpload upload = uploadListAdapter.selectedOCUpload; + OCFile fileOnlyExistOnLocalStorage = getStorageManager().getFileByEncryptedRemotePath(upload.getRemotePath()); + getFileOperationsHelper().removeFiles(Collections.singletonList(fileOnlyExistOnLocalStorage), false, false); + uploadListAdapter.removeUpload(upload); } }); dialog.show(this.getSupportFragmentManager(), null); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java index a5ffdbe80c76..f2795eac0f86 100755 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java @@ -80,15 +80,15 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter toggleSectionExpanded(section)); switch (group.type) { - case CURRENT: - case FINISHED: - headerViewHolder.binding.uploadListAction.setImageResource(R.drawable.ic_close); - break; - case FAILED: - headerViewHolder.binding.uploadListAction.setImageResource(R.drawable.ic_sync); - break; + case CURRENT, FINISHED -> headerViewHolder.binding.uploadListAction.setImageResource(R.drawable.ic_close); + case FAILED -> headerViewHolder.binding.uploadListAction.setImageResource(R.drawable.ic_sync); } headerViewHolder.binding.uploadListAction.setOnClickListener(v -> { switch (group.type) { - case CURRENT: + case CURRENT -> { FileUploader.FileUploaderBinder uploaderBinder = parentActivity.getFileUploaderBinder(); - if (uploaderBinder != null) { for (OCUpload upload : group.getItems()) { uploaderBinder.cancel(upload); } } - break; - case FINISHED: - uploadsStorageManager.clearSuccessfulUploads(); - break; - case FAILED: - new Thread(() -> FileUploader.retryFailedUploads( - parentActivity, - uploadsStorageManager, - connectivityService, - accountManager, - powerManagementService - )).start(); - break; - - default: - // do nothing - break; + } + case FINISHED -> uploadsStorageManager.clearSuccessfulUploads(); + case FAILED -> new Thread(() -> FileUploader.retryFailedUploads( + parentActivity, + uploadsStorageManager, + connectivityService, + accountManager, + powerManagementService + )).start(); + default -> { + } + // do nothing } loadUploadItemsFromDb(); @@ -213,11 +202,14 @@ public void refresh() { loadUploadItemsFromDb(); } + public OCUpload selectedOCUpload; + @Override public void onBindViewHolder(SectionedViewHolder holder, int section, int relativePosition, int absolutePosition) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; OCUpload item = uploadGroups[section].getItem(relativePosition); + selectedOCUpload = item; itemViewHolder.binding.uploadName.setText(item.getLocalPath()); @@ -272,11 +264,10 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati // Update information depending of upload details String status = getStatusText(item); switch (item.getUploadStatus()) { - case UPLOAD_IN_PROGRESS: + case UPLOAD_IN_PROGRESS -> { viewThemeUtils.platform.themeHorizontalProgressBar(itemViewHolder.binding.uploadProgressBar); itemViewHolder.binding.uploadProgressBar.setProgress(0); itemViewHolder.binding.uploadProgressBar.setVisibility(View.VISIBLE); - FileUploader.FileUploaderBinder binder = parentActivity.getFileUploaderBinder(); if (binder != null) { if (binder.isUploadingNow(item)) { @@ -286,7 +277,7 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati binder.removeDatatransferProgressListener( progressListener, progressListener.getUpload() // the one that was added - ); + ); } // ... then, bind the current progress bar to listen for updates progressListener = new ProgressListener(item, itemViewHolder.binding.uploadProgressBar); @@ -304,19 +295,12 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati } else { Log_OC.w(TAG, "FileUploaderBinder not ready yet for upload " + item.getRemotePath()); } - itemViewHolder.binding.uploadDate.setVisibility(View.GONE); itemViewHolder.binding.uploadFileSize.setVisibility(View.GONE); itemViewHolder.binding.uploadProgressBar.invalidate(); - break; - - case UPLOAD_FAILED: - itemViewHolder.binding.uploadDate.setVisibility(View.GONE); - break; - - case UPLOAD_SUCCEEDED: - itemViewHolder.binding.uploadStatus.setVisibility(View.GONE); - break; + } + case UPLOAD_FAILED -> itemViewHolder.binding.uploadDate.setVisibility(View.GONE); + case UPLOAD_SUCCEEDED -> itemViewHolder.binding.uploadStatus.setVisibility(View.GONE); } itemViewHolder.binding.uploadStatus.setText(status); @@ -502,9 +486,6 @@ private boolean checkAndOpenConflictResolutionDialog(User user, ItemViewHolder itemViewHolder, OCUpload item, String status) { - // TODO Optimize - selectedOCUpload = item; - selectedFileRemotePath = item.getRemotePath(); String remotePath = item.getRemotePath(); OCFile localFile = storageManager.getFileByEncryptedRemotePath(remotePath); @@ -529,8 +510,6 @@ private boolean checkAndOpenConflictResolutionDialog(User user, return false; } - public OCUpload selectedOCUpload; - private void refreshFolderAndUpdateUI(ItemViewHolder holder, User user, OCFile folder, String remotePath, OCUpload item, String status) { Context context = MainApp.getAppContext(); @@ -575,12 +554,6 @@ private void showItemConflictPopup(User user, popup.show(); } - private String selectedFileRemotePath; - - public OCFile getSelectedOCFile() { - return storageManager.getFileByEncryptedRemotePath(selectedFileRemotePath); - } - public void removeUpload(OCUpload item) { uploadsStorageManager.removeUpload(item); loadUploadItemsFromDb();