|
@@ -83,17 +83,17 @@ 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 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;
|
|
|
private NotificationManager mNotificationManager;
|
|
|
- private Clock clock;
|
|
|
- private UploadGroup[] uploadGroups;
|
|
|
- private boolean showUser;
|
|
|
- private final ViewThemeUtils viewThemeUtils;
|
|
|
|
|
|
@Override
|
|
|
public int getSectionCount() {
|
|
@@ -119,42 +119,31 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
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();
|
|
@@ -217,6 +206,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
loadUploadItemsFromDb();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public void onBindViewHolder(SectionedViewHolder holder, int section, int relativePosition, int absolutePosition) {
|
|
|
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
|
|
@@ -276,11 +266,10 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
// 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)) {
|
|
@@ -290,7 +279,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
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);
|
|
@@ -308,19 +297,12 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
} 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);
|
|
|
|
|
@@ -507,29 +489,22 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
OCUpload item,
|
|
|
String status) {
|
|
|
String remotePath = item.getRemotePath();
|
|
|
- OCFile ocFile = storageManager.getFileByPath(remotePath);
|
|
|
+ OCFile localFile = storageManager.getFileByEncryptedRemotePath(remotePath);
|
|
|
|
|
|
- if (ocFile == null) {
|
|
|
+ if (localFile == null) {
|
|
|
// Remote file doesn't exist, try to refresh folder
|
|
|
- OCFile folder = storageManager.getFileByPath(new File(remotePath).getParent() + "/");
|
|
|
+ OCFile folder = storageManager.getFileByEncryptedRemotePath(new File(remotePath).getParent() + "/");
|
|
|
+
|
|
|
if (folder != null && folder.isFolder()) {
|
|
|
- this.refreshFolder(itemViewHolder, user, folder, (caller, result) -> {
|
|
|
- itemViewHolder.binding.uploadStatus.setText(status);
|
|
|
- if (result.isSuccess()) {
|
|
|
- OCFile file = storageManager.getFileByPath(remotePath);
|
|
|
- if (file != null) {
|
|
|
- this.openConflictActivity(file, item);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ refreshFolderAndUpdateUI(itemViewHolder, user, folder, remotePath, item, status);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
// Destination folder doesn't exist anymore
|
|
|
}
|
|
|
|
|
|
- if (ocFile != null) {
|
|
|
- this.openConflictActivity(ocFile, item);
|
|
|
+ if (localFile != null) {
|
|
|
+ this.openConflictActivity(localFile, item);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -537,6 +512,29 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private void refreshFolderAndUpdateUI(ItemViewHolder holder, User user, OCFile folder, String remotePath, OCUpload item, String status) {
|
|
|
+ Context context = MainApp.getAppContext();
|
|
|
+
|
|
|
+ this.refreshFolder(context, holder, user, folder, (caller, result) -> {
|
|
|
+ holder.binding.uploadStatus.setText(status);
|
|
|
+
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ OCFile fileOnServer = storageManager.getFileByEncryptedRemotePath(remotePath);
|
|
|
+
|
|
|
+ if (fileOnServer != null) {
|
|
|
+ openConflictActivity(fileOnServer, item);
|
|
|
+ } else {
|
|
|
+ displayFileNotFoundError(holder.itemView, context);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void displayFileNotFoundError(View itemView, Context context) {
|
|
|
+ String message = context.getString(R.string.uploader_file_not_found_message);
|
|
|
+ DisplayUtils.showSnackMessage(itemView, message);
|
|
|
+ }
|
|
|
+
|
|
|
private void showItemConflictPopup(User user,
|
|
|
ItemViewHolder itemViewHolder,
|
|
|
OCUpload item,
|
|
@@ -558,20 +556,20 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
popup.show();
|
|
|
}
|
|
|
|
|
|
- private void removeUpload(OCUpload item) {
|
|
|
+ public void removeUpload(OCUpload item) {
|
|
|
uploadsStorageManager.removeUpload(item);
|
|
|
cancelOldErrorNotification(item);
|
|
|
loadUploadItemsFromDb();
|
|
|
}
|
|
|
|
|
|
private void refreshFolder(
|
|
|
+ Context context,
|
|
|
ItemViewHolder view,
|
|
|
User user,
|
|
|
OCFile folder,
|
|
|
OnRemoteOperationListener listener) {
|
|
|
view.binding.uploadListItemLayout.setClickable(false);
|
|
|
view.binding.uploadStatus.setText(R.string.uploads_view_upload_status_fetching_server_version);
|
|
|
- Context context = MainApp.getAppContext();
|
|
|
new RefreshFolderOperation(folder,
|
|
|
clock.getCurrentTime(),
|
|
|
false,
|