SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.FilmKatalog.Film;
  2.  
  3. import android.content.Intent;
  4. import androidx.annotation.NonNull;
  5. import androidx.recyclerview.widget.RecyclerView;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.ImageView;
  10. import android.widget.TextView;
  11. import com.example.FilmKatalog.R;
  12. import com.bumptech.glide.Glide;
  13. import java.util.ArrayList;
  14.  
  15. public class FilmAdapter extends RecyclerView.Adapter<FilmAdapter.MovieViewHolder> {
  16.  
  17.     private ArrayList<Film> mData = new ArrayList<>();
  18.     public void setData(ArrayList<Film> items) {
  19.         mData.clear();
  20.         mData.addAll(items);
  21.         notifyDataSetChanged();
  22.     }
  23.  
  24.     @NonNull
  25.     @Override
  26.     public MovieViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
  27.         View mView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_cardview_film, viewGroup, false);
  28.         return new MovieViewHolder(mView);
  29.     }
  30.  
  31.     @Override
  32.     public void onBindViewHolder(@NonNull MovieViewHolder movieViewHolder, int position) {
  33.         movieViewHolder.bind(mData.get(position));
  34.     }
  35.  
  36.     @Override
  37.     public int getItemCount() {
  38.         return mData.size();
  39.     }
  40.  
  41.     class MovieViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
  42.         ImageView imgPhoto;
  43.         TextView textViewTitle, textViewDateReleased,
  44.                 textViewVoteAverage;
  45.  
  46.         MovieViewHolder(@NonNull View itemView) {
  47.             super(itemView);
  48.             textViewTitle = itemView.findViewById(R.id.tv_item_title);
  49.             textViewDateReleased = itemView.findViewById(R.id.tv_item_dateReleased);
  50.             textViewVoteAverage = itemView.findViewById(R.id.tv_item_voteAverege);
  51.             imgPhoto = itemView.findViewById(R.id.img_item_photo);
  52.  
  53.             itemView.setOnClickListener(this);
  54.         }
  55.         void bind(Film movies) {
  56.             String vote_average = Double.toString(movies.getVote_average());
  57.             String url_image = "https://image.tmdb.org/t/p/w185" + movies.getPhoto();
  58.  
  59.             textViewTitle.setText(movies.getTitle());
  60.             textViewDateReleased.setText(movies.getRelease_date());
  61.             textViewVoteAverage.setText(vote_average);
  62.  
  63.             Glide.with(itemView.getContext())
  64.                     .load(url_image)
  65.                     .placeholder(R.color.colorAccent)
  66.                     .dontAnimate()
  67.                     .into(imgPhoto);
  68.         }
  69.  
  70.         @Override
  71.         public void onClick(View v) {
  72.             int position = getAdapterPosition();
  73.             Film movie = mData.get(position);
  74.  
  75.             movie.setTitle(movie.getTitle());
  76.             movie.setOverview(movie.getOverview());
  77.  
  78.             Intent moveWithObjectIntent = new Intent(itemView.getContext(), FilmDetail.class);
  79.             moveWithObjectIntent.putExtra(FilmDetail.EXTRA_MOVIE, movie);
  80.             itemView.getContext().startActivity(moveWithObjectIntent);
  81.         }
  82.     }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top