<commit_before>package com.setiawanpaiman.tmdb.android.moviedetail;

import com.setiawanpaiman.tmdb.android.data.source.MovieRepository;
import com.setiawanpaiman.tmdb.android.data.viewmodel.MovieViewModel;
import com.setiawanpaiman.tmdb.android.util.scheduler.BaseSchedulerProvider;

import javax.inject.Inject;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable;

/**
 * Created by <NAME> on 1/7/17.
 */

class MovieDetailPresenter implements MovieDetailContract.Presenter {

    private final long mMovieId;
    private final MovieDetailContract.View mMovieDetailView;
    private final MovieRepository mMovieRepository;
    private final BaseSchedulerProvider mSchedulerProvider;

    @NonNull
    private CompositeDisposable mComposite;

    @Inject
    MovieDetailPresenter(@NonNull long movieId,
                         MovieDetailContract.View movieDetailView,
                         MovieRepository movieRepository,
                         BaseSchedulerProvider schedulerProvider) {
        this.mMovieId = movieId;
        this.mMovieDetailView = movieDetailView;
        this.mMovieRepository = movieRepository;
        this.mSchedulerProvider = schedulerProvider;

        this.mComposite = new CompositeDisposable();
    }

    @Override
    public void subscribe() {
        //no-op
    }

    @Override
    public void unsubscribe() {
        this.mComposite.clear();
    }

    @Override
    public void loadTrailers() {
        mComposite.add(mMovieRepository.getTrailers(mMovieId)
                .subscribeOn(mSchedulerProvider.io())
                .observeOn(mSchedulerProvider.ui())
                .subscribe(mMovieDetailView::showTrailers));
    }

    @Override
    public void loadReviews() {
        mComposite.add(mMovieRepository.getReviews(mMovieId)
                .subscribeOn(mSchedulerProvider.io())
                .observeOn(mSchedulerProvider.ui())
                .subscribe(mMovieDetailView::showReviews));
    }

    @Override
    public boolean isFavoriteMovie(MovieViewModel movieViewModel) {
        return mMovieRepository.isFavoriteMovie(movieViewModel);
    }

    @Override
    public boolean addFavoriteMovie(MovieViewModel movieViewModel) {
        return mMovieRepository.addFavoriteMovie(movieViewModel);
    }

    @Override
    public boolean removeFavoriteMovie(MovieViewModel movieViewModel) {
        return mMovieRepository.removeFavoriteMovie(movieViewModel);<commit_msg>Handle error of load trailers and reviews<commit_after>package com.setiawanpaiman.tmdb.android.moviedetail;

import com.setiawanpaiman.tmdb.android.data.source.MovieRepository;
import com.setiawanpaiman.tmdb.android.data.viewmodel.MovieViewModel;
import com.setiawanpaiman.tmdb.android.util.scheduler.BaseSchedulerProvider;

import java.util.ArrayList;

import javax.inject.Inject;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable;

/**
 * Created by <NAME> on 1/7/17.
 */

class MovieDetailPresenter implements MovieDetailContract.Presenter {

    private final long mMovieId;
    private final MovieDetailContract.View mMovieDetailView;
    private final MovieRepository mMovieRepository;
    private final BaseSchedulerProvider mSchedulerProvider;

    @NonNull
    private CompositeDisposable mComposite;

    @Inject
    MovieDetailPresenter(@NonNull long movieId,
                         MovieDetailContract.View movieDetailView,
                         MovieRepository movieRepository,
                         BaseSchedulerProvider schedulerProvider) {
        this.mMovieId = movieId;
        this.mMovieDetailView = movieDetailView;
        this.mMovieRepository = movieRepository;
        this.mSchedulerProvider = schedulerProvider;

        this.mComposite = new CompositeDisposable();
    }

    @Override
    public void subscribe() {
        //no-op
    }

    @Override
    public void unsubscribe() {
        this.mComposite.clear();
    }

    @Override
    public void loadTrailers() {
        mComposite.add(mMovieRepository.getTrailers(mMovieId)
                .subscribeOn(mSchedulerProvider.io())
                .observeOn(mSchedulerProvider.ui())
                .subscribe(mMovieDetailView::showTrailers,
                        (t) -> mMovieDetailView.showTrailers(new ArrayList<>()), () -> {}));
    }

    @Override
    public void loadReviews() {
        mComposite.add(mMovieRepository.getReviews(mMovieId)
                .subscribeOn(mSchedulerProvider.io())
                .observeOn(mSchedulerProvider.ui())
                .subscribe(mMovieDetailView::showReviews,
                        (t) -> mMovieDetailView.showReviews(new ArrayList<>()), () -> {}));
    }

    @Override
    public boolean isFavoriteMovie(MovieViewModel movieViewModel) {
        return mMovieRepository.isFavoriteMovie(movieViewModel);
    }

    @Override
    public boolean addFavoriteMovie(MovieViewModel movieViewModel) {
        return mMovieRepository.addFavoriteMovie(movieViewModel);
    }

    @Override
    public boolean removeFavoriteMovie(MovieViewModel movieViewModel) {
        return mMovieRepository.removeFavoriteMovie(movieViewModel);
{'fraction_non_alphanumeric': 0.08073217726396917, 'fraction_numerical': 0.0015414258188824663, 'mean_word_length': 3.05546875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3232738', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1409, 'n_words': 235}