app/src/main/java/com/rashwan/reactive_popular_movies/data/model/Movie.java
 @AutoValue public abstract class Movie implements Parcelable{
    public static final String QUALITY_LOW = "w342";
    public static final String QUALITY_MEDIUM = "w500";
    public static final String QUALITY_HIGH = "w780";

    public abstract long id();
    @Nullable @Json(name = "imdb_id") public abstract String ImdbId();
    public abstract String title();
    @Nullable public abstract String overview();
    public abstract long runtime();
    @Json(name = "vote_average") public abstract float tmdbRating();
    @Json(name = "release_date") public abstract String releaseDate();
    @Nullable @Json(name = "backdrop_path") public abstract String backdropPath();
    @Nullable @Json(name = "poster_path") public abstract String posterPath();


    public static Movie create(long id, String ImdbId,String title, String overview, Long runtime,
           float tmdbRating,String releaseDate, String backdropPath, String posterPath) {
        return new AutoValue_Movie(id,ImdbId,title,overview,runtime,tmdbRating,releaseDate,backdropPath,posterPath);
    }



    public static JsonAdapter<Movie> jsonAdapter(Moshi moshi){
        return new AutoValue_Movie.MoshiJsonAdapter(moshi);
    }


    public String getFormattedRuntime(Long runtime){
        int hours = (int) (runtime / 60);
        int minutes = (int) (runtime % 60);
        return hours > 1 ? String.format(Locale.getDefault(), "%d hrs %02d mins", hours, minutes)
                : String.format(Locale.getDefault(), "%d hr %02d mins", hours, minutes);
    }

}
app/src/main/java/com/rashwan/reactive_popular_movies/data/model/MovieDetails.java
@AutoValue
public abstract class MovieDetails {
    public abstract String imdbID ();
    public abstract String imdbRating();
    @Json(name = "Ratings") public abstract List<Rating> ratings();
    @Json(name = "Rated") public abstract String rated();
    @Json(name = "Genre") public abstract String genre();
    @Json(name = "Metascore") public abstract String metascore();
    @Json(name = "BoxOffice") public abstract String boxOffice();
    @Json(name = "Awards") public abstract String awards();
    @Json(name = "Production") public abstract String production();
    @Json(name = "Website") public abstract String website();


    public static JsonAdapter<MovieDetails> jsonAdapter(Moshi moshi){
        return new AutoValue_MovieDetails.MoshiJsonAdapter(moshi);
    }

    public String getFormattedBoxOffice(){
        return this.boxOffice().substring(0,this.boxOffice().length()-3);
    }
}
app/src/main/java/com/rashwan/reactive_popular_movies/feature/favoriteMovies/FavoriteMoviesActivity.java
public class FavoriteMoviesActivity extends BaseActivity {

    @BindView(R.id.browse_toolbar) Toolbar toolbar;
    @BindView(R.id.navigation_view) NavigationView navigationView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_favorite_movies);
        navigationView.setCheckedItem(R.id.nav_favorites);
        toolbar.setTitle(R.string.nav_favorites_title);
        super.onCreateBaseActivity(savedInstanceState);
    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }
}
app/src/main/java/com/rashwan/reactive_popular_movies/data/model/Rating.java
@AutoValue
public abstract class Rating {
    public static final String ROTTEN_TOMATOES_KEY = "Rotten Tomatoes";
    @Json(name = "Source") public abstract String source();
    @Json(name = "Value") public abstract String value();

    public static JsonAdapter<Rating> jsonAdapter(Moshi moshi){
        return new AutoValue_Rating.MoshiJsonAdapter(moshi);
    }
}
app/src/main/java/com/rashwan/reactive_popular_movies/data/model/Trailer.java
@AutoValue public abstract class Trailer {
    @Inject public transient Application context;
    @Json(name = "key") public abstract String youtubeUrl();
    public abstract String name();
    public abstract String type();

    public Trailer() {
        PopularMoviesApplication.getApplicationComponent().inject(this);
    }

    public static JsonAdapter<Trailer> jsonAdapter(Moshi moshi){
        return new AutoValue_Trailer.MoshiJsonAdapter(moshi);
    }

    public String getTrailerThumbnail(){
        String baseUrl = context.getString(R.string.trailer_youtube_thumbnail);
        return String.format(baseUrl,youtubeUrl());
    }
    public Uri getFullYoutubeUri(){
        String baseUrl = context.getString(R.string.trailer_youtube_video);
        return Uri.parse(baseUrl).buildUpon()
                .appendQueryParameter("v",this.youtubeUrl()).build();
    }

}
app/src/main/java/com/rashwan/reactive_popular_movies/feature/movieDetails/MovieDetailsActivity.java
public class MovieDetailsActivity extends AppCompatActivity implements DelegateToActivity
        ,MovieDetailsView,ShowDetailsInActivity,AppBarLayout.OnOffsetChangedListener{

    private static final String EXTRA_MOVIE = "com.rashwan.reactive_popular_movies.feature.movieDetails.EXTRA_MOVIE";
    private static final String EXTRA_SHARED_ELEMENT_NAME = "com.rashwan.reactive_popular_movies.feature.movieDetails.EXTRA_SHARED_ELEMENT_NAME";
    @BindView(R.id.details_coordinator_layout) CoordinatorLayout coordinatorLayout;
    @BindView(R.id.details_sliding_tabs) TabLayout detailsTabLayout;
    @BindView(R.id.details_view_pager) ViewPager detailsViewPager;
    @BindView(R.id.image_backdrop) ImageView blurPoster;
    @BindView(R.id.image_poster) ImageView posterImage;
    @BindView(R.id.text_release) TextView release;
    @BindView(R.id.text_movie_title) TextView textMovieTitle;
    @BindView(R.id.toolbar_movie_title) TextView toolbarMovieTitle;
    @BindView(R.id.collapsing_toolbar_layout) CollapsingToolbarLayout collapsingToolbar;
    @BindView(R.id.toggle_watchlist) ToggleButton toggleWatchlist;
    @BindView(R.id.button_play_main_trailer) ImageButton buttonPlayTrailer;
    @BindView(R.id.appbar) AppBarLayout appBarLayout;
    @BindView(R.id.text_runtime) TextView textRuntime;
    @BindView(R.id.text_movie_genres) TextView textGenres;
    @BindView(R.id.image_mpaa_rating) ImageView imageMpaaRating;
    @BindView(R.id.appbar_constraint_layout) ConstraintLayout appbarConstraintLayout;
    @BindView(R.id.fab_favorite) FloatingActionButton fab;
    @Nullable @BindView(R.id.toolbar_details) Toolbar toolbar;
    @BindColor(android.R.color.black) int blackColor;
    private String sharedElementName;
    private Movie movie;
    @Inject MovieDetailsPresenter presenter;
    private boolean isFavorite = false;
    private ConstantState fullHeartConstantState;
    private ConstantState emptyHeartConstantState;
    private String sharedTrailerUrl;
    private Uri mainTrailerUri;
    private TransitionListenerAdapter transitionListener;

    public static Intent getMovieDetailsIntent(Context context, Movie movie, String sharedElementName){
        Intent intent = new Intent(context,MovieDetailsActivity.class);
        intent.putExtra(EXTRA_MOVIE,movie);
        intent.putExtra(EXTRA_SHARED_ELEMENT_NAME,sharedElementName);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ((PopularMoviesApplication)getApplication()).createMovieDetailsComponent().inject(this);
        Intent intent = getIntent();
        movie = intent.getParcelableExtra(EXTRA_MOVIE);
        sharedElementName = intent.getStringExtra(EXTRA_SHARED_ELEMENT_NAME);
        setContentView(R.layout.activity_movie_details);
        ButterKnife.bind(this);
        presenter.attachView(this);
        setupShareElementTransition();
        setupViews();



//        MovieInfoFragment movieDetailsFragment = (MovieInfoFragment)
//                fragmentManager.findFragmentByTag(TAG_MOVIE_DETAILS_FRAGMENT);
//        if (savedInstanceState == null && movieDetailsFragment == null){
//            movieDetailsFragment = MovieInfoFragment.newInstance(movie,sharedElementName);
//            fragmentManager.beginTransaction()
//                    .replace(R.id.movie_details_container,movieDetailsFragment, TAG_MOVIE_DETAILS_FRAGMENT)
//                    .commit();
//        }
    }

    private void setupShareElementTransition() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            transitionListener = new TransitionListenerAdapter() {
                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onTransitionEnd(Transition transition) {
                    super.onTransitionEnd(transition);
                    setupViewPager();
                    getWindow().getSharedElementEnterTransition().removeListener(transitionListener);
                }
            };
            posterImage.setTransitionName(sharedElementName);
            getWindow().getSharedElementEnterTransition().addListener(transitionListener);
        }
    }

    private void setupViewPager() {
        MovieDetailsPagerAdapter detailsPagerAdapter = new MovieDetailsPagerAdapter(
                getSupportFragmentManager(),movie);
        detailsViewPager.setAdapter(detailsPagerAdapter);
        detailsTabLayout.setupWithViewPager(detailsViewPager);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void enterReveal() {
        if (!isDestroyed()) {
            blurPoster.setVisibility(View.VISIBLE);
            final int finalRadius = Math.max(blurPoster.getWidth(), blurPoster.getHeight()) / 2;
            Animator circularReveal = ViewAnimationUtils.createCircularReveal(blurPoster
                    , blurPoster.getWidth() / 2, blurPoster.getHeight() / 2
                    , 0, finalRadius);
            circularReveal.start();
        }
    }

    @Override
    public void showFavoriteMovie() {
        if (!isFavorite) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                AnimatedVectorDrawable emptyHeart = (AnimatedVectorDrawable)
                        emptyHeartConstantState.newDrawable();
                fab.setImageDrawable(emptyHeart);
                emptyHeart.start();

            } else {
                fab.setImageResource(R.drawable.heart_fill);
            }
            isFavorite = true;
        }
    }

    @Override
    public void showNonFavoriteMovie() {
        if (isFavorite) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                AnimatedVectorDrawable fullHeart = (AnimatedVectorDrawable)
                        fullHeartConstantState.newDrawable();
                fab.setImageDrawable(fullHeart);
                fullHeart.start();

            } else {
                fab.setImageResource(R.drawable.fab_heart_empty);
            }
            isFavorite = false;
        }
    }
    @Override
    public void showWatchlistMovie() {
        toggleWatchlist.setChecked(true);
    }

    @Override
    public void showNormalMovie() {
        toggleWatchlist.setChecked(false);
    }

    @Override
    public void showRuntime(String runtime) {
        textRuntime.setText(runtime);
    }

    @Override
    public void showOmdbDetails(MovieDetails movieDetails) {
        textGenres.setText(movieDetails.genre());
        imageMpaaRating.setImageDrawable(ContextCompat.getDrawable(this
                ,chooseRatingImage(movieDetails.rated())));
    }

    @Override
    public void showReviewMessage(String message) {
        Snackbar.make(coordinatorLayout,message,Snackbar.LENGTH_SHORT).show();
    }

    @Override
    public void showShareIcon(String trailerUrl) {
        sharedTrailerUrl = trailerUrl;
        supportInvalidateOptionsMenu();
    }

    @Override
    public void showPlayMainTrailer(Uri mainTrailerUri) {
        this.mainTrailerUri = mainTrailerUri;
        buttonPlayTrailer.setVisibility(View.VISIBLE);
    }

    private @DrawableRes
    int chooseRatingImage(String rating){
        switch (rating){
            case "PG-13":
                return R.drawable.ic_rated_pg_13;
            case "PG":
                return R.drawable.ic_rated_pg;
            case "R":
                return R.drawable.ic_rated_r;
            case "G":
                return R.drawable.ic_rated_g;
            case "NC-17":
                return R.drawable.ic_rated_nc_17;
            default:
                return R.drawable.ic_not_applicable;
        }
    }

    @OnClick(R.id.fab_favorite)
    public void onFabClicked(){
        if (isFavorite){
            presenter.removeMovieFromFavorites(movie.id());
        }else {
            presenter.addMovieToFavorites(movie);
        }
    }

    @OnClick(R.id.toggle_watchlist)
    public void onWatchlistClicked(){
        if (!toggleWatchlist.isChecked()){
            presenter.removeMovieFromWatchlist(movie.id());
        }else {
            presenter.addMovieToWatchlist(movie);
        }
    }

    @OnClick({R.id.image_backdrop,R.id.button_play_main_trailer})
    public void onPlayTrailerClicked(){
        if (mainTrailerUri != null) {
            Intent intent = new Intent(Intent.ACTION_VIEW,mainTrailerUri);
            startActivity(intent);
        }
    }

    private void setupViews(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            fullHeartConstantState = ContextCompat.getDrawable(this,R.drawable.fab_heart_fill).getConstantState();
            emptyHeartConstantState = ContextCompat.getDrawable(this,R.drawable.fab_heart_empty).getConstantState();
            getWindow().setStatusBarColor(ContextCompat.getColor(this,R.color.transparent_black));
        }
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        presenter.isMovieFavorite(movie.id());
        presenter.isMovieInWatchlist(movie.id());



        getSupportActionBar().setDisplayShowTitleEnabled(false);
        toolbarMovieTitle.setAlpha(0);
        toolbarMovieTitle.setText(movie.title());
        appBarLayout.addOnOffsetChangedListener(this);
        populateMovieDetilas();
    }

    private void populateMovieDetilas(){
        textMovieTitle.setText(movie.title());
        release.setText(Utilities.getFormattedDate(movie.releaseDate(),Utilities.MONTH_YEAR_DATE_FORMAT));
        Picasso.with(this)
                .load(Utilities.getFullPosterPath(this,movie.posterPath(),Utilities.QUALITY_LOW))
                .networkPolicy(NetworkPolicy.OFFLINE)
                .transform(new PaletteTransformation())
                .into(posterImage, new PaletteTransformation.Callback(posterImage) {
                    @Override
                    public void onPalette(Palette palette) {
                        if (palette != null) {
                            Palette.Swatch darkVibrantSwatch = palette.getDarkVibrantSwatch();
                            if (collapsingToolbar != null && darkVibrantSwatch != null) {
                                int darkVibrantColor = darkVibrantSwatch.getRgb();
                                collapsingToolbar.setContentScrimColor(darkVibrantColor);
                                collapsingToolbar.setStatusBarScrimColor(darkVibrantColor);
                                detailsTabLayout.setBackgroundColor(darkVibrantColor);
                                GradientDrawable gradient = new GradientDrawable
                                        (GradientDrawable.Orientation.TL_BR,new int[]{
                                                blackColor,
                                                darkVibrantColor
                                        });
                                gradient.setGradientType(GradientDrawable.LINEAR_GRADIENT);
                                appbarConstraintLayout.setBackground(gradient);
                            }
                        }
                    }});

        Picasso.with(this).load(Utilities.getFullBackdropPath(this,movie.backdropPath()
                ,Movie.QUALITY_MEDIUM)).fit().centerCrop()
                .into(blurPoster, new Callback() {
                    @Override
                    public void onSuccess() {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            enterReveal();
                        }else {
                            blurPoster.setVisibility(View.VISIBLE);
                        }
                    }
                    @Override
                    public void onError() {
                    }
                });
    }


    @Override
    public boolean onNavigateUp() {
        supportFinishAfterTransition();
        return true;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_movie_details,menu);
        if (sharedTrailerUrl != null){
            menu.findItem(R.id.menu_share).setVisible(true);
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                onNavigateUp();
                return true;
            case R.id.menu_share:
                Utilities.createShareIntent(this,movie.title(), sharedTrailerUrl);
                Timber.d("Share Clicked!");
                return true;
        }
        return false;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.detachView();
        ((PopularMoviesApplication)getApplication()).releaseMovieDetailsComponent();
    }

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if(collapsingToolbar.getHeight() + verticalOffset > collapsingToolbar.getScrimVisibleHeightTrigger()){
            toolbarMovieTitle.animate().alpha(0).setDuration(250);
        }else {
            toolbarMovieTitle.animate().alpha(1).setDuration(500);

        }
    }


    @Override
    public void delegateItemClicked(Object item, ImageView sharedView) {
        //Dosen't handle master/detail views
        Intent intent;
        String transitionName = "";
        if (item instanceof Cast){
            Cast clickedCastItem = (Cast) item;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                transitionName = sharedView.getTransitionName();
                intent = ActorDetailsActivity.getActorDetailsIntent(this,clickedCastItem,transitionName);
                ActivityOptions activityOptions = ActivityOptions
                        .makeSceneTransitionAnimation(this,sharedView,sharedView.getTransitionName());
                startActivity(intent,activityOptions.toBundle());

            }else {
                intent = ActorDetailsActivity.getActorDetailsIntent(this,clickedCastItem,transitionName);
                startActivity(intent);
            }
        }else if (item instanceof Movie){
            Movie clickedMovie = (Movie) item;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                transitionName = sharedView.getTransitionName();
                intent = getMovieDetailsIntent(this,clickedMovie,transitionName);
                ActivityOptions activityOptions = ActivityOptions
                        .makeSceneTransitionAnimation(this,sharedView,sharedView.getTransitionName());
                startActivity(intent,activityOptions.toBundle());

            }else {
                intent = MovieDetailsActivity.getMovieDetailsIntent(this,clickedMovie,transitionName);
                startActivity(intent);
            }
        }
        else {
            throw new IllegalArgumentException("Unknown item type");
        }
    }
}
app/src/main/java/com/rashwan/reactive_popular_movies/feature/movieDetails/ShowDetailsInActivity.java
public interface ShowDetailsInActivity {
    void showRuntime(String runtime);
    void showOmdbDetails(MovieDetails movieDetails);
    void showReviewMessage(String message);
    void showShareIcon(String trailerUrl);
    void showPlayMainTrailer(Uri mainTrailerUrl);
}
app/src/main/java/com/rashwan/reactive_popular_movies/common/utilities/DelegateToActivity.java
public interface DelegateToActivity<T> {
    void delegateItemClicked(T item, ImageView sharedView);

}
app/src/main/java/com/rashwan/reactive_popular_movies/PopularMoviesApplication.java
public class PopularMoviesApplication extends Application {
    private static ApplicationComponent applicationComponent;
    private BrowseMoviesComponent browseMoviesComponent;
    private MovieDetailsComponent movieDetailsComponent;
    private MovieInfoComponent movieInfoComponent;
    private NearbyMoviesComponent nearbyMoviesComponent;
    private FavoriteMoviesComponent favoriteMoviesComponent;
    private WatchlistComponent watchlistComponent;
    private MovieReviewsComponent movieReviewsComponent;
    private MovieCastComponent movieCastComponent;
    private ActorInfoComponent actorInfoComponent;
    private ActorMoviesComponent actorMoviesComponent;
    private ActorDetailsComponent actorDetailsComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        if (LeakCanary.isInAnalyzerProcess(this)) {
            // This process is dedicated to LeakCanary for heap analysis.
            // You should not init your app in this process.
            return;
        }
        LeakCanary.install(this);
        applicationComponent = createAppComponent();

        Timber.plant(new Timber.DebugTree() {
            @Override
            protected String createStackElementTag(StackTraceElement element) {
                return super.createStackElementTag(element) + ':' + element.getLineNumber();
            }
        });


    }

    private ApplicationComponent createAppComponent() {
        return DaggerApplicationComponent.builder().applicationModule(new ApplicationModule(this))
                .castRepositoryModule(new CastRepositoryModule())
                .moviesRepositoryModule(new MoviesRepositoryModule())
                .build();
    }

    public BrowseMoviesComponent createBrowseMoviesComponent(){
         browseMoviesComponent = applicationComponent.plus(new BrowseMoviesModule());

        return browseMoviesComponent;
    }

    public MovieDetailsComponent createMovieDetailsComponent(){
        movieDetailsComponent = applicationComponent.plusMovieDetailsComponent();
        return movieDetailsComponent;
    }

    public NearbyMoviesComponent createNearbyMoviesComponent(){
        nearbyMoviesComponent = applicationComponent.plus(new NearbyMoviesModule());
        return nearbyMoviesComponent;
    }

    public FavoriteMoviesComponent createFavoriteMoviesComponent(){
        favoriteMoviesComponent = applicationComponent.plus(new FavoriteMoviesModule());
        return favoriteMoviesComponent;
    }

    public WatchlistComponent createWatchlistComponent(){
        watchlistComponent = applicationComponent.plus(new WatchlistModule());
        return watchlistComponent;
    }
    public MovieInfoComponent createMovieInfoComponent(){
        movieInfoComponent = applicationComponent.plus(new MovieInfoModule());
        return movieInfoComponent;
    }
    public MovieReviewsComponent createMovieReviewsComponent(){
        movieReviewsComponent = applicationComponent.plus(new MovieReviewsModule());
        return movieReviewsComponent;
    }
    public MovieCastComponent createMovieCastComponent(){
        movieCastComponent = applicationComponent.plus(new MovieCastModule());
        return movieCastComponent;
    }

    public ActorInfoComponent createActorInfoComponent(){
        actorInfoComponent = applicationComponent.plus(new ActorInfoModule());
        return actorInfoComponent;
    }

    public ActorMoviesComponent createActorMoviesComponent(){
        actorMoviesComponent = applicationComponent.plus(new ActorMoviesModule());
        return actorMoviesComponent;
    }
    public ActorDetailsComponent createActorDetailsComponent(){
        actorDetailsComponent = applicationComponent.plusActorDetailsComponent();
        return actorDetailsComponent;
    }


    public void releaseBrowseMoviesComponent(){
        browseMoviesComponent = null;
    }
    public void releaseMovieDetailsComponent(){
        movieDetailsComponent = null;
    }
    public void releaseNearbyMoviesComponent(){
        nearbyMoviesComponent = null;
    }
    public void releaseFavoriteMoviesComponent(){
        favoriteMoviesComponent = null;
    }
    public void releaseWatchlistMoviesComponent(){
        watchlistComponent = null;
    }
    public void releaseMovieInfoComponent(){
        movieInfoComponent = null;
    }
    public void releaseMovieReviewsComponent(){
        movieReviewsComponent = null;
    }
    public void releaseMovieCastComponent(){
        movieCastComponent = null;
    }
    public void releaseActorInfoComponent(){actorInfoComponent = null;}
    public void releaseActorMoviesComponent(){actorMoviesComponent = null;}
    public void releaseActorDetailsComponent(){actorDetailsComponent = null;}



    public static ApplicationComponent getApplicationComponent(){
        return applicationComponent;
    }
}
app/src/main/java/com/rashwan/reactive_popular_movies/feature/discoverMovies/BrowseMoviesActivity.java
public class BrowseMoviesActivity extends BaseActivity implements DelegateToActivity<Movie> {

    @BindView(R.id.slidingTabs) TabLayout tabLayout;
    @BindView(R.id.viewpager) ViewPager viewPager;
    @BindView(R.id.navigation_view) NavigationView navigationView;
    @BindView(R.id.browse_toolbar) Toolbar toolbar;
    private BrowseMoviesPagerAdapter browseMoviesPagerAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browse_movies);
        navigationView.setCheckedItem(R.id.nav_discover);
        browseMoviesPagerAdapter = new BrowseMoviesPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(browseMoviesPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
        toolbar.setTitle(R.string.nav_discover_title);
        super.onCreateBaseActivity(savedInstanceState);

    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == NearbyMoviesFragment.REQUEST_RESOLVE_ERROR){
            browseMoviesPagerAdapter.getItem(viewPager.getCurrentItem())
                    .onActivityResult(requestCode,resultCode,data);
        }else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}


Question: package com.rashwan.reactive_popular_movies.feature.movieDetails.movieInfo;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.rashwan.reactive_popular_movies.PopularMoviesApplication;
import com.rashwan.reactive_popular_movies.R;
import com.rashwan.reactive_popular_movies.common.utilities.DelegateToActivity;
import com.rashwan.reactive_popular_movies.data.model.Movie;
import com.rashwan.reactive_popular_movies.data.model.MovieDetails;
import com.rashwan.reactive_popular_movies.data.model.Rating;
import com.rashwan.reactive_popular_movies.data.model.Trailer;
import com.rashwan.reactive_popular_movies.feature.discoverMovies.BrowseMoviesActivity;
import com.rashwan.reactive_popular_movies.feature.favoriteMovies.FavoriteMoviesActivity;
import com.rashwan.reactive_popular_movies.feature.movieDetails.MovieDetailsActivity;
import com.rashwan.reactive_popular_movies.feature.movieDetails.ShowDetailsInActivity;
import java.util.List;
import javax.inject.Inject;
import butterknife.BindColor;
import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import rx.Observable;






/**
 * Created by rashwan on 7/3/16.
 */

public class MovieInfoFragment extends Fragment implements MovieInfoView
        ,MovieTrailersAdapter.ClickListener,SimilarMoviesAdapter.ClickListener {

    private static final String ARGUMENT_MOVIE_ID = "ARGUMENT_MOVIE_ID";
    private static final String ARGUMENT_DESCRIPTION = "ARGUMENT_DESCRIPTION";
    private static final String ARGUMENT_TMDB_RATING = "ARGUMENT_TMDB_RATING";
    private static final ButterKnife.Action<View> SHOW = (view, index) -> view.setVisibility(View.VISIBLE);
    private static final ButterKnife.Action<View> HIDE = (view, index) -> view.setVisibility(View.GONE);
Answer:     private DelegateToActivity<Movie> delegateListener;