|
@@ -89,7 +89,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
private Clock clock;
|
|
|
private UploadGroup[] uploadGroups;
|
|
|
private boolean showUser;
|
|
|
- private final ViewThemeUtils viewThemeUtils;
|
|
|
+ private final ViewThemeUtils viewThemeUtils;
|
|
|
|
|
|
@Override
|
|
|
public int getSectionCount() {
|
|
@@ -235,7 +235,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
// file size
|
|
|
if (item.getFileSize() != 0) {
|
|
|
itemViewHolder.binding.uploadFileSize.setText(String.format("%s, ",
|
|
|
- DisplayUtils.bytesToHumanReadable(item.getFileSize())));
|
|
|
+ DisplayUtils.bytesToHumanReadable(item.getFileSize())));
|
|
|
} else {
|
|
|
itemViewHolder.binding.uploadFileSize.setText("");
|
|
|
}
|
|
@@ -286,7 +286,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);
|
|
@@ -383,16 +383,16 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
DisplayUtils.showSnackMessage(
|
|
|
v.getRootView().findViewById(android.R.id.content),
|
|
|
R.string.local_file_not_found_message
|
|
|
- );
|
|
|
+ );
|
|
|
}
|
|
|
});
|
|
|
- } else if (item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
|
|
|
+ } else if (item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED){
|
|
|
itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadedItemClick(item));
|
|
|
}
|
|
|
|
|
|
|
|
|
// click on thumbnail to open locally
|
|
|
- if (item.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED) {
|
|
|
+ if (item.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED){
|
|
|
itemViewHolder.binding.thumbnail.setOnClickListener(v -> onUploadingItemClick(item));
|
|
|
}
|
|
|
|
|
@@ -405,17 +405,17 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
fakeFileToCheatThumbnailsCacheManagerInterface.setMimeType(item.getMimeType());
|
|
|
|
|
|
boolean allowedToCreateNewThumbnail = ThumbnailsCacheManager.cancelPotentialThumbnailWork(
|
|
|
- fakeFileToCheatThumbnailsCacheManagerInterface, itemViewHolder.binding.thumbnail
|
|
|
- );
|
|
|
+ fakeFileToCheatThumbnailsCacheManagerInterface, itemViewHolder.binding.thumbnail
|
|
|
+ );
|
|
|
|
|
|
// TODO this code is duplicated; refactor to a common place
|
|
|
if (MimeTypeUtil.isImage(fakeFileToCheatThumbnailsCacheManagerInterface)
|
|
|
- && fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
|
|
|
- item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
|
|
|
+ && fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
|
|
|
+ item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
|
|
|
// Thumbnail in Cache?
|
|
|
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
|
|
- String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId())
|
|
|
- );
|
|
|
+ String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId())
|
|
|
+ );
|
|
|
if (thumbnail != null && !fakeFileToCheatThumbnailsCacheManagerInterface.isUpdateThumbnailNeeded()) {
|
|
|
itemViewHolder.binding.thumbnail.setImageBitmap(thumbnail);
|
|
|
} else {
|
|
@@ -423,11 +423,11 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
Optional<User> user = parentActivity.getUser();
|
|
|
if (allowedToCreateNewThumbnail && user.isPresent()) {
|
|
|
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
|
|
- new ThumbnailsCacheManager.ThumbnailGenerationTask(
|
|
|
- itemViewHolder.binding.thumbnail,
|
|
|
- parentActivity.getStorageManager(),
|
|
|
- user.get()
|
|
|
- );
|
|
|
+ new ThumbnailsCacheManager.ThumbnailGenerationTask(
|
|
|
+ itemViewHolder.binding.thumbnail,
|
|
|
+ parentActivity.getStorageManager(),
|
|
|
+ user.get()
|
|
|
+ );
|
|
|
if (thumbnail == null) {
|
|
|
if (MimeTypeUtil.isVideo(fakeFileToCheatThumbnailsCacheManagerInterface)) {
|
|
|
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
|
|
@@ -436,20 +436,20 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
}
|
|
|
}
|
|
|
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
|
|
- new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
|
|
- parentActivity.getResources(),
|
|
|
- thumbnail,
|
|
|
- task
|
|
|
- );
|
|
|
+ new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
|
|
+ parentActivity.getResources(),
|
|
|
+ thumbnail,
|
|
|
+ task
|
|
|
+ );
|
|
|
itemViewHolder.binding.thumbnail.setImageDrawable(asyncDrawable);
|
|
|
task.execute(new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(
|
|
|
- fakeFileToCheatThumbnailsCacheManagerInterface, null));
|
|
|
+ fakeFileToCheatThumbnailsCacheManagerInterface, null));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if ("image/png".equals(item.getMimeType())) {
|
|
|
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources()
|
|
|
- .getColor(R.color.bg_default));
|
|
|
+ .getColor(R.color.bg_default));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -457,14 +457,14 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
File file = new File(item.getLocalPath());
|
|
|
// Thumbnail in Cache?
|
|
|
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
|
|
- String.valueOf(file.hashCode()));
|
|
|
+ String.valueOf(file.hashCode()));
|
|
|
if (thumbnail != null) {
|
|
|
itemViewHolder.binding.thumbnail.setImageBitmap(thumbnail);
|
|
|
} else {
|
|
|
// generate new Thumbnail
|
|
|
if (allowedToCreateNewThumbnail) {
|
|
|
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
|
|
- new ThumbnailsCacheManager.ThumbnailGenerationTask(itemViewHolder.binding.thumbnail);
|
|
|
+ new ThumbnailsCacheManager.ThumbnailGenerationTask(itemViewHolder.binding.thumbnail);
|
|
|
|
|
|
if (MimeTypeUtil.isVideo(file)) {
|
|
|
thumbnail = ThumbnailsCacheManager.mDefaultVideo;
|
|
@@ -484,7 +484,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
|
|
|
if ("image/png".equalsIgnoreCase(item.getMimeType())) {
|
|
|
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources()
|
|
|
- .getColor(R.color.bg_default));
|
|
|
+ .getColor(R.color.bg_default));
|
|
|
}
|
|
|
} else {
|
|
|
if (optionalUser.isPresent()) {
|
|
@@ -503,14 +503,21 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
OCUpload item,
|
|
|
String status) {
|
|
|
String remotePath = item.getRemotePath();
|
|
|
- OCFile ocFile = storageManager.getFileByEncryptedRemotePath(remotePath);
|
|
|
+ OCFile ocFile = storageManager.getFileByPath(remotePath);
|
|
|
|
|
|
if (ocFile == null) {
|
|
|
// Remote file doesn't exist, try to refresh folder
|
|
|
- OCFile folder = storageManager.getFileByEncryptedRemotePath(new File(remotePath).getParent() + "/");
|
|
|
-
|
|
|
+ OCFile folder = storageManager.getFileByPath(new File(remotePath).getParent() + "/");
|
|
|
if (folder != null && folder.isFolder()) {
|
|
|
- refreshFolderAndUpdateUI(itemViewHolder, user, folder, remotePath, item, status);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -526,29 +533,6 @@ 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 file = storageManager.getFileByEncryptedRemotePath(remotePath);
|
|
|
-
|
|
|
- if (file != null) {
|
|
|
- openConflictActivity(file, 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,
|
|
@@ -576,13 +560,13 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
}
|
|
|
|
|
|
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,
|
|
@@ -614,7 +598,8 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Gets the status text to show to the user according to the status and last result of the the given upload.
|
|
|
+ * Gets the status text to show to the user according to the status and last result of the
|
|
|
+ * the given upload.
|
|
|
*
|
|
|
* @param upload Upload to describe.
|
|
|
* @return Text describing the status of the given upload.
|
|
@@ -695,8 +680,8 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
case SSL_RECOVERABLE_PEER_UNVERIFIED:
|
|
|
status =
|
|
|
parentActivity.getString(
|
|
|
- R.string.uploads_view_upload_status_failed_ssl_certificate_not_trusted
|
|
|
- );
|
|
|
+ R.string.uploads_view_upload_status_failed_ssl_certificate_not_trusted
|
|
|
+ );
|
|
|
break;
|
|
|
case UNKNOWN:
|
|
|
status = parentActivity.getString(R.string.uploads_view_upload_status_unknown_fail);
|
|
@@ -706,7 +691,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
break;
|
|
|
case DELAYED_IN_POWER_SAVE_MODE:
|
|
|
status = parentActivity.getString(
|
|
|
- R.string.uploads_view_upload_status_waiting_exit_power_save_mode);
|
|
|
+ R.string.uploads_view_upload_status_waiting_exit_power_save_mode);
|
|
|
break;
|
|
|
case VIRUS_DETECTED:
|
|
|
status = parentActivity.getString(R.string.uploads_view_upload_status_virus_detected);
|
|
@@ -778,17 +763,17 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
|
|
*/
|
|
|
private void onUploadedItemClick(OCUpload upload) {
|
|
|
final OCFile file = parentActivity.getStorageManager().getFileByEncryptedRemotePath(upload.getRemotePath());
|
|
|
- if (file == null) {
|
|
|
+ if (file == null){
|
|
|
DisplayUtils.showSnackMessage(parentActivity, R.string.error_retrieving_file);
|
|
|
Log_OC.i(TAG, "Could not find uploaded file on remote.");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (PreviewImageFragment.canBePreviewed(file)) {
|
|
|
+ if (PreviewImageFragment.canBePreviewed(file)){
|
|
|
//show image preview and stay in uploads tab
|
|
|
Intent intent = FileDisplayActivity.openFileIntent(parentActivity, parentActivity.getUser().get(), file);
|
|
|
parentActivity.startActivity(intent);
|
|
|
- } else {
|
|
|
+ }else{
|
|
|
Intent intent = new Intent(parentActivity, FileDisplayActivity.class);
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
intent.putExtra(FileDisplayActivity.KEY_FILE_PATH, upload.getRemotePath());
|