Search in sources :

Example 1 with PhilmPersonCredit

use of app.philm.in.model.PhilmPersonCredit in project philm by chrisbanes.

the class FetchTmdbPersonCreditsRunnable method onSuccess.

@Override
public void onSuccess(PersonCredits result) {
    PhilmPerson person = mMoviesState.getPerson(mId);
    if (person != null) {
        if (!PhilmCollections.isEmpty(result.cast)) {
            List<PhilmPersonCredit> credits = new ArrayList<>();
            for (PersonCastCredit credit : result.cast) {
                credits.add(new PhilmPersonCredit(credit));
            }
            Collections.sort(credits, PhilmPersonCredit.COMPARATOR_SORT_DATE);
            person.setCastCredits(credits);
        }
        if (!PhilmCollections.isEmpty(result.crew)) {
            List<PhilmPersonCredit> credits = new ArrayList<>();
            for (PersonCrewCredit credit : result.crew) {
                credits.add(new PhilmPersonCredit(credit));
            }
            Collections.sort(credits, PhilmPersonCredit.COMPARATOR_SORT_DATE);
            person.setCrewCredits(credits);
        }
        person.setFetchedCredits(true);
        getEventBus().post(new MoviesState.PersonChangedEvent(getCallingId(), person));
    }
}
Also used : PersonCastCredit(com.uwetrottmann.tmdb.entities.PersonCastCredit) PersonCrewCredit(com.uwetrottmann.tmdb.entities.PersonCrewCredit) ArrayList(java.util.ArrayList) PhilmPerson(app.philm.in.model.PhilmPerson) PhilmPersonCredit(app.philm.in.model.PhilmPersonCredit) MoviesState(app.philm.in.state.MoviesState)

Example 2 with PhilmPersonCredit

use of app.philm.in.model.PhilmPersonCredit in project philm by chrisbanes.

the class FetchTmdbPersonRunnable method onSuccess.

@Override
public void onSuccess(Person result) {
    PhilmPerson person = getTmdbPersonEntityMapper().map(result);
    if (person != null && result.movie_credits != null) {
        if (!PhilmCollections.isEmpty(result.movie_credits.cast)) {
            List<PhilmPersonCredit> credits = new ArrayList<>();
            for (PersonCastCredit credit : result.movie_credits.cast) {
                credits.add(new PhilmPersonCredit(credit));
            }
            Collections.sort(credits, PhilmPersonCredit.COMPARATOR_SORT_DATE);
            person.setCastCredits(credits);
        }
        if (!PhilmCollections.isEmpty(result.movie_credits.crew)) {
            List<PhilmPersonCredit> credits = new ArrayList<>();
            for (PersonCrewCredit credit : result.movie_credits.crew) {
                credits.add(new PhilmPersonCredit(credit));
            }
            Collections.sort(credits, PhilmPersonCredit.COMPARATOR_SORT_DATE);
            person.setCrewCredits(credits);
        }
        person.setFetchedCredits(true);
        getEventBus().post(new MoviesState.PersonChangedEvent(getCallingId(), person));
    }
}
Also used : PersonCastCredit(com.uwetrottmann.tmdb.entities.PersonCastCredit) PersonCrewCredit(com.uwetrottmann.tmdb.entities.PersonCrewCredit) ArrayList(java.util.ArrayList) PhilmPerson(app.philm.in.model.PhilmPerson) PhilmPersonCredit(app.philm.in.model.PhilmPersonCredit) MoviesState(app.philm.in.state.MoviesState)

Example 3 with PhilmPersonCredit

use of app.philm.in.model.PhilmPersonCredit in project philm by chrisbanes.

the class PersonCreditSectionedListAdapter method bindView.

@Override
protected void bindView(int position, View view, ListItem<PhilmPersonCredit> item) {
    PhilmPersonCredit credit = item.getListItem();
    final TextView nameTextView = (TextView) view.findViewById(R.id.textview_title);
    nameTextView.setText(credit.getTitle());
    final TextView characterTextView = (TextView) view.findViewById(R.id.textview_subtitle_1);
    if (TextUtils.isEmpty(credit.getJob())) {
        characterTextView.setVisibility(View.GONE);
    } else {
        characterTextView.setVisibility(View.VISIBLE);
        characterTextView.setText(credit.getJob());
    }
    final TextView release = (TextView) view.findViewById(R.id.textview_subtitle_2);
    mDate.setTime(credit.getReleaseDate());
    release.setText(mActivity.getString(R.string.movie_release_date, mMediumDateFormatter.format(mDate)));
    final PhilmImageView imageView = (PhilmImageView) view.findViewById(R.id.imageview_poster);
    imageView.loadPoster(credit);
}
Also used : TextView(android.widget.TextView) PhilmPersonCredit(app.philm.in.model.PhilmPersonCredit) PhilmImageView(app.philm.in.view.PhilmImageView)

Example 4 with PhilmPersonCredit

use of app.philm.in.model.PhilmPersonCredit in project philm by chrisbanes.

the class MovieController method createUiCallbacks.

@Override
protected MovieUiCallbacks createUiCallbacks(final MovieUi ui) {
    return new MovieUiCallbacks() {

        @Override
        public void updateColorScheme(ColorScheme colorScheme) {
            // First make sure that the color scheme is recorded
            recordColorSchemeFromUi(ui, colorScheme);
            Display display = getDisplay();
            if (display != null) {
                display.setColorScheme(colorScheme);
            }
            updateDisplayTitle(ui);
            ui.setColorScheme(colorScheme);
        }

        @Override
        public void addFilter(MovieFilter filter) {
            if (mMoviesState.getFilters().add(filter)) {
                removeMutuallyExclusiveFilters(filter);
                populateUi(ui);
            }
        }

        @Override
        public void removeFilter(MovieFilter filter) {
            if (mMoviesState.getFilters().remove(filter)) {
                populateUi(ui);
            }
        }

        @Override
        public void clearFilters() {
            if (!mMoviesState.getFilters().isEmpty()) {
                mMoviesState.getFilters().clear();
                populateUi(ui);
            }
        }

        @Override
        public void refresh() {
            switch(ui.getMovieQueryType()) {
                case TRENDING:
                    fetchTrending(getId(ui));
                    break;
                case LIBRARY:
                    fetchLibrary(getId(ui));
                    break;
                case WATCHLIST:
                    fetchWatchlist(getId(ui));
                    break;
                case MOVIE_DETAIL:
                    fetchDetailMovie(getId(ui), ui.getRequestParameter());
                    break;
                case POPULAR:
                    fetchPopular(getId(ui));
                    break;
                case RECOMMENDED:
                    fetchRecommended(getId(ui));
                    break;
                case UPCOMING:
                    fetchUpcoming(getId(ui));
                    break;
                case NOW_PLAYING:
                    fetchNowPlaying(getId(ui));
                    break;
            }
        }

        @Override
        public void showMovieDetail(PhilmMovie movie, Bundle bundle) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            Display display = getDisplay();
            if (display != null) {
                if (!TextUtils.isEmpty(movie.getTraktId())) {
                    display.startMovieDetailActivity(movie.getTraktId(), bundle);
                }
            // TODO: Handle the else case
            }
        }

        @Override
        public void showMovieDetail(PhilmPersonCredit credit, Bundle bundle) {
            Preconditions.checkNotNull(credit, "credit cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.startMovieDetailActivity(String.valueOf(credit.getId()), bundle);
            }
        }

        @Override
        public void toggleMovieSeen(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            if (movie.isWatched()) {
                markMoviesUnseen(getId(ui), movie.getTraktId());
            } else {
                markMoviesSeen(getId(ui), movie.getTraktId());
            }
        }

        @Override
        public void toggleInWatchlist(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            if (movie.inWatchlist()) {
                removeFromWatchlist(getId(ui), movie.getTraktId());
            } else {
                addToWatchlist(getId(ui), movie.getTraktId());
            }
        }

        @Override
        public void toggleInCollection(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            if (movie.inCollection()) {
                removeFromCollection(getId(ui), movie.getTraktId());
            } else {
                addToCollection(getId(ui), movie.getTraktId());
            }
        }

        @Override
        public void setMoviesInCollection(List<PhilmMovie> movies, boolean inCollection) {
            final ArrayList<String> ids = new ArrayList<>(movies.size());
            for (PhilmMovie movie : movies) {
                if (inCollection != movie.inCollection()) {
                    ids.add(movie.getTraktId());
                }
            }
            final String[] idsArray = new String[ids.size()];
            if (inCollection) {
                addToCollection(getId(ui), ids.toArray(idsArray));
            } else {
                removeFromCollection(getId(ui), ids.toArray(idsArray));
            }
        }

        @Override
        public void setMoviesInWatchlist(List<PhilmMovie> movies, boolean inWatchlist) {
            final ArrayList<String> ids = new ArrayList<>(movies.size());
            for (PhilmMovie movie : movies) {
                if (inWatchlist != movie.inWatchlist()) {
                    ids.add(movie.getTraktId());
                }
            }
            final String[] idsArray = new String[ids.size()];
            if (inWatchlist) {
                addToWatchlist(getId(ui), ids.toArray(idsArray));
            } else {
                removeFromWatchlist(getId(ui), ids.toArray(idsArray));
            }
        }

        @Override
        public void setMoviesSeen(List<PhilmMovie> movies, boolean seen) {
            final ArrayList<String> ids = new ArrayList<>(movies.size());
            for (PhilmMovie movie : movies) {
                if (seen != movie.isWatched()) {
                    ids.add(movie.getTraktId());
                }
            }
            final String[] idsArray = new String[ids.size()];
            if (seen) {
                markMoviesSeen(getId(ui), ids.toArray(idsArray));
            } else {
                markMoviesUnseen(getId(ui), ids.toArray(idsArray));
            }
        }

        @Override
        public void search(String query) {
            switch(ui.getMovieQueryType()) {
                case SEARCH:
                    fetchSearchResults(getId(ui), query);
                    break;
                case SEARCH_MOVIES:
                    fetchMovieSearchResults(getId(ui), query);
                    break;
                case SEARCH_PEOPLE:
                    fetchPeopleSearchResults(getId(ui), query);
                    break;
            }
        }

        @Override
        public void clearSearch() {
            mMoviesState.setSearchResult(null);
        }

        @Override
        public void showRateMovie(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.showRateMovieFragment(movie.getTraktId());
            }
        }

        @Override
        public void submitRating(PhilmMovie movie, Rating rating) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            markMovieRating(getId(ui), movie.getTraktId(), rating);
        }

        @Override
        public void onScrolledToBottom() {
            MoviesState.SearchResult searchResult;
            MoviesState.MoviePaginatedResult result;
            switch(ui.getMovieQueryType()) {
                case POPULAR:
                    result = mMoviesState.getPopular();
                    if (canFetchNextPage(result)) {
                        fetchPopular(getId(ui), result.page + 1);
                    }
                    break;
                case SEARCH_PEOPLE:
                    searchResult = mMoviesState.getSearchResult();
                    if (searchResult != null && canFetchNextPage(searchResult.people)) {
                        fetchPeopleSearchResults(getId(ui), searchResult.query, searchResult.people.page + 1);
                    }
                    break;
                case SEARCH_MOVIES:
                    searchResult = mMoviesState.getSearchResult();
                    if (searchResult != null && canFetchNextPage(searchResult.movies)) {
                        fetchMovieSearchResults(getId(ui), searchResult.query, searchResult.movies.page + 1);
                    }
                    break;
                case UPCOMING:
                    result = mMoviesState.getUpcoming();
                    if (canFetchNextPage(result)) {
                        fetchUpcoming(getId(ui), result.page + 1);
                    }
                    break;
            }
        }

        @Override
        public void showRelatedMovies(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.showRelatedMovies(String.valueOf(movie.getTmdbId()));
            }
        }

        @Override
        public void showCastList(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.showCastList(String.valueOf(movie.getTmdbId()));
            }
        }

        @Override
        public void showCrewList(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.showCrewList(String.valueOf(movie.getTmdbId()));
            }
        }

        @Override
        public void checkin(PhilmMovie movie, String message, boolean shareFacebook, boolean shareTwitter, boolean sharePath, boolean shareTumblr) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            checkinMovie(getId(ui), movie, message, shareFacebook, shareTwitter, sharePath, shareTumblr);
        }

        @Override
        public void cancelCurrentCheckin() {
            cancelCheckin(getId(ui));
        }

        @Override
        public void requestCheckin(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.showCheckin(movie.getTraktId());
            }
        }

        @Override
        public void requestCancelCurrentCheckin() {
            Display display = getDisplay();
            if (display != null) {
                display.showCancelCheckin();
            }
        }

        @Override
        public void showPersonDetail(PhilmPerson person, Bundle bundle) {
            Preconditions.checkNotNull(person, "person cannot be null");
            Preconditions.checkNotNull(person.getTmdbId(), "person id cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.startPersonDetailActivity(String.valueOf(person.getTmdbId()), bundle);
            }
        }

        @Override
        public void showPersonCastCredits(PhilmPerson person) {
            Preconditions.checkNotNull(person, "person cannot be null");
            Preconditions.checkNotNull(person.getTmdbId(), "person id cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.showPersonCastCredits(String.valueOf(person.getTmdbId()));
            }
        }

        @Override
        public void showPersonCrewCredits(PhilmPerson person) {
            Preconditions.checkNotNull(person, "person cannot be null");
            Preconditions.checkNotNull(person.getTmdbId(), "person id cannot be null");
            Display display = getDisplay();
            if (display != null) {
                display.showPersonCrewCredits(String.valueOf(person.getTmdbId()));
            }
        }

        @Override
        public void showMovieSearchResults() {
            Display display = getDisplay();
            if (display != null) {
                display.showSearchMoviesFragment();
            }
        }

        @Override
        public void showPeopleSearchResults() {
            Display display = getDisplay();
            if (display != null) {
                display.showSearchPeopleFragment();
            }
        }

        @Override
        public void playTrailer(PhilmMovieVideo trailer) {
            Preconditions.checkNotNull(trailer, "trailer cannot be null");
            Preconditions.checkNotNull(trailer.getId(), "trailer id cannot be null");
            final Display display = getDisplay();
            if (display != null) {
                switch(trailer.getSource()) {
                    case YOUTUBE:
                        display.playYoutubeVideo(trailer.getId());
                        break;
                }
            }
        }

        @Override
        public void showMovieImages(PhilmMovie movie) {
            Preconditions.checkNotNull(movie, "movie cannot be null");
            final Display display = getDisplay();
            if (display != null) {
                display.startMovieImagesActivity(String.valueOf(movie.getTmdbId()));
            }
        }

        @Override
        public String getUiTitle() {
            return MovieController.this.getUiTitle(ui);
        }

        @Override
        public void setHeaderScrollValue(float scrollPercentage) {
            Display display = getDisplay();
            if (display != null) {
                getDisplay().setStatusBarColor(scrollPercentage);
            }
        }

        private boolean canFetchNextPage(MoviesState.PaginatedResult<?> paginatedResult) {
            return paginatedResult != null && paginatedResult.page < paginatedResult.totalPages;
        }
    };
}
Also used : PhilmMovieVideo(app.philm.in.model.PhilmMovieVideo) Bundle(android.os.Bundle) Rating(com.jakewharton.trakt.enumerations.Rating) ColorScheme(app.philm.in.model.ColorScheme) ArrayList(java.util.ArrayList) PhilmPerson(app.philm.in.model.PhilmPerson) MoviesState(app.philm.in.state.MoviesState) PhilmMovie(app.philm.in.model.PhilmMovie) List(java.util.List) ArrayList(java.util.ArrayList) PhilmPersonCredit(app.philm.in.model.PhilmPersonCredit) Display(app.philm.in.Display)

Aggregations

PhilmPersonCredit (app.philm.in.model.PhilmPersonCredit)4 PhilmPerson (app.philm.in.model.PhilmPerson)3 MoviesState (app.philm.in.state.MoviesState)3 ArrayList (java.util.ArrayList)3 PersonCastCredit (com.uwetrottmann.tmdb.entities.PersonCastCredit)2 PersonCrewCredit (com.uwetrottmann.tmdb.entities.PersonCrewCredit)2 Bundle (android.os.Bundle)1 TextView (android.widget.TextView)1 Display (app.philm.in.Display)1 ColorScheme (app.philm.in.model.ColorScheme)1 PhilmMovie (app.philm.in.model.PhilmMovie)1 PhilmMovieVideo (app.philm.in.model.PhilmMovieVideo)1 PhilmImageView (app.philm.in.view.PhilmImageView)1 Rating (com.jakewharton.trakt.enumerations.Rating)1 List (java.util.List)1