Skip to content
This repository was archived by the owner on Oct 27, 2024. It is now read-only.

Commit dfcb981

Browse files
author
Ashwini Kumar
authored
1. Added ButterKnife (#3)
2. Updated gradle
1 parent 066bc09 commit dfcb981

File tree

5 files changed

+68
-48
lines changed

5 files changed

+68
-48
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252
compile 'net.jcip:jcip-annotations:1.0'
5353
compile 'com.squareup.picasso:picasso:2.5.2'
5454
compile 'com.squareup.moshi:moshi:1.1.0'
55+
compile 'com.jakewharton:butterknife:7.0.1'
5556

5657
// Dependency Injection
5758
apt 'com.google.dagger:dagger-compiler:2.5'

app/src/main/java/com/esoxjem/movieguide/details/MovieDetailsFragment.java

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333

3434
import javax.inject.Inject;
3535

36+
import butterknife.Bind;
37+
import butterknife.ButterKnife;
38+
import butterknife.OnClick;
39+
40+
import static com.esoxjem.movieguide.R.id.trailers_label;
41+
3642
/**
3743
* A simple {@link Fragment} subclass.
3844
*/
@@ -41,18 +47,34 @@ public class MovieDetailsFragment extends Fragment implements IMovieDetailsView,
4147
@Inject
4248
IMovieDetailsPresenter movieDetailsPresenter;
4349

44-
private ImageView poster;
45-
private TextView title;
46-
private TextView releaseDate;
47-
private TextView rating;
48-
private TextView overview;
49-
private TextView label;
50-
private HorizontalScrollView horizontalScrollView;
51-
private LinearLayout trailers;
52-
private TextView reviews;
53-
private LinearLayout reviewsContainer;
54-
private FloatingActionButton favorite;
55-
private Movie movie;
50+
@Bind(R.id.movie_poster)
51+
ImageView poster;
52+
@Bind(R.id.movie_name)
53+
TextView title;
54+
@Bind(R.id.movie_year)
55+
TextView releaseDate;
56+
@Bind(R.id.movie_rating)
57+
TextView rating;
58+
@Bind(R.id.movie_description)
59+
TextView overview;
60+
@Bind(trailers_label)
61+
TextView label;
62+
@Bind(R.id.trailers_container)
63+
HorizontalScrollView horizontalScrollView;
64+
@Bind(R.id.trailers)
65+
LinearLayout trailers;
66+
@Bind(R.id.reviews_label)
67+
TextView reviews;
68+
@Bind(R.id.reviews)
69+
LinearLayout reviewsContainer;
70+
@Bind(R.id.favorite)
71+
FloatingActionButton favorite;
72+
@Bind(R.id.toolbar)
73+
Toolbar toolbar;
74+
@Bind(R.id.collapsing_toolbar)
75+
CollapsingToolbarLayout collapsingToolbarLayout;
76+
77+
Movie movie;
5678

5779
public MovieDetailsFragment()
5880
{
@@ -82,8 +104,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
82104
Bundle savedInstanceState)
83105
{
84106
View rootView = inflater.inflate(R.layout.fragment_movie_details, container, false);
85-
setToolbar(rootView);
86-
initLayoutReferences(rootView);
107+
ButterKnife.bind(this, rootView);
108+
setToolbar();
87109
return rootView;
88110
}
89111

@@ -103,33 +125,14 @@ public void onViewCreated(View view, Bundle savedInstanceState)
103125
}
104126
}
105127

106-
private void initLayoutReferences(View rootView)
107-
{
108-
poster = (ImageView) rootView.findViewById(R.id.movie_poster);
109-
title = (TextView) rootView.findViewById(R.id.movie_name);
110-
releaseDate = (TextView) rootView.findViewById(R.id.movie_year);
111-
rating = (TextView) rootView.findViewById(R.id.movie_rating);
112-
overview = (TextView) rootView.findViewById(R.id.movie_description);
113-
label = (TextView) rootView.findViewById(R.id.trailers_label);
114-
horizontalScrollView = (HorizontalScrollView) rootView.findViewById(R.id.trailers_container);
115-
trailers = (LinearLayout) rootView.findViewById(R.id.trailers);
116-
reviews = (TextView) rootView.findViewById(R.id.reviews_label);
117-
reviewsContainer = (LinearLayout) rootView.findViewById(R.id.reviews);
118-
favorite = (FloatingActionButton) rootView.findViewById(R.id.favorite);
119-
favorite.setOnClickListener(this);
120-
}
121-
122-
private void setToolbar(View rootView)
128+
private void setToolbar()
123129
{
124-
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
125-
126130
collapsingToolbarLayout.setContentScrimColor(getResources().getColor(R.color.colorPrimary));
127131
collapsingToolbarLayout.setTitle(getString(R.string.movie_details));
128132
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedToolbar);
129133
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedToolbar);
130134
collapsingToolbarLayout.setTitleEnabled(true);
131135

132-
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
133136
if (toolbar != null)
134137
{
135138
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
@@ -245,6 +248,12 @@ public void showUnFavorited()
245248
}
246249
}
247250

251+
@OnClick(R.id.favorite)
252+
public void onFavouriteClicked()
253+
{
254+
onFavoriteClick();
255+
}
256+
248257
@Override
249258
public void onClick(View view)
250259
{
@@ -258,10 +267,6 @@ public void onClick(View view)
258267
onReviewClick((TextView) view);
259268
break;
260269

261-
case R.id.favorite:
262-
onFavoriteClick();
263-
break;
264-
265270
default:
266271
break;
267272
}

app/src/main/java/com/esoxjem/movieguide/listing/MoviesListingActivity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@
1212
import com.esoxjem.movieguide.details.MovieDetailsFragment;
1313
import com.esoxjem.movieguide.Movie;
1414

15+
import butterknife.Bind;
16+
import butterknife.ButterKnife;
17+
1518
public class MoviesListingActivity extends AppCompatActivity implements MoviesListingFragment.Callback
1619
{
1720
public static final String DETAILS_FRAGMENT = "DetailsFragment";
1821
private boolean twoPaneMode;
1922

23+
@Bind(R.id.toolbar)
24+
Toolbar toolbar;
25+
2026
@Override
2127
protected void onCreate(Bundle savedInstanceState)
2228
{
2329
super.onCreate(savedInstanceState);
2430
setContentView(R.layout.activity_main);
31+
ButterKnife.bind(this);
2532
setToolbar();
2633

2734
if (findViewById(R.id.movie_details_container) != null)
@@ -42,7 +49,6 @@ protected void onCreate(Bundle savedInstanceState)
4249

4350
private void setToolbar()
4451
{
45-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
4652
setSupportActionBar(toolbar);
4753

4854
if (getSupportActionBar() != null)

app/src/main/java/com/esoxjem/movieguide/sorting/SortingDialogFragment.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import javax.inject.Inject;
1919

20+
import butterknife.Bind;
21+
import butterknife.ButterKnife;
22+
2023
/**
2124
* @author arun
2225
*/
@@ -25,7 +28,15 @@ public class SortingDialogFragment extends DialogFragment implements ISortingDia
2528
@Inject
2629
ISortingDialogPresenter sortingDialogPresenter;
2730

28-
private RadioGroup sortingOptionsGroup;
31+
@Bind(R.id.most_popular)
32+
RadioButton mostPopular;
33+
@Bind(R.id.highest_rated)
34+
RadioButton highestRated;
35+
@Bind(R.id.favorites)
36+
RadioButton favorites;
37+
@Bind(R.id.sorting_group)
38+
RadioGroup sortingOptionsGroup;
39+
2940
private static IMoviesListingPresenter moviesListingPresenter;
3041

3142
public static SortingDialogFragment newInstance(IMoviesListingPresenter moviesListingPresenter)
@@ -49,7 +60,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
4960
{
5061
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
5162
View dialogView = inflater.inflate(R.layout.sorting_options, null);
52-
initViews(dialogView);
63+
ButterKnife.bind(this, dialogView);
64+
initViews();
5365

5466
Dialog dialog = new Dialog(getActivity());
5567
dialog.setContentView(dialogView);
@@ -58,31 +70,27 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
5870
return dialog;
5971
}
6072

61-
private void initViews(View dialogView)
73+
private void initViews()
6274
{
63-
sortingOptionsGroup = (RadioGroup) dialogView.findViewById(R.id.sorting_group);
6475
sortingDialogPresenter.setLastSavedOption();
6576
sortingOptionsGroup.setOnCheckedChangeListener(this);
6677
}
6778

6879
@Override
6980
public void setPopularChecked()
7081
{
71-
RadioButton popular = (RadioButton) sortingOptionsGroup.findViewById(R.id.most_popular);
72-
popular.setChecked(true);
82+
mostPopular.setChecked(true);
7383
}
7484

7585
@Override
7686
public void setHighestRatedChecked()
7787
{
78-
RadioButton highestRated = (RadioButton) sortingOptionsGroup.findViewById(R.id.highest_rated);
7988
highestRated.setChecked(true);
8089
}
8190

8291
@Override
8392
public void setFavoritesChecked()
8493
{
85-
RadioButton favorites = (RadioButton) sortingOptionsGroup.findViewById(R.id.favorites);
8694
favorites.setChecked(true);
8795
}
8896

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.0'
8+
classpath 'com.android.tools.build:gradle:2.2.1'
99
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files

0 commit comments

Comments
 (0)