Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 7, 2023
1 parent 96cb61b commit 8f90565
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 65 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/nextcloud/model/HTTPStatusCodes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package com.nextcloud.model

@Suppress("MagicNumber")
enum class HTTPStatusCodes(val code: Int) {
NOT_FOUND(404)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
return
}

@Suppress("NestedBlockDepth")
private fun setupPushWarning() {
if (!resources.getBoolean(R.bool.show_push_warning)) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.owncloud.android.utils.theme.ViewThemeUtils;

import java.util.ArrayList;
import java.util.Collections;

import javax.inject.Inject;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
private static final String TAG = UploadListAdapter.class.getSimpleName();

private ProgressListener progressListener;
private FileActivity parentActivity;
private UploadsStorageManager uploadsStorageManager;
private FileDataStorageManager storageManager;
private ConnectivityService connectivityService;
private PowerManagementService powerManagementService;
private UserAccountManager accountManager;
private Clock clock;
private UploadGroup[] uploadGroups;
private boolean showUser;
private final FileActivity parentActivity;
private final UploadsStorageManager uploadsStorageManager;
private final FileDataStorageManager storageManager;
private final ConnectivityService connectivityService;
private final PowerManagementService powerManagementService;
private final UserAccountManager accountManager;
private final Clock clock;
private final UploadGroup[] uploadGroups;
private final boolean showUser;
private final ViewThemeUtils viewThemeUtils;

@Override
Expand All @@ -115,42 +115,31 @@ public void onBindHeaderViewHolder(SectionedViewHolder holder, int section, bool
headerViewHolder.binding.uploadListTitle.setOnClickListener(v -> 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();
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8f90565

Please sign in to comment.