// Path: app/src/main/java/com/xurxodev/moviesandroidkata/MoviesApplication.java
// public class MoviesApplication extends Application {
//     private ApplicationComponent appComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         // Dagger%COMPONENT_NAME%
//         appComponent = DaggerApplicationComponent.builder()
//                 .appModule(new AppModule(this))
//                 .dataModule(new DataModule())
//                 .build();
// 
//     }
// 
//     public ApplicationComponent getAppComponent() {
//         return appComponent;
//     }
// }
// 
// Path: app/src/main/java/com/xurxodev/moviesandroidkata/di/module/ActivityModule.java
// @Module
// public class ActivityModule {
//     private final Activity activityContext;
// 
//     public ActivityModule(Activity activityContext) {
//         this.activityContext = activityContext;
//     }
// 
//     @Provides
//     @ActivityScope
//     Activity provideActivityContext() {
//         return this.activityContext;
//     }
// 
//     @Provides
//     @ActivityScope
//     Navigator provideNavigator(Activity activityContext) {
//         return new TransitionAnimationNavigator(activityContext);
//     }
// 
//     @Provides
//     @ActivityScope
//     MoviesPresenter provideMoviesPresenter(
//             Navigator navigator, GetMoviesUseCase getGetMoviesUseCase) {
//         return new MoviesPresenter(navigator, getGetMoviesUseCase);
//     }
// 
//     @Provides
//     @ActivityScope
//     MovieDetailPresenter provideMovieDetailPresenter(GetMovieDetailUseCase getMovieDetailUseCase) {
//         return new MovieDetailPresenter(getMovieDetailUseCase);
//     }
// }
// 
// Path: app/src/main/java/com/xurxodev/moviesandroidkata/presentation/presenter/MovieDetailPresenter.java
// public class MovieDetailPresenter {
// 
//     private View view;
//     private GetMovieDetailUseCase getMovieDetailUseCase;
// 
// 
//     private Movie movie;
// 
//     public MovieDetailPresenter(GetMovieDetailUseCase getCompetitorDetailsUseCase) {
//         this.getMovieDetailUseCase = getCompetitorDetailsUseCase;
//     }
// 
//     public void attachView(View view, String movieName) {
//         if (view == null) {
//             throw new IllegalArgumentException("You can't set a null view");
//         }
//         this.view = view;
//         loadCompetitor(movieName);
//     }
// 
//     public void loadCompetitor(String movieTitle) {
//         view.showLoading();
// 
//         getMovieDetailUseCase.execute(movieTitle,
//                 new GetMovieDetailUseCase.Callback() {
//                     @Override
//                     public void onCompetitorDetailLoaded(Movie retrievedMovie) {
// 
//                         movie = retrievedMovie;
// 
//                         if (view.isReady()) {
//                             view.hideLoading();
//                             view.renderImage(movie.getImage());
//                             view.renderOverview(movie.getOverview());
//                             view.renderTitle(movie.getTitle());
//                         }
//                     }
// 
//                     @Override
//                     public void onCompetitorDetailNotFound() {
//                         view.hideLoading();
//                         //TODO: show message in view
//                     }
// 
//                     @Override
//                     public void onConnectionError() {
//                         view.hideLoading();
//                         //TODO: show message in view
//                     }
//                 });
// 
//     }
// 
// 
//     public interface View {
//         void renderImage(String image);
// 
//         void renderOverview(String biography);
// 
//         void renderTitle(String title);
// 
//         void showLoading();
// 
//         void hideLoading();
// 
//         boolean isReady();
//     }
// }


import static com.xurxodev.moviesandroidkata.presentation.view.activity.MovieDetailActivity
        .MOVIE_TITLE;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.Fragment;
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.ProgressBar;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import com.xurxodev.moviesandroidkata.MoviesApplication;
import com.xurxodev.moviesandroidkata.R;
import com.xurxodev.moviesandroidkata.di.module.ActivityModule;
import com.xurxodev.moviesandroidkata.presentation.presenter.MovieDetailPresenter;
import javax.inject.Inject;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_movie_detail, container, false);


        if (getArguments().containsKey(MOVIE_TITLE)) {

            String competitorName = (String) getArguments().get(MOVIE_TITLE);

            appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.app_bar);
            progressBarLoading = (ProgressBar) getActivity().findViewById(R.id.pb_loading);

            initializePresenter(competitorName);
        }

        return rootView;
    }

    private void initializePresenter(String competitorName) {
        presenter.attachView(this, competitorName);
    }

    @Override
    public void renderImage(String image) {
        Activity activity = this.getActivity();

        ImageView imgtoolbar = (ImageView) activity.findViewById(R.id.imgToolbar);

        if (imgtoolbar != null) {
            Picasso.with(activity.getApplicationContext()).load(image)
// Path: app/src/main/java/com/xurxodev/moviesandroidkata/MoviesApplication.java
// public class MoviesApplication extends Application {
//     private ApplicationComponent appComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         // Dagger%COMPONENT_NAME%
//         appComponent = DaggerApplicationComponent.builder()
//                 .appModule(new AppModule(this))
//                 .dataModule(new DataModule())
//                 .build();
// 
//     }
// 
//     public ApplicationComponent getAppComponent() {
//         return appComponent;
//     }
// }
// 
// Path: app/src/main/java/com/xurxodev/moviesandroidkata/di/module/ActivityModule.java
// @Module
// public class ActivityModule {
//     private final Activity activityContext;
// 
//     public ActivityModule(Activity activityContext) {
//         this.activityContext = activityContext;
//     }
// 
//     @Provides
//     @ActivityScope
//     Activity provideActivityContext() {
//         return this.activityContext;
//     }
// 
//     @Provides
//     @ActivityScope
//     Navigator provideNavigator(Activity activityContext) {
//         return new TransitionAnimationNavigator(activityContext);
//     }
// 
//     @Provides
//     @ActivityScope
//     MoviesPresenter provideMoviesPresenter(
//             Navigator navigator, GetMoviesUseCase getGetMoviesUseCase) {
//         return new MoviesPresenter(navigator, getGetMoviesUseCase);
//     }
// 
//     @Provides
//     @ActivityScope
//     MovieDetailPresenter provideMovieDetailPresenter(GetMovieDetailUseCase getMovieDetailUseCase) {
//         return new MovieDetailPresenter(getMovieDetailUseCase);
//     }
// }
// 
// Path: app/src/main/java/com/xurxodev/moviesandroidkata/presentation/presenter/MovieDetailPresenter.java
// public class MovieDetailPresenter {
// 
//     private View view;
//     private GetMovieDetailUseCase getMovieDetailUseCase;
// 
// 
//     private Movie movie;
// 
//     public MovieDetailPresenter(GetMovieDetailUseCase getCompetitorDetailsUseCase) {
//         this.getMovieDetailUseCase = getCompetitorDetailsUseCase;
//     }
// 
//     public void attachView(View view, String movieName) {
//         if (view == null) {
//             throw new IllegalArgumentException("You can't set a null view");
//         }
//         this.view = view;
//         loadCompetitor(movieName);
//     }
// 
//     public void loadCompetitor(String movieTitle) {
//         view.showLoading();
// 
//         getMovieDetailUseCase.execute(movieTitle,
//                 new GetMovieDetailUseCase.Callback() {
//                     @Override
//                     public void onCompetitorDetailLoaded(Movie retrievedMovie) {
// 
//                         movie = retrievedMovie;
// 
//                         if (view.isReady()) {
//                             view.hideLoading();
//                             view.renderImage(movie.getImage());
//                             view.renderOverview(movie.getOverview());
//                             view.renderTitle(movie.getTitle());
//                         }
//                     }
// 
//                     @Override
//                     public void onCompetitorDetailNotFound() {
//                         view.hideLoading();
//                         //TODO: show message in view
//                     }
// 
//                     @Override
//                     public void onConnectionError() {
//                         view.hideLoading();
//                         //TODO: show message in view
//                     }
//                 });
// 
//     }
// 
// 
//     public interface View {
//         void renderImage(String image);
// 
//         void renderOverview(String biography);
// 
//         void renderTitle(String title);
// 
//         void showLoading();
// 
//         void hideLoading();
// 
//         boolean isReady();
//     }
// }


// Path: app/src/main/java/com/xurxodev/moviesandroidkata/presentation/view/fragment/MovieDetailFragment.java
import static com.xurxodev.moviesandroidkata.presentation.view.activity.MovieDetailActivity
        .MOVIE_TITLE;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.Fragment;
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.ProgressBar;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import com.xurxodev.moviesandroidkata.MoviesApplication;
import com.xurxodev.moviesandroidkata.R;
import com.xurxodev.moviesandroidkata.di.module.ActivityModule;
import com.xurxodev.moviesandroidkata.presentation.presenter.MovieDetailPresenter;
import javax.inject.Inject;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_movie_detail, container, false);


        if (getArguments().containsKey(MOVIE_TITLE)) {

            String competitorName = (String) getArguments().get(MOVIE_TITLE);

            appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.app_bar);
            progressBarLoading = (ProgressBar) getActivity().findViewById(R.id.pb_loading);

            initializePresenter(competitorName);
        }

        return rootView;
    }

    private void initializePresenter(String competitorName) {
        presenter.attachView(this, competitorName);
    }

    @Override
    public void renderImage(String image) {
        Activity activity = this.getActivity();

        ImageView imgtoolbar = (ImageView) activity.findViewById(R.id.imgToolbar);

        if (imgtoolbar != null) {
            Picasso.with(activity.getApplicationContext()).load(image)
                    .into(imgtoolbar);