tune grid view of images

Resolves: #311
This commit is contained in:
AndyScherzinger 2016-10-06 21:37:03 +02:00
parent 7525088db2
commit 00a2f103b6
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
3 changed files with 84 additions and 26 deletions

View file

@ -71,8 +71,6 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
private Account mAccount; private Account mAccount;
private ComponentsGetter mTransferServiceGetter; private ComponentsGetter mTransferServiceGetter;
private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM}
public FileListListAdapter( public FileListListAdapter(
boolean justFolders, boolean justFolders,
Context context, Context context,

View file

@ -105,20 +105,54 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView; View view = convertView;
boolean isGridView = parent instanceof GridView; File file = null;
if (view == null) { boolean isGridView = true;
LayoutInflater inflator = (LayoutInflater) mContext LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = isGridView ? inflator.inflate(R.layout.grid_item, null) :
inflator.inflate(R.layout.list_item, null);
}
if (mFiles != null && mFiles.length > position && mFiles[position] != null) { if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
File file = mFiles[position]; file = mFiles[position];
}
TextView fileName = (TextView) view.findViewById(R.id.Filename);
String name = file.getName(); if (file != null) {
fileName.setText(name); // Find out which layout should be displayed
ViewType viewType;
if (parent instanceof GridView) {
String mimeType = MimetypeIconUtil.getBestMimeTypeByFilename(file.getName());
if (MimetypeIconUtil.isImage(mimeType) || MimetypeIconUtil.isVideo(mimeType)) {
viewType = ViewType.GRID_IMAGE;
} else {
viewType = ViewType.GRID_ITEM;
}
} else {
viewType = ViewType.LIST_ITEM;
isGridView = false;
}
// create view only if differs, otherwise reuse
if (convertView == null || convertView.getTag() != viewType) {
switch (viewType) {
case GRID_IMAGE:
view = inflater.inflate(R.layout.grid_image, parent, false);
view.setTag(ViewType.GRID_IMAGE);
break;
case GRID_ITEM:
view = inflater.inflate(R.layout.grid_item, parent, false);
view.setTag(ViewType.GRID_ITEM);
break;
case LIST_ITEM:
view = inflater.inflate(R.layout.list_item, parent, false);
view.setTag(ViewType.LIST_ITEM);
break;
}
}
if(!ViewType.GRID_IMAGE.equals(viewType)) {
TextView fileName = (TextView) view.findViewById(R.id.Filename);
String name = file.getName();
fileName.setText(name);
}
ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail); ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail);
/** Cancellation needs do be checked and done before changing the drawable in fileIcon, or /** Cancellation needs do be checked and done before changing the drawable in fileIcon, or
@ -175,19 +209,17 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
if (allowedToCreateNewThumbnail) { if (allowedToCreateNewThumbnail) {
final ThumbnailsCacheManager.ThumbnailGenerationTask task = final ThumbnailsCacheManager.ThumbnailGenerationTask task =
new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon); new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon);
if (thumbnail == null) { if (BitmapUtils.isVideo(file)) {
if (BitmapUtils.isVideo(file)) { thumbnail = ThumbnailsCacheManager.mDefaultVideo;
thumbnail = ThumbnailsCacheManager.mDefaultVideo; } else {
} else { thumbnail = ThumbnailsCacheManager.mDefaultImg;
thumbnail = ThumbnailsCacheManager.mDefaultImg;
}
} }
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable = final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
new ThumbnailsCacheManager.AsyncThumbnailDrawable( new ThumbnailsCacheManager.AsyncThumbnailDrawable(
mContext.getResources(), mContext.getResources(),
thumbnail, thumbnail,
task task
); );
fileIcon.setImageDrawable(asyncDrawable); fileIcon.setImageDrawable(asyncDrawable);
task.execute(file); task.execute(file);
Log_OC.v(TAG, "Executing task to generate a new thumbnail"); Log_OC.v(TAG, "Executing task to generate a new thumbnail");

View file

@ -117,6 +117,34 @@ public class MimetypeIconUtil {
return candidates.get(0); return candidates.get(0);
} }
/**
* @return 'True' if the mime type defines image
*/
public static boolean isImage(String mimeType) {
return (mimeType.startsWith("image/") && !mimeType.contains("djvu"));
}
/**
* @return 'True' the mime type defines video
*/
public static boolean isVideo(String mimeType) {
return (mimeType != null && mimeType.startsWith("video/"));
}
/**
* @return 'True' the mime type defines audio
*/
public boolean isAudio(String mimeType) {
return (mimeType != null && mimeType.startsWith("audio/"));
}
/**
* @return 'True' if mime type defines text
*/
public boolean isText(String mimeType) {
return (mimeType != null && mimeType.startsWith("text/"));
}
/** /**
* determines the icon based on the mime type. * determines the icon based on the mime type.
* *