|
@@ -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;
|
|
|
|
- if (view == null) {
|
|
|
|
- LayoutInflater inflator = (LayoutInflater) mContext
|
|
|
|
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
- view = isGridView ? inflator.inflate(R.layout.grid_item, null) :
|
|
|
|
- inflator.inflate(R.layout.list_item, null);
|
|
|
|
- }
|
|
|
|
|
|
+ File file = null;
|
|
|
|
+ boolean isGridView = true;
|
|
|
|
+ LayoutInflater inflater = (LayoutInflater) mContext
|
|
|
|
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
+
|
|
if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
|
|
if (mFiles != null && mFiles.length > position && mFiles[position] != null) {
|
|
- File file = mFiles[position];
|
|
|
|
-
|
|
|
|
- TextView fileName = (TextView) view.findViewById(R.id.Filename);
|
|
|
|
- String name = file.getName();
|
|
|
|
- fileName.setText(name);
|
|
|
|
-
|
|
|
|
|
|
+ file = mFiles[position];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (file != null) {
|
|
|
|
+ // 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)) {
|
|
|
|
- thumbnail = ThumbnailsCacheManager.mDefaultVideo;
|
|
|
|
- } else {
|
|
|
|
- thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
|
|
|
- }
|
|
|
|
|
|
+ if (BitmapUtils.isVideo(file)) {
|
|
|
|
+ thumbnail = ThumbnailsCacheManager.mDefaultVideo;
|
|
|
|
+ } else {
|
|
|
|
+ thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
|
}
|
|
}
|
|
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
|
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
|
- new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
|
|
|
- mContext.getResources(),
|
|
|
|
- thumbnail,
|
|
|
|
- task
|
|
|
|
- );
|
|
|
|
|
|
+ new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
|
|
|
+ mContext.getResources(),
|
|
|
|
+ thumbnail,
|
|
|
|
+ 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");
|