mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
parent
7525088db2
commit
00a2f103b6
3 changed files with 84 additions and 26 deletions
|
@ -71,8 +71,6 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
private Account mAccount;
|
||||
private ComponentsGetter mTransferServiceGetter;
|
||||
|
||||
private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM}
|
||||
|
||||
public FileListListAdapter(
|
||||
boolean justFolders,
|
||||
Context context,
|
||||
|
|
|
@ -105,20 +105,54 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
|||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
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) {
|
||||
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);
|
||||
|
||||
/** 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) {
|
||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||
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 =
|
||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
||||
mContext.getResources(),
|
||||
thumbnail,
|
||||
task
|
||||
);
|
||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(
|
||||
mContext.getResources(),
|
||||
thumbnail,
|
||||
task
|
||||
);
|
||||
fileIcon.setImageDrawable(asyncDrawable);
|
||||
task.execute(file);
|
||||
Log_OC.v(TAG, "Executing task to generate a new thumbnail");
|
||||
|
|
|
@ -117,6 +117,34 @@ public class MimetypeIconUtil {
|
|||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue