Search in sources :

Example 6 with Movie

use of org.javaee7.movieplex7.entities.Movie in project SeriesGuide by UweTrottmann.

the class TmdbMoviesLoader method loadInBackground.

@Override
public Result loadInBackground() {
    String languageCode = DisplaySettings.getMoviesLanguage(getContext());
    String regionCode = DisplaySettings.getMoviesRegion(getContext());
    List<Movie> results = null;
    String action = null;
    try {
        Response<MovieResultsPage> response;
        if (TextUtils.isEmpty(query)) {
            MoviesService moviesService = this.moviesService.get();
            Call<MovieResultsPage> call;
            switch(link) {
                case POPULAR:
                    action = "get popular movies";
                    call = moviesService.popular(null, languageCode);
                    break;
                case DIGITAL:
                    action = "get movie digital releases";
                    call = tmdb.get().discoverMovie().with_release_type(new DiscoverFilter(DiscoverFilter.Separator.AND, ReleaseType.DIGITAL)).release_date_lte(getDateNow()).release_date_gte(getDateOneMonthAgo()).language(languageCode).region(regionCode).build();
                    break;
                case DISC:
                    action = "get movie disc releases";
                    call = tmdb.get().discoverMovie().with_release_type(new DiscoverFilter(DiscoverFilter.Separator.AND, ReleaseType.PHYSICAL)).release_date_lte(getDateNow()).release_date_gte(getDateOneMonthAgo()).language(languageCode).region(regionCode).build();
                    break;
                case IN_THEATERS:
                default:
                    action = "get now playing movies";
                    call = tmdb.get().discoverMovie().with_release_type(new DiscoverFilter(DiscoverFilter.Separator.OR, ReleaseType.THEATRICAL, ReleaseType.THEATRICAL_LIMITED)).release_date_lte(getDateNow()).release_date_gte(getDateOneMonthAgo()).language(languageCode).region(regionCode).build();
                    break;
            }
            response = call.execute();
        } else {
            action = "search for movies";
            response = searchService.get().movie(query, null, languageCode, false, null, null, null).execute();
        }
        if (response.isSuccessful()) {
            MovieResultsPage page = response.body();
            if (page != null) {
                results = page.results;
            }
        } else {
            SgTmdb.trackFailedRequest(getContext(), action, response);
            return buildErrorResult();
        }
    } catch (IOException e) {
        SgTmdb.trackFailedRequest(getContext(), action, e);
        // only check for connection here to allow hitting the response cache
        return AndroidUtils.isNetworkConnected(getContext()) ? buildErrorResult() : new Result(null, getContext().getString(R.string.offline));
    }
    return new Result(results, getContext().getString(R.string.no_results));
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) DiscoverFilter(com.uwetrottmann.tmdb2.entities.DiscoverFilter) MovieResultsPage(com.uwetrottmann.tmdb2.entities.MovieResultsPage) IOException(java.io.IOException) MoviesService(com.uwetrottmann.tmdb2.services.MoviesService)

Example 7 with Movie

use of org.javaee7.movieplex7.entities.Movie in project SeriesGuide by UweTrottmann.

the class MovieDetailsFragment method populateMovieViews.

private void populateMovieViews() {
    /**
         * Get everything from TMDb. Also get additional rating from trakt.
         */
    final Ratings traktRatings = movieDetails.traktRatings();
    final Movie tmdbMovie = movieDetails.tmdbMovie();
    final boolean inCollection = movieDetails.inCollection;
    final boolean inWatchlist = movieDetails.inWatchlist;
    final boolean isWatched = movieDetails.isWatched;
    final int rating = movieDetails.userRating;
    textViewMovieTitle.setText(tmdbMovie.title);
    getActivity().setTitle(tmdbMovie.title);
    textViewMovieDescription.setText(tmdbMovie.overview);
    // release date and runtime: "July 17, 2009 | 95 min"
    StringBuilder releaseAndRuntime = new StringBuilder();
    if (tmdbMovie.release_date != null) {
        releaseAndRuntime.append(TimeTools.formatToLocalDate(getContext(), tmdbMovie.release_date));
        releaseAndRuntime.append(" | ");
    }
    releaseAndRuntime.append(getString(R.string.runtime_minutes, String.valueOf(tmdbMovie.runtime)));
    textViewMovieDate.setText(releaseAndRuntime.toString());
    // check-in button
    final String title = tmdbMovie.title;
    buttonMovieCheckIn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // display a check-in dialog
            MovieCheckInDialogFragment f = MovieCheckInDialogFragment.newInstance(tmdbId, title);
            f.show(getFragmentManager(), "checkin-dialog");
            Utils.trackAction(getActivity(), TAG, "Check-In");
        }
    });
    CheatSheet.setup(buttonMovieCheckIn);
    // hide check-in if not connected to trakt or hexagon is enabled
    boolean isConnectedToTrakt = TraktCredentials.get(getActivity()).hasCredentials();
    boolean displayCheckIn = isConnectedToTrakt && !HexagonSettings.isEnabled(getActivity());
    buttonMovieCheckIn.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    dividerMovieButtons.setVisibility(displayCheckIn ? View.VISIBLE : View.GONE);
    // watched button (only supported when connected to trakt)
    if (isConnectedToTrakt) {
        buttonMovieWatched.setText(isWatched ? R.string.action_unwatched : R.string.action_watched);
        CheatSheet.setup(buttonMovieWatched, isWatched ? R.string.action_unwatched : R.string.action_watched);
        Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonMovieWatched, 0, isWatched ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatched) : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatch), 0, 0);
        buttonMovieWatched.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isWatched) {
                    MovieTools.unwatchedMovie(SgApp.from(getActivity()), tmdbId);
                    Utils.trackAction(getActivity(), TAG, "Unwatched movie");
                } else {
                    MovieTools.watchedMovie(SgApp.from(getActivity()), tmdbId);
                    Utils.trackAction(getActivity(), TAG, "Watched movie");
                }
            }
        });
        buttonMovieWatched.setVisibility(View.VISIBLE);
    } else {
        buttonMovieWatched.setVisibility(View.GONE);
    }
    // collected button
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonMovieCollected, 0, inCollection ? R.drawable.ic_collected : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollect), 0, 0);
    buttonMovieCollected.setText(inCollection ? R.string.action_collection_remove : R.string.action_collection_add);
    CheatSheet.setup(buttonMovieCollected, inCollection ? R.string.action_collection_remove : R.string.action_collection_add);
    buttonMovieCollected.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (inCollection) {
                MovieTools.removeFromCollection(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Uncollected movie");
            } else {
                MovieTools.addToCollection(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Collected movie");
            }
        }
    });
    // watchlist button
    Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(buttonMovieWatchlisted, 0, inWatchlist ? R.drawable.ic_listed : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableList), 0, 0);
    buttonMovieWatchlisted.setText(inWatchlist ? R.string.watchlist_remove : R.string.watchlist_add);
    CheatSheet.setup(buttonMovieWatchlisted, inWatchlist ? R.string.watchlist_remove : R.string.watchlist_add);
    buttonMovieWatchlisted.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (inWatchlist) {
                MovieTools.removeFromWatchlist(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Unwatchlist movie");
            } else {
                MovieTools.addToWatchlist(SgApp.from(getActivity()), tmdbId);
                Utils.trackAction(getActivity(), TAG, "Watchlist movie");
            }
        }
    });
    // show button bar
    containerMovieButtons.setVisibility(View.VISIBLE);
    // language button
    LanguageTools.LanguageData languageData = LanguageTools.getMovieLanguageData(getContext());
    if (languageData != null) {
        currentLanguageIndex = languageData.languageIndex;
        buttonMovieLanguage.setText(languageData.languageString);
    } else {
        buttonMovieLanguage.setText(null);
    }
    buttonMovieLanguage.setVisibility(View.VISIBLE);
    // ratings
    textViewRatingsTmdbValue.setText(TraktTools.buildRatingString(tmdbMovie.vote_average));
    textViewRatingsTmdbVotes.setText(TraktTools.buildRatingVotesString(getActivity(), tmdbMovie.vote_count));
    if (traktRatings != null) {
        textViewRatingsTraktVotes.setText(TraktTools.buildRatingVotesString(getActivity(), traktRatings.votes));
        textViewRatingsTraktValue.setText(TraktTools.buildRatingString(traktRatings.rating));
    }
    // if movie is not in database, can't handle user ratings
    if (!inCollection && !inWatchlist && !isWatched) {
        textViewRatingsTraktUserLabel.setVisibility(View.GONE);
        textViewRatingsTraktUser.setVisibility(View.GONE);
        containerRatings.setClickable(false);
        // cheat sheet
        containerRatings.setLongClickable(false);
    } else {
        textViewRatingsTraktUserLabel.setVisibility(View.VISIBLE);
        textViewRatingsTraktUser.setVisibility(View.VISIBLE);
        textViewRatingsTraktUser.setText(TraktTools.buildUserRatingString(getActivity(), rating));
        containerRatings.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                rateMovie();
            }
        });
        CheatSheet.setup(containerRatings, R.string.action_rate);
    }
    containerRatings.setVisibility(View.VISIBLE);
    // genres
    textViewMovieGenresLabel.setVisibility(View.VISIBLE);
    Utils.setValueOrPlaceholder(textViewMovieGenres, TmdbTools.buildGenresString(tmdbMovie.genres));
    // trakt comments link
    buttonMovieComments.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), TraktCommentsActivity.class);
            i.putExtras(TraktCommentsActivity.createInitBundleMovie(title, tmdbId));
            Utils.startActivityWithAnimation(getActivity(), i, v);
            Utils.trackAction(v.getContext(), TAG, "Comments");
        }
    });
    buttonMovieComments.setVisibility(View.VISIBLE);
    // load poster, cache on external storage
    if (TextUtils.isEmpty(tmdbMovie.poster_path)) {
        frameLayoutMoviePoster.setClickable(false);
        frameLayoutMoviePoster.setFocusable(false);
    } else {
        final String smallImageUrl = TmdbSettings.getImageBaseUrl(getActivity()) + TmdbSettings.POSTER_SIZE_SPEC_W342 + tmdbMovie.poster_path;
        ServiceUtils.loadWithPicasso(getActivity(), smallImageUrl).into(imageViewMoviePoster, new Callback.EmptyCallback() {

            @Override
            public void onSuccess() {
                Bitmap bitmap = ((BitmapDrawable) imageViewMoviePoster.getDrawable()).getBitmap();
                paletteAsyncTask = Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {

                    @Override
                    public void onGenerated(Palette palette) {
                        int color = palette.getVibrantColor(Color.WHITE);
                        color = ColorUtils.setAlphaComponent(color, 50);
                        rootLayoutMovie.setBackgroundColor(color);
                    }
                });
            }
        });
        // click listener for high resolution poster
        frameLayoutMoviePoster.setFocusable(true);
        frameLayoutMoviePoster.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                String largeImageUrl = TmdbSettings.getImageBaseUrl(getActivity()) + TmdbSettings.POSTER_SIZE_SPEC_ORIGINAL + tmdbMovie.poster_path;
                Intent intent = new Intent(getActivity(), FullscreenImageActivity.class);
                intent.putExtra(FullscreenImageActivity.EXTRA_PREVIEW_IMAGE, smallImageUrl);
                intent.putExtra(FullscreenImageActivity.EXTRA_IMAGE, largeImageUrl);
                Utils.startActivityWithAnimation(getActivity(), intent, view);
            }
        });
    }
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) Palette(android.support.v7.graphics.Palette) MovieCheckInDialogFragment(com.battlelancer.seriesguide.ui.dialogs.MovieCheckInDialogFragment) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView) LanguageTools(com.battlelancer.seriesguide.util.LanguageTools) Ratings(com.uwetrottmann.trakt5.entities.Ratings) Bitmap(android.graphics.Bitmap) Callback(com.squareup.picasso.Callback) OnClickListener(android.view.View.OnClickListener)

Example 8 with Movie

use of org.javaee7.movieplex7.entities.Movie in project SeriesGuide by UweTrottmann.

the class MovieTools method loadSummaryFromTmdb.

@Nullable
private com.uwetrottmann.tmdb2.entities.Movie loadSummaryFromTmdb(String languageCode, int movieTmdbId) {
    // try to get local movie summary
    Movie movie = getMovieSummary("get local movie summary", languageCode, movieTmdbId);
    if (movie != null && !TextUtils.isEmpty(movie.overview)) {
        return movie;
    }
    // fall back to default language if TMDb has no localized text
    movie = getMovieSummary("get default movie summary", null, movieTmdbId);
    if (movie != null) {
        // add note about non-translated or non-existing overview
        String untranslatedOverview = movie.overview;
        movie.overview = context.getString(R.string.no_translation, LanguageTools.getMovieLanguageStringFor(context, languageCode), context.getString(R.string.tmdb));
        if (!TextUtils.isEmpty(untranslatedOverview)) {
            movie.overview += "\n\n" + untranslatedOverview;
        }
    }
    return movie;
}
Also used : Movie(com.uwetrottmann.tmdb2.entities.Movie) BaseMovie(com.uwetrottmann.trakt5.entities.BaseMovie) SyncMovie(com.uwetrottmann.trakt5.entities.SyncMovie) Nullable(android.support.annotation.Nullable)

Aggregations

Movie (com.uwetrottmann.tmdb2.entities.Movie)5 Ratings (com.uwetrottmann.trakt5.entities.Ratings)2 SyncMovie (com.uwetrottmann.trakt5.entities.SyncMovie)2 Movie (org.javaee7.movieplex7.entities.Movie)2 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Nullable (android.support.annotation.Nullable)1 NestedScrollView (android.support.v4.widget.NestedScrollView)1 Palette (android.support.v7.graphics.Palette)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 MovieDetails (com.battlelancer.seriesguide.items.MovieDetails)1 MovieCheckInDialogFragment (com.battlelancer.seriesguide.ui.dialogs.MovieCheckInDialogFragment)1 LanguageTools (com.battlelancer.seriesguide.util.LanguageTools)1 Callback (com.squareup.picasso.Callback)1 DiscoverFilter (com.uwetrottmann.tmdb2.entities.DiscoverFilter)1