Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display thumbnail when file is image on FileDetailFragment #1065

Merged
merged 1 commit into from
Oct 15, 2015
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
25 changes: 20 additions & 5 deletions src/com/owncloud/android/ui/fragment/FileDetailFragment.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import android.accounts.Account;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -41,6 +42,7 @@
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
Expand Down Expand Up @@ -343,7 +345,7 @@ public void updateFileDetails(boolean transferring, boolean refresh) {

// set file details
setFilename(file.getFileName());
setFiletype(file.getMimetype(), file.getFileName());
setFiletype(file);
setFilesize(file.getFileLength());

setTimeModified(file.getModificationTimestamp());
Expand Down Expand Up @@ -395,18 +397,31 @@ private void setFilename(String filename) {

/**
* Updates the MIME type in view
* @param mimetype MIME type to set
* @param filename Name of the file, to deduce the icon to use in case the MIME type is not precise enough
* @param file : An {@link OCFile}
*/
private void setFiletype(String mimetype, String filename) {
private void setFiletype(OCFile file) {
String mimetype = file.getMimetype();
TextView tv = (TextView) getView().findViewById(R.id.fdType);
if (tv != null) {
// mimetype MIME type to set
String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);
tv.setText(printableMimetype);
}
ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon);
if (iv != null) {
iv.setImageResource(DisplayUtils.getFileTypeIconId(mimetype, filename));
Bitmap thumbnail = null;
if (file.isImage()) {
String tagId = String.valueOf(file.getRemoteId());
thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(tagId);
}
if (thumbnail != null) {
// Display thumbnail
iv.setImageBitmap(thumbnail);
} else {
// Name of the file, to deduce the icon to use in case the MIME type is not precise enough
String filename = file.getFileName();
iv.setImageResource(DisplayUtils.getFileTypeIconId(mimetype, filename));
}
}
}

Expand Down