我的Android应用程序中有毕加索,因此我可以从Firebase数据库+存储中检索图像URL到我的recyclerview并显示它。现在,我已将所有Firebase存储映像制作为缩略图。所以我想在原始图像之前加载缩略图。图像名称以-502.jpg开头,缩略图以thumb_502.jpg开头。
ImageAdapter类
public class ImageAdapter extends
RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private Context mContext;
private List<Upload> mUploads;
private OnItemClickListener mListener;
public ImageAdapter(Context context, List<Upload> uploads) {
mContext = context;
mUploads = uploads;
}
@Override
public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.image_item, parent, false);
return new ImageViewHolder(v);
}
@Override
public void onBindViewHolder(final ImageViewHolder holder, int position) {
final Upload uploadCurrent = mUploads.get(position);
String imgUrl = uploadCurrent.getImageUrl();
holder.imageView.setVisibility(View.VISIBLE);
if( imgUrl != null && !"".equals(imgUrl) ){
Picasso.with(mContext)
.load(uploadCurrent.getImageUrl())
.into(holder.imageView);}
else{
Picasso.with(mContext).cancelRequest(holder.imageView);
}
}
上传课程
public class Upload {
private String mName;
private String mImageUrl;
private String mKey;
public Upload() {
//empty constructor needed
}
public Upload(String name, String imageUrl) {
/*if (name.trim().equals("")) {
name = "No Name";
}*/
mName = name;
mImageUrl = imageUrl;
}
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
public String getImageUrl() {
return mImageUrl;
}
public void setImageUrl(String imageUrl) {
mImageUrl = imageUrl;
}
@Exclude
public String getKey(){
return mKey;
}
@Exclude
public void setKey(String key){
mKey = key;
}
}
食品课
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.activity_image1, container, false);
mRecyclerView = view.findViewById(R.id.recycler_view);
//mRecyclerView.setHasFixedSize(true);
//mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(),3);
mRecyclerView.setLayoutManager(gridLayoutManager);
mProgressCircle = view.findViewById(R.id.progress_circle);
mUploads = new ArrayList<>();
//FirebaseDatabase.getInstance().setPersistenceEnabled(true);
mDatabaseRef = FirebaseDatabase.getInstance().getReference("uploads");
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Upload upload = postSnapshot.getValue(Upload.class);
mUploads.add(upload);
Collections.reverse(mUploads);
}
mAdapter = new ImageAdapter(getContext(), mUploads);
mRecyclerView.setAdapter(mAdapter);