Skip to content

Commit

Permalink
header interface in viewmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperDeSutter committed Nov 6, 2016
1 parent 7cc30f5 commit 934218b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions WatchFriends/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ android {




dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public EpisodeFragmentViewModel(Context context, FragmentEpisodeBinding fragment
this.context = context;
this.fragmentEpisodeBinding = fragmentEpisodeBinding;
this.episode = episode;
mListener = (Interfaces.onHeaderChanged) context;
if (context instanceof Interfaces.onHeaderChanged) {
mListener = (Interfaces.onHeaderChanged) context;
} else {
throw new RuntimeException(context.toString() + " must implement onHeaderChanged");
}
}

public void loadEpisode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import nmct.jaspernielsmichielhein.watchfriends.BR;
import nmct.jaspernielsmichielhein.watchfriends.databinding.FragmentSeasonBinding;
import nmct.jaspernielsmichielhein.watchfriends.helper.ApiHelper;
import nmct.jaspernielsmichielhein.watchfriends.helper.Interfaces;
import nmct.jaspernielsmichielhein.watchfriends.model.Season;
import nmct.jaspernielsmichielhein.watchfriends.view.MainActivity;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class SeasonFragmentViewModel extends BaseObservable {
private final Interfaces.onHeaderChanged mListener;
private Context context;
private FragmentSeasonBinding fragmentSeasonBinding;

Expand All @@ -42,6 +44,11 @@ public SeasonFragmentViewModel(Context context, FragmentSeasonBinding fragmentSe
this.seriesName = seriesName;
this.seriesId = seriesId;
this.seasonNumber = seasonNumber;
if (context instanceof Interfaces.onHeaderChanged) {
mListener = (Interfaces.onHeaderChanged) context;
} else {
throw new RuntimeException(context.toString() + " must implement onHeaderChanged");
}
}

public void loadSeason() {
Expand All @@ -61,12 +68,9 @@ public void call(Season returnedSeason) {
}

private void setHeader() {
MainActivity mainActivity = (MainActivity) context;
mainActivity.setTitle(seriesName);

Picasso.with(context).load(season.getImage_uri()).into(mainActivity.getHeaderImage());

final FloatingActionButton fab = mainActivity.getActionButton();
mListener.onSetTitle(seriesName);
mListener.onSetImage(season.getImage_uri());
final FloatingActionButton fab = mListener.onGetActionButton();
fab.setVisibility(View.INVISIBLE);
}
}

0 comments on commit 934218b

Please sign in to comment.