Search in sources :

Example 1 with ColorScheme

use of app.philm.in.model.ColorScheme 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

Bundle (android.os.Bundle)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 PhilmPerson (app.philm.in.model.PhilmPerson)1 PhilmPersonCredit (app.philm.in.model.PhilmPersonCredit)1 MoviesState (app.philm.in.state.MoviesState)1 Rating (com.jakewharton.trakt.enumerations.Rating)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1