Search in sources :

Example 26 with PhilmMovie

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

the class TraktMovieEntityMapper method map.

@Override
public PhilmMovie map(Movie entity) {
    PhilmMovie movie = getEntity(entity.imdb_id);
    if (movie == null && entity.tmdbId != 0) {
        movie = getEntity(String.valueOf(entity.tmdbId));
    }
    if (movie == null) {
        // No movie, so create one
        movie = new PhilmMovie();
    }
    // We already have a movie, so just update it wrapped value
    movie.setFromMovie(entity);
    putEntity(movie);
    return movie;
}
Also used : PhilmMovie(app.philm.in.model.PhilmMovie)

Example 27 with PhilmMovie

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

the class FetchTmdbMoviesReleasesRunnable method onSuccess.

@Override
public void onSuccess(Releases result) {
    final String countryCode = mCountryProvider.getTwoLetterCountryCode();
    PhilmMovie movie = mMoviesState.getMovie(mId);
    if (movie != null) {
        movie.updateWithReleases(result, countryCode);
        getDbHelper().put(movie);
        getEventBus().post(new MoviesState.MovieReleasesUpdatedEvent(getCallingId(), movie));
    }
}
Also used : PhilmMovie(app.philm.in.model.PhilmMovie) MoviesState(app.philm.in.state.MoviesState)

Example 28 with PhilmMovie

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

the class FetchTmdbRelatedMoviesRunnable method onSuccess.

@Override
public void onSuccess(MovieResultsPage result) {
    PhilmMovie movie = mMoviesState.getMovie(String.valueOf(mId));
    if (movie != null) {
        movie.setRelated(getTmdbMovieEntityMapper().mapAll(result.results));
        getEventBus().post(new MoviesState.MovieRelatedItemsUpdatedEvent(getCallingId(), movie));
    }
}
Also used : PhilmMovie(app.philm.in.model.PhilmMovie) MoviesState(app.philm.in.state.MoviesState)

Example 29 with PhilmMovie

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

the class SubmitTraktMovieRatingRunnable method onSuccess.

@Override
public void onSuccess(RatingResponse result) {
    if (RESULT_TRAKT_SUCCESS.equals(result.status)) {
        PhilmMovie movie = mMoviesState.getMovie(mId);
        if (movie != null) {
            if (result.rating != null) {
                movie.setUserRatingAdvanced(result.rating);
            } else {
                movie.setUserRatingAdvanced(mRating);
            }
            getDbHelper().put(movie);
            getEventBus().post(new MoviesState.MovieUserRatingChangedEvent(getCallingId(), movie));
        }
    }
}
Also used : PhilmMovie(app.philm.in.model.PhilmMovie) MoviesState(app.philm.in.state.MoviesState)

Example 30 with PhilmMovie

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

PhilmMovie (app.philm.in.model.PhilmMovie)39 MoviesState (app.philm.in.state.MoviesState)17 ArrayList (java.util.ArrayList)4 TextView (android.widget.TextView)2 WatchingMovie (app.philm.in.model.WatchingMovie)2 PhilmImageView (app.philm.in.view.PhilmImageView)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Bitmap (android.graphics.Bitmap)1 Bundle (android.os.Bundle)1 View (android.view.View)1 Display (app.philm.in.Display)1 ColorScheme (app.philm.in.model.ColorScheme)1 PhilmMovieCredit (app.philm.in.model.PhilmMovieCredit)1 PhilmMovieVideo (app.philm.in.model.PhilmMovieVideo)1 PhilmPerson (app.philm.in.model.PhilmPerson)1 PhilmPersonCredit (app.philm.in.model.PhilmPersonCredit)1 PhilmUserProfile (app.philm.in.model.PhilmUserProfile)1 FetchTmdbDetailMovieRunnable (app.philm.in.tasks.FetchTmdbDetailMovieRunnable)1 FetchTmdbMovieImagesRunnable (app.philm.in.tasks.FetchTmdbMovieImagesRunnable)1 FetchTraktDetailMovieRunnable (app.philm.in.tasks.FetchTraktDetailMovieRunnable)1