|
| 1 | +package cf.vandit.movie_app.adapters; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.content.Intent; |
| 5 | +import android.view.LayoutInflater; |
| 6 | +import android.view.View; |
| 7 | +import android.view.ViewGroup; |
| 8 | +import android.widget.TextView; |
| 9 | + |
| 10 | +import androidx.annotation.NonNull; |
| 11 | +import androidx.constraintlayout.widget.ConstraintLayout; |
| 12 | +import androidx.recyclerview.widget.LinearLayoutManager; |
| 13 | +import androidx.recyclerview.widget.RecyclerView; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +import cf.vandit.movie_app.R; |
| 18 | +import cf.vandit.movie_app.activities.ViewAllMoviesActivity; |
| 19 | +import cf.vandit.movie_app.network.movie.MovieBrief; |
| 20 | +import cf.vandit.movie_app.utils.Constants; |
| 21 | +import cf.vandit.movie_app.utils.NestedRecViewModel; |
| 22 | + |
| 23 | +public class MoviesNestedRecViewAdapter extends RecyclerView.Adapter<MoviesNestedRecViewAdapter.ViewHolder> { |
| 24 | + private List<NestedRecViewModel> mNestedList; |
| 25 | + private Context mContext; |
| 26 | + |
| 27 | + public MoviesNestedRecViewAdapter(List<NestedRecViewModel> mNestedList, Context mContext) { |
| 28 | + this.mNestedList = mNestedList; |
| 29 | + this.mContext = mContext; |
| 30 | + } |
| 31 | + |
| 32 | + @NonNull |
| 33 | + @Override |
| 34 | + public MoviesNestedRecViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
| 35 | + return new MoviesNestedRecViewAdapter.ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.nested_rv_item, parent, false)); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public void onBindViewHolder(@NonNull MoviesNestedRecViewAdapter.ViewHolder holder, int position) { |
| 40 | + switch (mNestedList.get(position).getmGenreId()){ |
| 41 | + case 28: |
| 42 | + holder.nested_heading.setText("Action"); |
| 43 | + holder.nested_view_all.setOnClickListener(view -> { |
| 44 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 45 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.ACTION_MOVIES_TYPE); |
| 46 | + mContext.startActivity(intent); |
| 47 | + }); |
| 48 | + break; |
| 49 | + case 12: |
| 50 | + holder.nested_heading.setText("Adventure"); |
| 51 | + holder.nested_view_all.setOnClickListener(view -> { |
| 52 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 53 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.ADVENTURE_MOVIES_TYPE); |
| 54 | + mContext.startActivity(intent); |
| 55 | + }); |
| 56 | + break; |
| 57 | + case 16: |
| 58 | + holder.nested_heading.setText("Animation"); |
| 59 | + holder.nested_view_all.setOnClickListener(view -> { |
| 60 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 61 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.ANIMATION_MOVIES_TYPE); |
| 62 | + mContext.startActivity(intent); |
| 63 | + }); |
| 64 | + break; |
| 65 | + case 35: |
| 66 | + holder.nested_heading.setText("Comedy"); |
| 67 | + holder.nested_view_all.setOnClickListener(view -> { |
| 68 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 69 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.COMEDY_MOVIES_TYPE); |
| 70 | + mContext.startActivity(intent); |
| 71 | + }); |
| 72 | + break; |
| 73 | + case 80: |
| 74 | + holder.nested_heading.setText("Crime"); |
| 75 | + holder.nested_view_all.setOnClickListener(view -> { |
| 76 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 77 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.CRIME_MOVIES_TYPE); |
| 78 | + mContext.startActivity(intent); |
| 79 | + }); |
| 80 | + break; |
| 81 | + case 99: |
| 82 | + holder.nested_heading.setText("Documentary"); |
| 83 | + holder.nested_view_all.setOnClickListener(view -> { |
| 84 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 85 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.DOCUMENTARY_MOVIES_TYPE); |
| 86 | + mContext.startActivity(intent); |
| 87 | + }); |
| 88 | + break; |
| 89 | + case 18: |
| 90 | + holder.nested_heading.setText("Drama"); |
| 91 | + holder.nested_view_all.setOnClickListener(view -> { |
| 92 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 93 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.DRAMA_MOVIES_TYPE); |
| 94 | + mContext.startActivity(intent); |
| 95 | + }); |
| 96 | + break; |
| 97 | + case 10751: |
| 98 | + holder.nested_heading.setText("Family"); |
| 99 | + holder.nested_view_all.setOnClickListener(view -> { |
| 100 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 101 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.FAMILY_MOVIES_TYPE); |
| 102 | + mContext.startActivity(intent); |
| 103 | + }); |
| 104 | + break; |
| 105 | + case 14: |
| 106 | + holder.nested_heading.setText("Fantasy"); |
| 107 | + holder.nested_view_all.setOnClickListener(view -> { |
| 108 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 109 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.FANTASY_MOVIES_TYPE); |
| 110 | + mContext.startActivity(intent); |
| 111 | + }); |
| 112 | + break; |
| 113 | + case 36: |
| 114 | + holder.nested_heading.setText("History"); |
| 115 | + holder.nested_view_all.setOnClickListener(view -> { |
| 116 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 117 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.HISTORY_MOVIES_TYPE); |
| 118 | + mContext.startActivity(intent); |
| 119 | + }); |
| 120 | + break; |
| 121 | + case 27: |
| 122 | + holder.nested_heading.setText("Horror"); |
| 123 | + holder.nested_view_all.setOnClickListener(view -> { |
| 124 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 125 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.HORROR_MOVIES_TYPE); |
| 126 | + mContext.startActivity(intent); |
| 127 | + }); |
| 128 | + break; |
| 129 | + case 10402: |
| 130 | + holder.nested_heading.setText("Music"); |
| 131 | + holder.nested_view_all.setOnClickListener(view -> { |
| 132 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 133 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.MUSIC_MOVIES_TYPE); |
| 134 | + mContext.startActivity(intent); |
| 135 | + }); |
| 136 | + break; |
| 137 | + case 9648: |
| 138 | + holder.nested_heading.setText("Mystery"); |
| 139 | + holder.nested_view_all.setOnClickListener(view -> { |
| 140 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 141 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.MYSTERY_MOVIES_TYPE); |
| 142 | + mContext.startActivity(intent); |
| 143 | + }); |
| 144 | + break; |
| 145 | + case 10749: |
| 146 | + holder.nested_heading.setText("Romance"); |
| 147 | + holder.nested_view_all.setOnClickListener(view -> { |
| 148 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 149 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.ROMANCE_MOVIES_TYPE); |
| 150 | + mContext.startActivity(intent); |
| 151 | + }); |
| 152 | + break; |
| 153 | + case 878: |
| 154 | + holder.nested_heading.setText("Science Fiction"); |
| 155 | + holder.nested_view_all.setOnClickListener(view -> { |
| 156 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 157 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.SCIFI_MOVIES_TYPE); |
| 158 | + mContext.startActivity(intent); |
| 159 | + }); |
| 160 | + break; |
| 161 | + case 10770: |
| 162 | + holder.nested_heading.setText("TV Movie"); |
| 163 | + holder.nested_view_all.setOnClickListener(view -> { |
| 164 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 165 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.TV_MOVIES_TYPE); |
| 166 | + mContext.startActivity(intent); |
| 167 | + }); |
| 168 | + break; |
| 169 | + case 53: |
| 170 | + holder.nested_heading.setText("Thriller"); |
| 171 | + holder.nested_view_all.setOnClickListener(view -> { |
| 172 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 173 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.THRILLER_MOVIES_TYPE); |
| 174 | + mContext.startActivity(intent); |
| 175 | + }); |
| 176 | + break; |
| 177 | + case 10752: |
| 178 | + holder.nested_heading.setText("War"); |
| 179 | + holder.nested_view_all.setOnClickListener(view -> { |
| 180 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 181 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.WAR_MOVIES_TYPE); |
| 182 | + mContext.startActivity(intent); |
| 183 | + }); |
| 184 | + break; |
| 185 | + case 37: |
| 186 | + holder.nested_heading.setText("Western"); |
| 187 | + holder.nested_view_all.setOnClickListener(view -> { |
| 188 | + Intent intent = new Intent(mContext, ViewAllMoviesActivity.class); |
| 189 | + intent.putExtra(Constants.VIEW_ALL_MOVIES_TYPE, Constants.WESTERN_MOVIES_TYPE); |
| 190 | + mContext.startActivity(intent); |
| 191 | + }); |
| 192 | + break; |
| 193 | + } |
| 194 | + |
| 195 | + setMovieRecView(holder.nested_recView, mNestedList.get(position).getmMovies()); |
| 196 | + } |
| 197 | + |
| 198 | + @Override |
| 199 | + public int getItemCount() { |
| 200 | + return mNestedList.size(); |
| 201 | + } |
| 202 | + |
| 203 | + public class ViewHolder extends RecyclerView.ViewHolder { |
| 204 | + public ConstraintLayout nested_heading_layout; |
| 205 | + public TextView nested_heading; |
| 206 | + public TextView nested_view_all; |
| 207 | + public RecyclerView nested_recView; |
| 208 | + |
| 209 | + public ViewHolder(@NonNull View itemView) { |
| 210 | + super(itemView); |
| 211 | + |
| 212 | + nested_heading_layout = itemView.findViewById(R.id.nested_constraint_layout); |
| 213 | + nested_heading = itemView.findViewById(R.id.nested_heading); |
| 214 | + nested_view_all = itemView.findViewById(R.id.nested_view_all); |
| 215 | + nested_recView = itemView.findViewById(R.id.nested_recView); |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + private void setMovieRecView(RecyclerView recyclerView, List<MovieBrief> mMovies){ |
| 220 | + MovieBriefSmallAdapter mMoviesAdapter = new MovieBriefSmallAdapter(mMovies, mContext); |
| 221 | + recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); |
| 222 | + recyclerView.setAdapter(mMoviesAdapter); |
| 223 | + } |
| 224 | +} |
0 commit comments