Skip to content

Commit

Permalink
open app internal preview on uploaded item click
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasMayerDev authored and tobiasKaminsky committed Nov 13, 2023
1 parent 2d02398 commit 50a7bdc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ public void onServiceDisconnected(ComponentName component) {
}
}

/**
* Switches to FileDisplayActivity and shows file (eg. image preview).
*/
public void openFile(String remotePath) {
Intent intent = new Intent(this, FileDisplayActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(FileDisplayActivity.KEY_FILE_PATH, remotePath);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}

/**
* Once the file upload has changed its status -> update uploads list view
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.ui.activity.ConflictsResolveActivity;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.UploadListActivity;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.theme.ViewThemeUtils;
Expand Down Expand Up @@ -346,12 +347,15 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
itemViewHolder.binding.uploadRightButton.setOnClickListener(v -> removeUpload(item));
}
itemViewHolder.binding.uploadRightButton.setVisibility(View.VISIBLE);
} else { // UploadStatus.UPLOAD_SUCCESS
} else { // UploadStatus.UPLOAD_SUCCEEDED
itemViewHolder.binding.uploadRightButton.setVisibility(View.INVISIBLE);
}

itemViewHolder.binding.uploadListItemLayout.setOnClickListener(null);

// Set icon or thumbnail
itemViewHolder.binding.thumbnail.setImageResource(R.drawable.file);

// click on item
if (item.getUploadStatus() == UploadStatus.UPLOAD_FAILED) {
final UploadResult uploadResult = item.getLastResult();
Expand Down Expand Up @@ -381,12 +385,15 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati
);
}
});
} else {
itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadItemClick(item));
} else if (item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED){
itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadedItemClick(item));
}

// Set icon or thumbnail
itemViewHolder.binding.thumbnail.setImageResource(R.drawable.file);

// click on thumbnail to open locally
if (item.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED){
itemViewHolder.binding.thumbnail.setOnClickListener(v -> onUploadingItemClick(item));
}

/*
* Cancellation needs do be checked and done before changing the drawable in fileIcon, or
Expand Down Expand Up @@ -738,7 +745,10 @@ public final void loadUploadItemsFromDb() {
notifyDataSetChanged();
}

private void onUploadItemClick(OCUpload file) {
/**
* Open local file.
*/
private void onUploadingItemClick(OCUpload file) {
File f = new File(file.getLocalPath());
if (!f.exists()) {
DisplayUtils.showSnackMessage(parentActivity, R.string.local_file_not_found_message);
Expand All @@ -747,6 +757,15 @@ private void onUploadItemClick(OCUpload file) {
}
}

/**
* Open remote file.
*/
private void onUploadedItemClick(OCUpload file) {
if (parentActivity instanceof UploadListActivity uploadListActivity) {
uploadListActivity.openFile(file.getRemotePath());
}
}


/**
* Open file with app associates with its MIME type. If MIME type unknown, show list with all apps.
Expand Down

0 comments on commit 50a7bdc

Please sign in to comment.