Skip to content

Commit

Permalink
Merge pull request #13745 from nextcloud/bugfix/check-existence-of-oc…
Browse files Browse the repository at this point in the history
…-upload

BugFix - Check Existence of OCUpload
  • Loading branch information
tobiasKaminsky authored Oct 9, 2024
2 parents c530e22 + f1d172d commit 9b69807
Showing 1 changed file with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -119,14 +118,20 @@ public void onBindHeaderViewHolder(SectionedViewHolder holder, int section, bool

headerViewHolder.binding.uploadListAction.setOnClickListener(v -> {
switch (group.type) {
case CURRENT -> {
new Thread(() -> {
uploadHelper.cancelFileUploads(
Arrays.asList(group.items),
group.getItem(0).getAccountName());
parentActivity.runOnUiThread(this::loadUploadItemsFromDb);
}).start();
}
case CURRENT -> new Thread(() -> {
OCUpload ocUpload = group.getItem(0);
if (ocUpload == null) {
return;
}

String accountName = ocUpload.getAccountName();
if (accountName == null) {
return;
}

uploadHelper.cancelFileUploads(Arrays.asList(group.items), accountName);
parentActivity.runOnUiThread(this::loadUploadItemsFromDb);
}).start();
case FINISHED -> {
uploadsStorageManager.clearSuccessfulUploads();
loadUploadItemsFromDb();
Expand Down Expand Up @@ -287,16 +292,27 @@ public void refresh() {

@Override
public void onBindViewHolder(SectionedViewHolder holder, int section, int relativePosition, int absolutePosition) {
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
if (uploadGroups.length == 0 || section < 0 || section >= uploadGroups.length) {
return;
}

UploadGroup uploadGroup = uploadGroups[section];
if (uploadGroup == null) {
return;
}

OCUpload item = uploadGroups[section].getItem(relativePosition);
OCUpload item = uploadGroup.getItem(relativePosition);
if (item == null) {
return;
}

ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
itemViewHolder.binding.uploadName.setText(item.getLocalPath());

// local file name
File remoteFile = new File(item.getRemotePath());
String fileName = remoteFile.getName();
if (fileName.length() == 0) {
if (fileName.isEmpty()) {
fileName = File.separator;
}
itemViewHolder.binding.uploadName.setText(fileName);
Expand Down Expand Up @@ -937,9 +953,9 @@ enum Type {
}

abstract class UploadGroup implements Refresh {
private Type type;
private final Type type;
private OCUpload[] items;
private String name;
private final String name;

UploadGroup(Type type, String groupName) {
this.type = type;
Expand All @@ -956,6 +972,10 @@ public OCUpload[] getItems() {
}

public OCUpload getItem(int position) {
if (items.length == 0 || position < 0 || position >= items.length) {
return null;
}

return items[position];
}

Expand Down

0 comments on commit 9b69807

Please sign in to comment.