Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
import java.util.Optional;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;

/**
* This Adapter populates a ListView with following types of uploads: pending, active, completed. Filtering possible.
Expand Down Expand Up @@ -170,37 +170,35 @@ public void onBindHeaderViewHolder(SectionedViewHolder holder, int section, bool

}

ViewExtensionsKt.setVisibleIf(headerViewHolder.binding.autoUploadBatterySaverWarningCard.root, powerManagementService.isPowerSavingEnabled());
ViewExtensionsKt.setVisibleIf(headerViewHolder.binding.autoUploadBatterySaverWarningCard.root,
powerManagementService.isPowerSavingEnabled());
viewThemeUtils.material.themeCardView(headerViewHolder.binding.autoUploadBatterySaverWarningCard.root);

headerViewHolder.binding.uploadListAction.setOnClickListener(v -> {
switch (group.type) {
case CURRENT -> {
String accountName = group.items()[0].getAccountName();
OCUpload[] items = group.items();
if (items.length == 0) return;

String accountName = items[0].getAccountName();

final int totalUploads = group.items().length;
final int[] completedCount = {0};

for (int i=0; i<group.items.length; i++) {
OCUpload upload = group.items[i];
uploadHelper.updateUploadStatus(upload.getRemotePath(), accountName, UploadStatus.UPLOAD_CANCELLED, new Function0<Unit>() {
@Override
public Unit invoke() {
FileUploadWorker.Companion.cancelUpload(upload.getRemotePath(), accountName, new Function0<Unit>() {
@Override
public Unit invoke() {
completedCount[0]++;
if (completedCount[0] == totalUploads) {
Log_OC.d(TAG, "refreshing upload items");

// All uploads finished, refresh UI once
loadUploadItemsFromDb(() -> {});
}
return Unit.INSTANCE;
}
});
uploadHelper.updateUploadStatus(upload.getRemotePath(), accountName, UploadStatus.UPLOAD_CANCELLED, () -> {
FileUploadWorker.Companion.cancelUpload(upload.getRemotePath(), accountName, () -> {
completedCount[0]++;
if (completedCount[0] == totalUploads) {
Log_OC.d(TAG, "refreshing upload items");

// All uploads finished, refresh UI once
loadUploadItemsFromDb(() -> {});
}
return Unit.INSTANCE;
}
});
return Unit.INSTANCE;
});
}
}
Expand Down Expand Up @@ -338,7 +336,8 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
}

// upload date
boolean showUploadDate = updateTime > 0 && item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED && item.getLastResult() == UploadResult.UPLOADED;
boolean showUploadDate = (updateTime > 0 && item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED &&
item.getLastResult() == UploadResult.UPLOADED);
itemViewHolder.binding.uploadDate.setVisibility(showUploadDate ? View.VISIBLE : View.GONE);
if (showUploadDate) {
CharSequence dateString = DisplayUtils.getRelativeDateTimeString(parentActivity,
Expand Down Expand Up @@ -381,8 +380,12 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
// really uploading, so...
// ... unbind the old progress bar, if any; ...
if (uploadProgressListener != null) {
String targetKey = FileUploadHelper.Companion.buildRemoteName(uploadProgressListener.getUpload().getAccountName(), uploadProgressListener.getUpload().getRemotePath());
uploadHelper.removeUploadTransferProgressListener(uploadProgressListener, targetKey);
final var upload = uploadProgressListener.getUpload();
if (upload != null) {
String targetKey = FileUploadHelper.Companion.buildRemoteName(upload.getAccountName(),
upload.getRemotePath());
uploadHelper.removeUploadTransferProgressListener(uploadProgressListener, targetKey);
}
}
// ... then, bind the current progress bar to listen for updates
uploadProgressListener = new UploadProgressListener(item, itemViewHolder.binding.uploadProgressBar);
Expand All @@ -393,11 +396,13 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
// not really uploading; stop listening progress if view is reused!
if (uploadProgressListener != null &&
uploadProgressListener.isWrapping(itemViewHolder.binding.uploadProgressBar)) {

String targetKey = FileUploadHelper.Companion.buildRemoteName(uploadProgressListener.getUpload().getAccountName(), uploadProgressListener.getUpload().getRemotePath());

uploadHelper.removeUploadTransferProgressListener(uploadProgressListener, targetKey);
uploadProgressListener = null;
final var upload = uploadProgressListener.getUpload();
if (upload != null) {
String targetKey = FileUploadHelper.Companion.buildRemoteName(upload.getAccountName(),
upload.getRemotePath());
uploadHelper.removeUploadTransferProgressListener(uploadProgressListener, targetKey);
uploadProgressListener = null;
}
}
}

Expand Down Expand Up @@ -439,9 +444,7 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
} else if (item.getUploadStatus() == UploadStatus.UPLOAD_FAILED) {
if (item.getLastResult() == UploadResult.SYNC_CONFLICT) {
itemViewHolder.binding.uploadRightButton.setImageResource(R.drawable.ic_dots_vertical);
itemViewHolder.binding.uploadRightButton.setOnClickListener(view -> {
optionalUser.ifPresent(user -> showItemConflictPopup(user, itemViewHolder, item, status, view));
});
itemViewHolder.binding.uploadRightButton.setOnClickListener(view -> optionalUser.ifPresent(user -> showItemConflictPopup(user, itemViewHolder, item, status, view)));
} else {
// Delete
itemViewHolder.binding.uploadRightButton.setImageResource(R.drawable.ic_action_delete_grey);
Expand Down Expand Up @@ -511,7 +514,9 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
&& fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
// Thumbnail in Cache?
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId()));

final var cacheKey = String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId());
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(cacheKey);

if (thumbnail != null && !fakeFileToCheatThumbnailsCacheManagerInterface.isUpdateThumbnailNeeded()) {
itemViewHolder.binding.thumbnail.setImageBitmap(thumbnail);
Expand Down Expand Up @@ -545,7 +550,8 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
}

if ("image/png".equals(item.getMimeType())) {
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources().getColor(R.color.bg_default));
final var backgroundColor = ContextCompat.getColor(parentActivity, R.color.bg_default);
itemViewHolder.binding.thumbnail.setBackgroundColor(backgroundColor);
}
} else if (MimeTypeUtil.isImage(fakeFileToCheatThumbnailsCacheManagerInterface)) {
File file = new File(item.getLocalPath());
Expand All @@ -566,9 +572,7 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
}

final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable(parentActivity.getResources(), thumbnail,
task);

new ThumbnailsCacheManager.AsyncThumbnailDrawable(parentActivity.getResources(), thumbnail, task);
task.execute(new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, null));
task.setListener(new ThumbnailsCacheManager.ThumbnailGenerationTask.Listener() {
@Override
Expand All @@ -586,7 +590,8 @@ public void onError() {
}

if ("image/png".equalsIgnoreCase(item.getMimeType())) {
itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources().getColor(R.color.bg_default));
final var backgroundColor = ContextCompat.getColor(parentActivity, R.color.bg_default);
itemViewHolder.binding.thumbnail.setBackgroundColor(backgroundColor);
}
} else {
if (optionalUser.isPresent()) {
Expand Down Expand Up @@ -633,7 +638,8 @@ private boolean checkAndOpenConflictResolutionDialog(User user,
return false;
}

private void refreshFolderAndUpdateUI(ItemViewHolder holder, User user, OCFile folder, String remotePath, OCUpload item, String status) {
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) -> {
Expand Down Expand Up @@ -885,9 +891,11 @@ private void onUploadedItemClick(OCUpload upload) {
return;
}

if (PreviewImageFragment.canBePreviewed(file)) {
final var optionalUser = parentActivity.getUser();

if (PreviewImageFragment.canBePreviewed(file) && optionalUser.isPresent()) {
//show image preview and stay in uploads tab
Intent intent = FileDisplayActivity.openFileIntent(parentActivity, parentActivity.getUser().get(), file);
Intent intent = FileDisplayActivity.openFileIntent(parentActivity, optionalUser.get(), file);
parentActivity.startActivity(intent);
} else {
Intent intent = new Intent(parentActivity, FileDisplayActivity.class);
Expand Down
Loading