-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup Recyclerview for Trending movie list
- Loading branch information
1 parent
2901629
commit e20f131
Showing
24 changed files
with
469 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/shashank/moviedb/di/home/HomeFragmentBuildersModule.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.shashank.moviedb.di.home; | ||
|
||
import com.shashank.moviedb.ui.home.HomeFragment; | ||
import com.shashank.moviedb.ui.home.viewholder.MovieViewHolder; | ||
|
||
import dagger.Module; | ||
import dagger.android.ContributesAndroidInjector; | ||
|
||
@Module | ||
public abstract class HomeFragmentBuildersModule { | ||
|
||
@ContributesAndroidInjector | ||
abstract HomeFragment contributeHomeFragment(); | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/shashank/moviedb/di/home/HomeModule.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.shashank.moviedb.di.home; | ||
|
||
import android.app.Application; | ||
|
||
import androidx.recyclerview.widget.GridLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.bumptech.glide.RequestManager; | ||
import com.shashank.moviedb.ui.home.adapter.MovieRecyclerAdapter; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
@Module | ||
public class HomeModule { | ||
|
||
@HomeScope | ||
@Provides | ||
public static MovieRecyclerAdapter provideMovieRecyclerAdapter(RequestManager requestManager) { | ||
return new MovieRecyclerAdapter(requestManager); | ||
} | ||
|
||
@HomeScope | ||
@Provides | ||
public static RecyclerView.LayoutManager provideGridLayoutManager(Application application) { | ||
return new GridLayoutManager(application, 2); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/shashank/moviedb/di/home/HomeScope.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.shashank.moviedb.di.home; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.inject.Scope; | ||
|
||
@Scope | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface HomeScope { | ||
} |
This file contains 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
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/shashank/moviedb/ui/home/adapter/MovieRecyclerAdapter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.shashank.moviedb.ui.home.adapter; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.lifecycle.MutableLiveData; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.bumptech.glide.RequestManager; | ||
import com.shashank.moviedb.R; | ||
import com.shashank.moviedb.model.MovieResult; | ||
import com.shashank.moviedb.ui.home.viewholder.MovieViewHolder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class MovieRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | ||
|
||
private static final int MOVIE_TYPE = 1; | ||
private static final int EXHAUSTED_TYPE = 2; | ||
private RequestManager requestManager; | ||
|
||
@Inject | ||
public MovieRecyclerAdapter(RequestManager requestManager) { | ||
this.requestManager = requestManager; | ||
} | ||
|
||
private List<MovieResult> mMovies = new ArrayList<>(); | ||
|
||
@NonNull | ||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
|
||
View view = null; | ||
|
||
switch (viewType) { | ||
|
||
case EXHAUSTED_TYPE: | ||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_search_exhausted, parent, false); | ||
return new SearchExhaustedViewHolder(view); | ||
|
||
case MOVIE_TYPE: | ||
|
||
default: | ||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.movie_view_layout, parent, false); | ||
return new MovieViewHolder(view, requestManager); | ||
} | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | ||
|
||
int viewType = getItemViewType(position); | ||
|
||
if(viewType == MOVIE_TYPE) { | ||
((MovieViewHolder)holder).onBind(mMovies.get(position)); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mMovies.size(); | ||
} | ||
|
||
@Override | ||
public int getItemViewType(int position) { | ||
if(!mMovies.isEmpty()) { | ||
return MOVIE_TYPE; | ||
} else { | ||
// movie list is empty | ||
return EXHAUSTED_TYPE; | ||
} | ||
} | ||
|
||
|
||
public void setMovies(List<MovieResult> movies) { | ||
this.mMovies = movies; | ||
notifyDataSetChanged(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/shashank/moviedb/ui/home/adapter/SearchExhaustedViewHolder.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.shashank.moviedb.ui.home.adapter; | ||
|
||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
public class SearchExhaustedViewHolder extends RecyclerView.ViewHolder { | ||
|
||
public SearchExhaustedViewHolder(@NonNull View itemView) { | ||
super(itemView); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/shashank/moviedb/ui/home/viewholder/MovieViewHolder.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.shashank.moviedb.ui.home.viewholder; | ||
|
||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.widget.AppCompatImageView; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.bumptech.glide.RequestManager; | ||
import com.shashank.moviedb.R; | ||
import com.shashank.moviedb.model.MovieResult; | ||
import com.shashank.moviedb.util.Constants; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class MovieViewHolder extends RecyclerView.ViewHolder { | ||
|
||
|
||
private RequestManager requestManager; | ||
|
||
private AppCompatImageView movieImage; | ||
private TextView movieTitle; | ||
private TextView movieVoteAverage; | ||
|
||
public MovieViewHolder(@NonNull View itemView, RequestManager requestManager) { | ||
super(itemView); | ||
this.requestManager = requestManager; | ||
movieImage = itemView.findViewById(R.id.iv_movie); | ||
movieTitle = itemView.findViewById(R.id.tv_movie_title); | ||
movieVoteAverage = itemView.findViewById(R.id.tv_vote_average); | ||
} | ||
|
||
|
||
public void onBind(MovieResult movie) { | ||
|
||
String url = getMoviePosterUrl(movie); | ||
if(url!=null) { | ||
final String finalPosterUrl = Constants.BASE_IMAGE_URL_API + url; | ||
requestManager.load(finalPosterUrl).into(movieImage); | ||
} | ||
|
||
movieTitle.setText(movie.getTitle()); | ||
|
||
String voteAverage = (movie.getVoteAverage()!=null)? movie.getVoteAverage().toString() : "_._"; | ||
movieVoteAverage.setText(voteAverage); | ||
} | ||
|
||
private String getMoviePosterUrl(MovieResult movie) { | ||
String url = null; | ||
if(movie.getBackdropPath()!=null) { | ||
url = movie.getBackdropPath(); | ||
} else if(movie.getPosterPath()!=null) { | ||
url = movie.getPosterPath(); | ||
} | ||
|
||
return url; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.