Android Open Source - UpcomingMoviesMVP Upcoming Movies Mapper






From Project

Back to project page UpcomingMoviesMVP.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Defi...

If you think the Android project UpcomingMoviesMVP listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jlmd.android.newfilmsmvp.api.mapper;
//from ww w . j a  va2s .co m
import com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.Result;
import com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.UpcomingMoviesResult;
import com.jlmd.android.newfilmsmvp.domain.model.Image;
import com.jlmd.android.newfilmsmvp.domain.model.Movie;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Map the api model of upcoming movies to domain model
 *
 * @author jlmd
 */
public class UpcomingMoviesMapper implements Mapper<UpcomingMoviesResult, List<Movie>> {

    private static final String IMAGE_URL = "http://image.tmdb.org/t/p/w";
    private static final String RELEASE_DATE_FORMAT = "yyyy-MM-dd";
    private static final int POSTER_WIDTH_LOW = 185;
    private static final int POSTER_WIDTH_MEDIUM = 342;
    private static final int POSTER_WIDTH_HIGH = 500;
    private static final int BACKDROP_WIDTH_LOW = 300;
    private static final int BACKDROP_WIDTH_MEDIUM = 500;
    private static final int BACKDROP_WIDTH_HIGH = 780;

    @Override
    public List<Movie> map(UpcomingMoviesResult upcomingMoviesResult) {
        List<Movie> movies = new ArrayList<Movie>();
        for (Result result : upcomingMoviesResult.getResults()) {
            movies.add(mapMovie(result));
        }
        return movies;
    }

    private Movie mapMovie(Result result) {
        Movie movie = new Movie();
        movie.setId(result.getId());
        movie.setTitle(result.getTitle());
        movie.setPosterImage(mapImage(result.getPosterPath(), POSTER_WIDTH_LOW,
                POSTER_WIDTH_MEDIUM, POSTER_WIDTH_HIGH));
        movie.setBackdropImage(mapImage((String) result.getBackdropPath(), BACKDROP_WIDTH_LOW,
                BACKDROP_WIDTH_MEDIUM, BACKDROP_WIDTH_HIGH));
        movie.setReleaseDate(parseReleaseDate(result.getReleaseDate()));
        movie.setAdult(result.getAdult());
        movie.setVoteAverage(result.getVoteAverage());
        movie.setVoteCount(result.getVoteCount());
        movie.setPopularity(result.getPopularity());
        movie.setOverview(result.getOverview());
        return movie;
    }

    private Image mapImage(String imageUrl, int sizeLow, int sizeMedium, int sizeHigh) {
        Image image = new Image();
        image.setLowResolutionImgUrl(createAbsoluteImgURL(imageUrl, sizeLow));
        image.setMediumResolutionImgUrl(createAbsoluteImgURL(imageUrl, sizeMedium));
        image.setHighResolutionImgUrl(createAbsoluteImgURL(imageUrl, sizeHigh));
        return image;
    }

    private Date parseReleaseDate(String date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(RELEASE_DATE_FORMAT);
        try {
            return simpleDateFormat.parse(date);
        } catch (ParseException e) {
            return new Date();
        }
    }

    private String createAbsoluteImgURL(String relativeImgURL, int width) {
        return IMAGE_URL + width + relativeImgURL;
    }
}




Java Source Code List

com.jlmd.android.newfilmsmvp.ApplicationTest.java
com.jlmd.android.newfilmsmvp.api.mapper.Mapper.java
com.jlmd.android.newfilmsmvp.api.mapper.MovieDetailsMapper.java
com.jlmd.android.newfilmsmvp.api.mapper.UpcomingMoviesMapper.java
com.jlmd.android.newfilmsmvp.api.mock.MockedMovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.mock.MockedUpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.moviedetails.MovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.BelongsToCollection.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.Genre.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.MovieDetailsResult.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.ProductionCompany.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.ProductionCountry.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.SpokenLanguage.java
com.jlmd.android.newfilmsmvp.api.retrofit.moviedetails.MovieDetailsService.java
com.jlmd.android.newfilmsmvp.api.retrofit.moviedetails.RetrofitMovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.retrofit.upcomingmovies.RetrofitUpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.retrofit.upcomingmovies.UpcomingMoviesService.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.UpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.Dates.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.Result.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.UpcomingMoviesResult.java
com.jlmd.android.newfilmsmvp.bus.event.MovieSelectedEvent.java
com.jlmd.android.newfilmsmvp.di.AppApplication.java
com.jlmd.android.newfilmsmvp.di.module.ComparatorModule.java
com.jlmd.android.newfilmsmvp.di.module.PresenterModule.java
com.jlmd.android.newfilmsmvp.di.module.RepositoryModule.java
com.jlmd.android.newfilmsmvp.di.module.RootModule.java
com.jlmd.android.newfilmsmvp.domain.comparator.MovieDateComparator.java
com.jlmd.android.newfilmsmvp.domain.comparator.MovieTitleComparator.java
com.jlmd.android.newfilmsmvp.domain.formatter.Formatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.GenresFormatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.RatingFormatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.ReleaseDateFormatter.java
com.jlmd.android.newfilmsmvp.domain.model.Image.java
com.jlmd.android.newfilmsmvp.domain.model.MovieDetails.java
com.jlmd.android.newfilmsmvp.domain.model.Movie.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MovieDetailsPresenterImp.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MovieDetailsPresenter.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MoviesListPresenterImp.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MoviesListPresenter.java
com.jlmd.android.newfilmsmvp.mvp.presenter.Presenter.java
com.jlmd.android.newfilmsmvp.mvp.view.MovieDetailsView.java
com.jlmd.android.newfilmsmvp.mvp.view.MoviesListView.java
com.jlmd.android.newfilmsmvp.mvp.view.View.java
com.jlmd.android.newfilmsmvp.ui.activity.BaseActivity.java
com.jlmd.android.newfilmsmvp.ui.activity.MainActivity.java
com.jlmd.android.newfilmsmvp.ui.activity.MovieDetailsActivity.java
com.jlmd.android.newfilmsmvp.ui.adapter.BaseRecyclerViewHolder.java
com.jlmd.android.newfilmsmvp.ui.adapter.MoviesListRecyclerAdapter.java
com.jlmd.android.newfilmsmvp.ui.fragment.BaseFragment.java
com.jlmd.android.newfilmsmvp.ui.fragment.MovieDetailsFragment.java
com.jlmd.android.newfilmsmvp.ui.fragment.MoviesListFragment.java
com.jlmd.android.newfilmsmvp.ui.view.ClickItemTouchListener.java
com.jlmd.android.newfilmsmvp.ui.view.ClickRecyclerView.java
com.jlmd.android.newfilmsmvp.utils.Constants.java
com.jlmd.android.newfilmsmvp.utils.Utils.java