mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Merge pull request #3572 from nextcloud/smallThumbnails
Local file list: make image/videos properly sized again
This commit is contained in:
commit
8475a041fb
3 changed files with 55 additions and 17 deletions
|
@ -70,6 +70,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
|
||||
private static final int VIEWTYPE_ITEM = 0;
|
||||
private static final int VIEWTYPE_FOOTER = 1;
|
||||
private static final int VIEWTYPE_IMAGE = 2;
|
||||
|
||||
public LocalFileListAdapter(boolean localFolderPickerMode, File directory,
|
||||
LocalFileListFragmentInterface localFileListFragmentInterface, Context context) {
|
||||
|
@ -144,7 +145,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
}
|
||||
|
||||
if (file != null) {
|
||||
LocalFileListGridViewHolder gridViewHolder = (LocalFileListGridViewHolder) holder;
|
||||
LocalFileListGridImageViewHolder gridViewHolder = (LocalFileListGridImageViewHolder) holder;
|
||||
|
||||
// checkbox
|
||||
if (isCheckedFile(file)) {
|
||||
|
@ -170,7 +171,6 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
gridViewHolder.itemLayout.setOnClickListener(v -> localFileListFragmentInterface
|
||||
.onItemClicked(finalFile));
|
||||
|
||||
gridViewHolder.fileName.setText(file.getName());
|
||||
|
||||
if (holder instanceof LocalFileListItemViewHolder) {
|
||||
LocalFileListItemViewHolder itemViewHolder = (LocalFileListItemViewHolder) holder;
|
||||
|
@ -187,11 +187,16 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
file.lastModified()));
|
||||
}
|
||||
|
||||
if (gridView && (MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file) ||
|
||||
if (gridViewHolder instanceof LocalFileListGridItemViewHolder) {
|
||||
LocalFileListGridItemViewHolder itemVH = (LocalFileListGridItemViewHolder) gridViewHolder;
|
||||
itemVH.fileName.setText(file.getName());
|
||||
|
||||
if (gridView && (MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file) ||
|
||||
localFileListFragmentInterface.getColumnSize() > showFilenameColumnThreshold)) {
|
||||
gridViewHolder.fileName.setVisibility(View.GONE);
|
||||
} else {
|
||||
gridViewHolder.fileName.setVisibility(View.VISIBLE);
|
||||
itemVH.fileName.setVisibility(View.GONE);
|
||||
} else {
|
||||
itemVH.fileName.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -251,10 +256,18 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
if (position == mFiles.size()) {
|
||||
return VIEWTYPE_FOOTER;
|
||||
} else {
|
||||
return VIEWTYPE_ITEM;
|
||||
if (MimeTypeUtil.isImageOrVideo(getItem(position))) {
|
||||
return VIEWTYPE_IMAGE;
|
||||
} else {
|
||||
return VIEWTYPE_ITEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File getItem(int position) {
|
||||
return mFiles.get(position);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
@ -263,7 +276,16 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
case VIEWTYPE_ITEM:
|
||||
if (gridView) {
|
||||
View itemView = LayoutInflater.from(mContext).inflate(R.layout.grid_item, parent, false);
|
||||
return new LocalFileListGridViewHolder(itemView);
|
||||
return new LocalFileListGridItemViewHolder(itemView);
|
||||
} else {
|
||||
View itemView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
|
||||
return new LocalFileListItemViewHolder(itemView);
|
||||
}
|
||||
|
||||
case VIEWTYPE_IMAGE:
|
||||
if (gridView) {
|
||||
View itemView = LayoutInflater.from(mContext).inflate(R.layout.grid_image, parent, false);
|
||||
return new LocalFileListGridImageViewHolder(itemView);
|
||||
} else {
|
||||
View itemView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
|
||||
return new LocalFileListItemViewHolder(itemView);
|
||||
|
@ -408,7 +430,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
this.gridView = gridView;
|
||||
}
|
||||
|
||||
private static class LocalFileListItemViewHolder extends LocalFileListGridViewHolder {
|
||||
private static class LocalFileListItemViewHolder extends LocalFileListGridItemViewHolder {
|
||||
private final TextView fileSize;
|
||||
private final TextView lastModification;
|
||||
private final TextView fileSeparator;
|
||||
|
@ -424,17 +446,15 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
}
|
||||
}
|
||||
|
||||
static class LocalFileListGridViewHolder extends RecyclerView.ViewHolder {
|
||||
private final ImageView thumbnail;
|
||||
private final TextView fileName;
|
||||
private final ImageView checkbox;
|
||||
private final LinearLayout itemLayout;
|
||||
static class LocalFileListGridImageViewHolder extends RecyclerView.ViewHolder {
|
||||
protected final ImageView thumbnail;
|
||||
protected final ImageView checkbox;
|
||||
protected final LinearLayout itemLayout;
|
||||
|
||||
private LocalFileListGridViewHolder(View itemView) {
|
||||
private LocalFileListGridImageViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
thumbnail = itemView.findViewById(R.id.thumbnail);
|
||||
fileName = itemView.findViewById(R.id.Filename);
|
||||
checkbox = itemView.findViewById(R.id.custom_checkbox);
|
||||
itemLayout = itemView.findViewById(R.id.ListItemLayout);
|
||||
|
||||
|
@ -444,6 +464,16 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
}
|
||||
}
|
||||
|
||||
static class LocalFileListGridItemViewHolder extends LocalFileListGridImageViewHolder {
|
||||
private final TextView fileName;
|
||||
|
||||
private LocalFileListGridItemViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
fileName = itemView.findViewById(R.id.Filename);
|
||||
}
|
||||
}
|
||||
|
||||
private static class LocalFileListFooterViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView footerText;
|
||||
|
||||
|
|
|
@ -497,7 +497,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
if (position == mFiles.size()) {
|
||||
return VIEWTYPE_FOOTER;
|
||||
} else {
|
||||
if (MimeTypeUtil.isImage(getItem(position))) {
|
||||
if (MimeTypeUtil.isImageOrVideo(getItem(position))) {
|
||||
return VIEWTYPE_IMAGE;
|
||||
} else {
|
||||
return VIEWTYPE_ITEM;
|
||||
|
|
|
@ -201,6 +201,14 @@ public final class MimeTypeUtil {
|
|||
return isImage(mimeType) || isVideo(mimeType);
|
||||
}
|
||||
|
||||
public static boolean isImageOrVideo(File file) {
|
||||
return isImage(file) || isVideo(file);
|
||||
}
|
||||
|
||||
public static boolean isImageOrVideo(ServerFileInterface file) {
|
||||
return isImage(file) || isVideo(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' if the mime type defines image
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue