package com.tobi.movies.posterdetails;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import rx.Subscriber;

public class MovieDetailsPresenter implements MovieDetailsMVP.Presenter {

    private final MovieDetailsRepository repository;

    @Nullable
    private MovieDetailsMVP.View view;

    @Nullable
    private Subscriber<MovieDetails> subscriber;

    public MovieDetailsPresenter(MovieDetailsRepository repository) {
        this.repository = repository;
    }

    @Override
    public void startPresenting(MovieDetailsMVP.View movieDetailsView, long movieId) {
        this.view = movieDetailsView;
        subscriber = createSubscriber();
        repository.getMovieDetails(movieId).subscribe(subscriber);
    }

    @Override
    public void stopPresenting() {
        if (subscriber != null) {
            subscriber.unsubscribe();
        }
        view = null;
    }

    @NonNull
    private Subscriber<MovieDetails> createSubscriber() {
        return new Subscriber<MovieDetails>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                if (MovieDetailsPresenter.this.view != null) {
                    MovieDetailsPresenter.this.view.showError();
                }
            }

            @Override
            public void onNext(MovieDetails movieDetails) {
                if (MovieDetailsPresenter.this.view != null) {
                    MovieDetailsPresenter.this.view.display(movieDetails);
                }
            }
        };
    }
}

@@ -37,472 +37,273 @@
 s;%0A%0A
-import android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0A%0Aimport rx.Subscriber;%0A%0Apublic class MovieDetailsPresenter implements MovieDetailsMVP.Presenter %7B%0A%0A    private final MovieDetailsRepository repository;%0A%0A    @Nullable%0A    private MovieDetailsMVP.View view;%0A%0A    @Nullable%0A    private Subscriber%3CMovieDetails%3E subscriber;%0A%0A    public MovieDetailsPresenter(MovieDetailsRepository repository) %7B%0A        this.repository = repository
+public class MovieDetailsPresenter implements MovieDetailsMVP.Presenter %7B%0A%0A    private final MovieDetailsUseCase movieDetailsUseCase;%0A%0A    public MovieDetailsPresenter(MovieDetailsUseCase movieDetailsUseCase) %7B%0A        this.movieDetailsUseCase = movieDetailsUseCase
 ;%0A  
@@ -353,16 +353,22 @@
 senting(
+final 
 MovieDet
@@ -426,426 +426,256 @@
     
-this.view = movieDetailsView;%0A        subscriber = createSubscriber();%0A        repository.getMovieDetails(movieId).subscribe(subscriber
+MovieDetails movieDetails = movieDetailsUseCase.getMovieDetails(
 );%0A    
-%7D%0A%0A
     
-@Override%0A    public void stopPresenting() %7B%0A        if (subscriber != null) %7B%0A            subscriber.unsubscribe();%0A        %7D%0A        view = null;
+if (movieDetails != null) %7B%0A            movieDetailsView.display(movieDetails);%0A        %7D else %7B
 %0A    
-%7D%0A%0A
     
-@NonNull%0A    private Subscriber%3CMovieDetails%3E createSubscriber() %7B%0A        return new Subscriber%3CMovieDetails%3E
+    movieDetailsUseCase.setListener(new MovieDetailsUseCase.Listener
 () %7B
@@ -679,32 +679,36 @@
 ) %7B%0A            
+  
+  
 @Override%0A      
@@ -693,32 +693,36 @@
       @Override%0A
+    
             publ
@@ -735,23 +735,114 @@
 d on
-Completed() %7B%0A%0A
+MovieDetails(MovieDetails movieDetails) %7B%0A                    movieDetailsView.display(movieDetails);%0A    
     
@@ -844,32 +844,36 @@
              %7D%0A%0A
+    
             @Ove
@@ -882,32 +882,36 @@
 ide%0A            
+    
 public void onEr
@@ -928,72 +928,17 @@
 ble 
-e) %7B%0A                if (MovieDetailsPresenter.this.view != null
+throwable
 ) %7B%0A
@@ -949,33 +949,33 @@
                 
-M
+m
 ovieDetailsPrese
@@ -969,32 +969,17 @@
 eDetails
-Presenter.this.v
+V
 iew.show
@@ -1014,34 +1014,45 @@
            %7D
-%0A%0A        
+);%0A        %7D%0A%0A    %7D%0A%0A
     @Overrid
@@ -1049,32 +1049,24 @@
   @Override%0A
-        
     public v
@@ -1073,223 +1073,72 @@
 oid 
-onNext(MovieDetails movieDetails) %7B%0A                if (MovieDetailsPresenter.this.view != null) %7B%0A                    MovieDetailsPresenter.this.view.display(movieDetails);%0A                %7D%0A            %7D%0A        %7D
+stopPresenting() %7B%0A        movieDetailsUseCase.setListener(null)
 ;%0A  

Use MovieDetailsUseCase Model in MovieDetailsPresenter