|
64 | 64 |
|
65 | 65 | import androidx.annotation.NonNull; |
66 | 66 | import kotlin.Unit; |
| 67 | +import kotlin.jvm.functions.Function0; |
67 | 68 |
|
68 | 69 | /** |
69 | 70 | * This Adapter populates a ListView with following types of uploads: pending, active, completed. Filtering possible. |
@@ -176,11 +177,31 @@ public void onBindHeaderViewHolder(SectionedViewHolder holder, int section, bool |
176 | 177 | case CURRENT -> { |
177 | 178 | String accountName = group.items()[0].getAccountName(); |
178 | 179 |
|
179 | | - for (OCUpload upload: group.items) { |
180 | | - uploadHelper.updateUploadStatus(upload.getRemotePath(), accountName, UploadStatus.UPLOAD_CANCELLED); |
181 | | - FileUploadWorker.Companion.cancelCurrentUpload(upload.getRemotePath(), accountName, () -> Unit.INSTANCE); |
| 180 | + final int totalUploads = group.items().length; |
| 181 | + final int[] completedCount = {0}; |
| 182 | + |
| 183 | + for (int i=0; i<group.items.length; i++) { |
| 184 | + OCUpload upload = group.items[i]; |
| 185 | + uploadHelper.updateUploadStatus(upload.getRemotePath(), accountName, UploadStatus.UPLOAD_CANCELLED, new Function0<Unit>() { |
| 186 | + @Override |
| 187 | + public Unit invoke() { |
| 188 | + FileUploadWorker.Companion.cancelCurrentUpload(upload.getRemotePath(), accountName, new Function0<Unit>() { |
| 189 | + @Override |
| 190 | + public Unit invoke() { |
| 191 | + completedCount[0]++; |
| 192 | + if (completedCount[0] == totalUploads) { |
| 193 | + Log_OC.d(TAG, "refreshing upload items"); |
| 194 | + |
| 195 | + // All uploads finished, refresh UI once |
| 196 | + loadUploadItemsFromDb(() -> {}); |
| 197 | + } |
| 198 | + return Unit.INSTANCE; |
| 199 | + } |
| 200 | + }); |
| 201 | + return Unit.INSTANCE; |
| 202 | + } |
| 203 | + }); |
182 | 204 | } |
183 | | - loadUploadItemsFromDb(() -> {}); |
184 | 205 | } |
185 | 206 | case FINISHED -> { |
186 | 207 | uploadsStorageManager.clearSuccessfulUploads(); |
@@ -211,7 +232,6 @@ private void showFailedPopupMenu(HeaderViewHolder headerViewHolder) { |
211 | 232 | connectivityService, |
212 | 233 | accountManager, |
213 | 234 | powerManagementService); |
214 | | - loadUploadItemsFromDb(() -> {}); |
215 | 235 | } |
216 | 236 |
|
217 | 237 | return true; |
@@ -254,7 +274,6 @@ private void retryCancelledUploads() { |
254 | 274 | connectivityService, |
255 | 275 | accountManager, |
256 | 276 | powerManagementService); |
257 | | - loadUploadItemsFromDb(() -> {}); |
258 | 277 | parentActivity.runOnUiThread(() -> { |
259 | 278 | if (showNotExistMessage) { |
260 | 279 | showNotExistMessage(); |
@@ -407,9 +426,13 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati |
407 | 426 | itemViewHolder.binding.uploadRightButton.setImageResource(R.drawable.ic_action_cancel_grey); |
408 | 427 | itemViewHolder.binding.uploadRightButton.setVisibility(View.VISIBLE); |
409 | 428 | itemViewHolder.binding.uploadRightButton.setOnClickListener(v -> { |
410 | | - uploadHelper.updateUploadStatus(item.getRemotePath(), item.getAccountName(), UploadStatus.UPLOAD_CANCELLED); |
411 | | - FileUploadWorker.Companion.cancelCurrentUpload(item.getRemotePath(), item.getAccountName(), () -> Unit.INSTANCE); |
412 | | - loadUploadItemsFromDb(() -> {}); |
| 429 | + uploadHelper.updateUploadStatus(item.getRemotePath(), item.getAccountName(), UploadStatus.UPLOAD_CANCELLED, () -> { |
| 430 | + FileUploadWorker.Companion.cancelCurrentUpload(item.getRemotePath(), item.getAccountName(), () -> { |
| 431 | + loadUploadItemsFromDb(() -> {}); |
| 432 | + return Unit.INSTANCE; |
| 433 | + }); |
| 434 | + return Unit.INSTANCE; |
| 435 | + }); |
413 | 436 | }); |
414 | 437 |
|
415 | 438 | } else if (item.getUploadStatus() == UploadStatus.UPLOAD_FAILED) { |
@@ -456,7 +479,6 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati |
456 | 479 | Optional<User> user = accountManager.getUser(item.getAccountName()); |
457 | 480 | if (file.exists() && user.isPresent()) { |
458 | 481 | uploadHelper.retryUpload(item, user.get()); |
459 | | - loadUploadItemsFromDb(() -> {}); |
460 | 482 | } else { |
461 | 483 | DisplayUtils.showSnackMessage(v.getRootView().findViewById(android.R.id.content), R.string.local_file_not_found_message); |
462 | 484 | } |
|
0 commit comments