Skip to content

Commit 9b69807

Browse files
Merge pull request nextcloud#13745 from nextcloud/bugfix/check-existence-of-oc-upload
BugFix - Check Existence of OCUpload
2 parents c530e22 + f1d172d commit 9b69807

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656

5757
import java.io.File;
5858
import java.util.Arrays;
59-
import java.util.List;
6059
import java.util.Optional;
6160

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

120119
headerViewHolder.binding.uploadListAction.setOnClickListener(v -> {
121120
switch (group.type) {
122-
case CURRENT -> {
123-
new Thread(() -> {
124-
uploadHelper.cancelFileUploads(
125-
Arrays.asList(group.items),
126-
group.getItem(0).getAccountName());
127-
parentActivity.runOnUiThread(this::loadUploadItemsFromDb);
128-
}).start();
129-
}
121+
case CURRENT -> new Thread(() -> {
122+
OCUpload ocUpload = group.getItem(0);
123+
if (ocUpload == null) {
124+
return;
125+
}
126+
127+
String accountName = ocUpload.getAccountName();
128+
if (accountName == null) {
129+
return;
130+
}
131+
132+
uploadHelper.cancelFileUploads(Arrays.asList(group.items), accountName);
133+
parentActivity.runOnUiThread(this::loadUploadItemsFromDb);
134+
}).start();
130135
case FINISHED -> {
131136
uploadsStorageManager.clearSuccessfulUploads();
132137
loadUploadItemsFromDb();
@@ -287,16 +292,27 @@ public void refresh() {
287292

288293
@Override
289294
public void onBindViewHolder(SectionedViewHolder holder, int section, int relativePosition, int absolutePosition) {
290-
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
295+
if (uploadGroups.length == 0 || section < 0 || section >= uploadGroups.length) {
296+
return;
297+
}
298+
299+
UploadGroup uploadGroup = uploadGroups[section];
300+
if (uploadGroup == null) {
301+
return;
302+
}
291303

292-
OCUpload item = uploadGroups[section].getItem(relativePosition);
304+
OCUpload item = uploadGroup.getItem(relativePosition);
305+
if (item == null) {
306+
return;
307+
}
293308

309+
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
294310
itemViewHolder.binding.uploadName.setText(item.getLocalPath());
295311

296312
// local file name
297313
File remoteFile = new File(item.getRemotePath());
298314
String fileName = remoteFile.getName();
299-
if (fileName.length() == 0) {
315+
if (fileName.isEmpty()) {
300316
fileName = File.separator;
301317
}
302318
itemViewHolder.binding.uploadName.setText(fileName);
@@ -937,9 +953,9 @@ enum Type {
937953
}
938954

939955
abstract class UploadGroup implements Refresh {
940-
private Type type;
956+
private final Type type;
941957
private OCUpload[] items;
942-
private String name;
958+
private final String name;
943959

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

958974
public OCUpload getItem(int position) {
975+
if (items.length == 0 || position < 0 || position >= items.length) {
976+
return null;
977+
}
978+
959979
return items[position];
960980
}
961981

0 commit comments

Comments
 (0)