Created
July 4, 2019 09:32
-
-
Save cod3smith/e684cb7acd57afbe2c0b9581f3e5fbdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kelynnjeri.memories; | |
| import android.content.Context; | |
| import android.view.LayoutInflater; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.ImageView; | |
| import androidx.annotation.NonNull; | |
| import androidx.recyclerview.widget.RecyclerView; | |
| import com.bumptech.glide.Glide; | |
| import java.util.List; | |
| /** | |
| * Created by Kelyn Njeri on 7/1/19. | |
| **/ | |
| public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> { | |
| private Context mContext; | |
| private List<Uploads> mUploadsList; | |
| public ImageAdapter(Context context, List<Uploads> uploadsList) { | |
| mContext = context; | |
| mUploadsList = uploadsList; | |
| } | |
| @NonNull | |
| @Override | |
| public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |
| View v = LayoutInflater.from(mContext).inflate(R.layout.image_item, parent, false); | |
| return new ImageViewHolder(v); | |
| } | |
| @Override | |
| public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) { | |
| Uploads currentImage = mUploadsList.get(position); | |
| Glide.with(mContext) | |
| .load(currentImage.getImageUrl()) | |
| .fitCenter() | |
| .centerCrop() | |
| .into(holder.mImageView); | |
| } | |
| @Override | |
| public int getItemCount() { | |
| return mUploadsList.size(); | |
| } | |
| public class ImageViewHolder extends RecyclerView.ViewHolder { | |
| public ImageView mImageView; | |
| public ImageViewHolder(@NonNull View itemView) { | |
| super(itemView); | |
| mImageView = itemView.findViewById(R.id.uploaded_image); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment