Created
October 16, 2016 08:27
-
-
Save fnk0/aee7456306ff0b044ae6420762a9d093 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
public class MovieDetailsViewHolder extends Presenter.ViewHolder { | |
@BindView(R.id.movie_title) | |
TextView movieTitleTV; | |
@BindView(R.id.movie_year) | |
TextView movieYearTV; | |
@BindView(R.id.overview) | |
TextView movieOverview; | |
@BindView(R.id.runtime) | |
TextView mRuntimeTV; | |
@BindView(R.id.tagline) | |
TextView mTaglineTV; | |
@BindView(R.id.director_tv) | |
TextView mDirectorTv; | |
@BindView(R.id.overview_label) | |
TextView mOverviewLabelTV; | |
@BindView(R.id.genres) | |
LinearLayout mGenresLayout; | |
private View itemView; | |
public MovieDetailsViewHolder(View view) { | |
super(view); | |
ButterKnife.bind(this, view); | |
itemView = view; | |
} | |
public void bind(MovieDetails movie) { | |
if (movie != null && movie.getTitle() != null) { | |
mRuntimeTV.setText(String.format(Locale.getDefault(), "%d minutes", movie.getRuntime())); | |
mTaglineTV.setText(movie.getTagline()); | |
movieTitleTV.setText(movie.getTitle()); | |
movieYearTV.setText(String.format(Locale.getDefault(), "(%s)", movie.getReleaseDate().substring(0, 4))); | |
movieOverview.setText(movie.getOverview()); | |
mGenresLayout.removeAllViews(); | |
if (movie.getDirector() != null) { | |
mDirectorTv.setText(String.format(Locale.getDefault(), "Director: %s", movie.getDirector())); | |
} | |
int _16dp = (int) itemView.getResources().getDimension(R.dimen.full_padding); | |
int _8dp = (int) itemView.getResources().getDimension(R.dimen.half_padding); | |
float corner = itemView.getResources().getDimension(R.dimen.genre_corner); | |
// Adds each genre to the genre layout | |
for (Genre g : movie.getGenres()) { | |
TextView tv = new TextView(itemView.getContext()); | |
tv.setText(g.getName()); | |
GradientDrawable shape = new GradientDrawable(); | |
shape.setShape(GradientDrawable.RECTANGLE); | |
shape.setCornerRadius(corner); | |
shape.setColor(ContextCompat.getColor(itemView.getContext(), R.color.primary_dark)); | |
tv.setPadding(_8dp, _8dp, _8dp, _8dp); | |
tv.setBackground(shape); | |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(new LinearLayout.LayoutParams( | |
LinearLayout.LayoutParams.WRAP_CONTENT, | |
LinearLayout.LayoutParams.WRAP_CONTENT)); | |
params.setMargins(0, 0, _16dp, 0); | |
tv.setLayoutParams(params); | |
mGenresLayout.addView(tv); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment