Search in sources :

Example 1 with Display

use of app.philm.in.Display in project philm by chrisbanes.

the class UserController method onNetworkError.

@Subscribe
public void onNetworkError(BaseState.OnErrorEvent event) {
    if (event.error == NetworkError.UNAUTHORIZED_TRAKT && mUserState.getCurrentAccount() != null) {
        mPhilmAccountManager.removeAccount(mUserState.getCurrentAccount());
        mUserState.setCurrentAccount(null);
        Display display = getDisplay();
        if (display != null) {
            display.showCredentialsChanged();
        }
    }
}
Also used : Display(app.philm.in.Display) Subscribe(com.squareup.otto.Subscribe)

Example 2 with Display

use of app.philm.in.Display in project philm by chrisbanes.

the class MainController method createUiCallbacks.

@Override
protected MainControllerUiCallbacks createUiCallbacks(final MainControllerUi ui) {
    return new MainControllerUiCallbacks() {

        @Override
        public void onSideMenuItemSelected(SideMenuItem item) {
            Display display = getDisplay();
            if (display != null) {
                showUiItem(display, item);
                display.closeDrawerLayout();
            }
        }

        @Override
        public void addAccountRequested() {
            Display display = getDisplay();
            if (display != null) {
                display.startAddAccountActivity();
                display.closeDrawerLayout();
            }
        }

        @Override
        public void showMovieCheckin() {
            Display display = getDisplay();
            WatchingMovie checkin = mState.getWatchingMovie();
            if (display != null && checkin != null) {
                display.closeDrawerLayout();
                display.startMovieDetailActivity(checkin.movie.getImdbId(), null);
            }
        }

        @Override
        public void setShownLoginPrompt() {
            mPreferences.setShownTraktLoginPrompt();
        }
    };
}
Also used : WatchingMovie(app.philm.in.model.WatchingMovie) Display(app.philm.in.Display)

Example 3 with Display

use of app.philm.in.Display 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)

Example 4 with Display

use of app.philm.in.Display in project philm by chrisbanes.

the class MovieController method onUiAttached.

@Override
protected void onUiAttached(final MovieUi ui) {
    final MovieQueryType queryType = ui.getMovieQueryType();
    if (queryType.requireLogin() && !isLoggedIn()) {
        return;
    }
    String title = null;
    String subtitle = null;
    final int callingId = getId(ui);
    switch(queryType) {
        case TRENDING:
            fetchTrendingIfNeeded(callingId);
            break;
        case POPULAR:
            fetchPopularIfNeeded(callingId);
            break;
        case LIBRARY:
            fetchLibraryIfNeeded(callingId);
            break;
        case WATCHLIST:
            fetchWatchlistIfNeeded(callingId);
            break;
        case MOVIE_DETAIL:
            fetchDetailMovieIfNeeded(callingId, ui.getRequestParameter());
            break;
        case NOW_PLAYING:
            fetchNowPlayingIfNeeded(callingId);
            break;
        case UPCOMING:
            fetchUpcomingIfNeeded(callingId);
            break;
        case RECOMMENDED:
            fetchRecommendedIfNeeded(callingId);
            break;
        case MOVIE_RELATED:
            fetchRelatedIfNeeded(callingId, ui.getRequestParameter());
            subtitle = mStringFetcher.getString(R.string.related_movies);
            break;
        case MOVIE_CAST:
            fetchMovieCastIfNeeded(callingId, ui.getRequestParameter());
            subtitle = mStringFetcher.getString(R.string.cast_movies);
            break;
        case MOVIE_CREW:
            fetchMovieCrewIfNeeded(callingId, ui.getRequestParameter());
            subtitle = mStringFetcher.getString(R.string.crew_movies);
            break;
        case MOVIE_IMAGES:
            fetchMovieImagesIfNeeded(callingId, ui.getRequestParameter());
            subtitle = mStringFetcher.getString(R.string.images_movies);
            break;
        case PERSON_DETAIL:
            fetchPersonIfNeeded(callingId, ui.getRequestParameter());
            break;
        case PERSON_CREDITS_CREW:
            fetchPersonCreditsIfNeeded(callingId, ui.getRequestParameter());
            subtitle = mStringFetcher.getString(R.string.crew_movies);
            break;
        case PERSON_CREDITS_CAST:
            fetchPersonCreditsIfNeeded(callingId, ui.getRequestParameter());
            subtitle = mStringFetcher.getString(R.string.cast_movies);
            break;
        case SEARCH_PEOPLE:
            subtitle = mStringFetcher.getString(R.string.category_people);
            break;
        case SEARCH_MOVIES:
            subtitle = mStringFetcher.getString(R.string.category_movies);
            break;
    }
    final Display display = getDisplay();
    if (display != null) {
        if (!ui.isModal()) {
            display.showUpNavigation(queryType != null && queryType.showUpNavigation());
            display.setColorScheme(getColorSchemeForUi(ui));
        }
        display.setActionBarSubtitle(subtitle);
    }
}
Also used : Display(app.philm.in.Display)

Aggregations

Display (app.philm.in.Display)4 Bundle (android.os.Bundle)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 WatchingMovie (app.philm.in.model.WatchingMovie)1 MoviesState (app.philm.in.state.MoviesState)1 Rating (com.jakewharton.trakt.enumerations.Rating)1 Subscribe (com.squareup.otto.Subscribe)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1