Skip to content

Commit 066b5f1

Browse files
committed
adding more categories in MovieFragment
1 parent 19cc182 commit 066b5f1

File tree

11 files changed

+1097
-7
lines changed

11 files changed

+1097
-7
lines changed

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/cf/vandit/movie_app/activities/ViewAllMoviesActivity.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
import cf.vandit.movie_app.R;
1616
import cf.vandit.movie_app.adapters.MovieBriefSmallAdapter;
17+
import cf.vandit.movie_app.network.movie.GenreMoviesResponse;
1718
import cf.vandit.movie_app.network.movie.MovieBrief;
1819
import cf.vandit.movie_app.network.movie.PopularMoviesResponse;
1920
import cf.vandit.movie_app.network.movie.TopRatedMoviesResponse;
2021
import cf.vandit.movie_app.request.ApiClient;
2122
import cf.vandit.movie_app.request.ApiInterface;
2223
import cf.vandit.movie_app.utils.Constants;
24+
import cf.vandit.movie_app.utils.NestedRecViewModel;
2325
import retrofit2.Call;
2426
import retrofit2.Callback;
2527
import retrofit2.Response;
@@ -40,6 +42,7 @@ public class ViewAllMoviesActivity extends AppCompatActivity {
4042

4143
private Call<PopularMoviesResponse> mPopularMoviesCall;
4244
private Call<TopRatedMoviesResponse> mTopRatedMoviesCall;
45+
Call<GenreMoviesResponse> mGenreMoviesResponseCall;
4346

4447
@Override
4548
protected void onCreate(Bundle savedInstanceState) {
@@ -62,6 +65,63 @@ protected void onCreate(Bundle savedInstanceState) {
6265
case Constants.TOP_RATED_MOVIES_TYPE:
6366
setTitle("Top Rated Movies");
6467
break;
68+
case Constants.ACTION_MOVIES_TYPE:
69+
setTitle("Action Movies");
70+
break;
71+
case Constants.ADVENTURE_MOVIES_TYPE:
72+
setTitle("Adventure Movies");
73+
break;
74+
case Constants.ANIMATION_MOVIES_TYPE:
75+
setTitle("Animation Movies");
76+
break;
77+
case Constants.COMEDY_MOVIES_TYPE:
78+
setTitle("Comedy Movies");
79+
break;
80+
case Constants.CRIME_MOVIES_TYPE:
81+
setTitle("Crime Movies");
82+
break;
83+
case Constants.DOCUMENTARY_MOVIES_TYPE:
84+
setTitle("Documentary Movies");
85+
break;
86+
case Constants.DRAMA_MOVIES_TYPE:
87+
setTitle("Drama Movies");
88+
break;
89+
case Constants.FAMILY_MOVIES_TYPE:
90+
setTitle("Family Movies");
91+
break;
92+
case Constants.FANTASY_MOVIES_TYPE:
93+
setTitle("Fantasy Movies");
94+
break;
95+
case Constants.HISTORY_MOVIES_TYPE:
96+
setTitle("History Movies");
97+
break;
98+
case Constants.HORROR_MOVIES_TYPE:
99+
setTitle("Horror Movies");
100+
break;
101+
case Constants.MUSIC_MOVIES_TYPE:
102+
setTitle("Music Movies");
103+
break;
104+
case Constants.MYSTERY_MOVIES_TYPE:
105+
setTitle("Mystery Movies");
106+
break;
107+
case Constants.ROMANCE_MOVIES_TYPE:
108+
setTitle("Romance Movies");
109+
break;
110+
case Constants.SCIFI_MOVIES_TYPE:
111+
setTitle("Sci-Fi Movies");
112+
break;
113+
case Constants.TV_MOVIES_TYPE:
114+
setTitle("TV Movies");
115+
break;
116+
case Constants.THRILLER_MOVIES_TYPE:
117+
setTitle("Thriller Movies");
118+
break;
119+
case Constants.WAR_MOVIES_TYPE:
120+
setTitle("War Movies");
121+
break;
122+
case Constants.WESTERN_MOVIES_TYPE:
123+
setTitle("Western Movies");
124+
break;
65125
}
66126

67127
mRecyclerView = (RecyclerView) findViewById(R.id.view_movies_recView);
@@ -163,6 +223,36 @@ public void onFailure(Call<TopRatedMoviesResponse> call, Throwable t) {
163223
}
164224
});
165225
break;
226+
227+
default:
228+
mGenreMoviesResponseCall = apiService.getMoviesByGenre(Constants.API_KEY, movieType, presentPage);
229+
mGenreMoviesResponseCall.enqueue(new Callback<GenreMoviesResponse>() {
230+
@Override
231+
public void onResponse(Call<GenreMoviesResponse> call, Response<GenreMoviesResponse> response) {
232+
if (!response.isSuccessful()){
233+
mGenreMoviesResponseCall = call.clone();
234+
mGenreMoviesResponseCall.enqueue(this);
235+
return;
236+
}
237+
238+
if (response.body() == null) return;
239+
if (response.body().getResults() == null) return;
240+
241+
for (MovieBrief movieBrief : response.body().getResults()){
242+
if(movieBrief != null && movieBrief.getPosterPath() != null){
243+
mMovies.add(movieBrief);
244+
}
245+
}
246+
mMoviesAdapter.notifyDataSetChanged();
247+
if (response.body().getPage().equals(response.body().getTotalPages()))
248+
pagesOver = true;
249+
else
250+
presentPage++;
251+
}
252+
253+
@Override
254+
public void onFailure(Call<GenreMoviesResponse> call, Throwable t) {}
255+
});
166256
}
167257
}
168258

app/src/main/java/cf/vandit/movie_app/activities/ViewAllSeriesActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void onFailure(Call<OnTheAirSeriesResponse> call, Throwable t) {}
134134
});
135135
break;
136136

137-
case Constants.POPULAR_MOVIES_TYPE:
137+
case Constants.POPULAR_TV_SHOWS_TYPE:
138138
mPopularSeriesCall = apiInterface.getPopularSeries(Constants.API_KEY, presentPage);
139139
mPopularSeriesCall.enqueue(new Callback<PopularSeriesResponse>() {
140140
@Override
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
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

Comments
 (0)