Skip to content

Commit

Permalink
Merge branch 'refactor/ui-polishing' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ecarrara-araujo committed Sep 13, 2017
2 parents a10945c + 4530b7a commit d899f75
Show file tree
Hide file tree
Showing 52 changed files with 986 additions and 304 deletions.
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# By default, the flags in this file are appended to flags specified
# in /home/ecarrara/tools/android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
# directive in buildPosterUrl.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public class RestConfigs {

public static final String SERVER_URL = "https://api.themoviedb.org/3/";
public static final String SERVER_IMAGE_URL = "https://image.tmdb.org/t/p/";
public static final String IMAGE_SIZE = "w185";
public static final String IMAGE_SIZE_POSTER = "w185";
public static final String IMAGE_SIZE_BACKDROP = "w780";
public static final String API_DATE_FORMAT = "yyyy-MM-dd";

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

public class RestImageUrlBuilder {

public static String build(String imagePath) {
return RestConfigs.SERVER_IMAGE_URL +
RestConfigs.IMAGE_SIZE +
imagePath;
public static String buildBackdropUrl(String imagePath) {
return build(imagePath, RestConfigs.IMAGE_SIZE_BACKDROP);
}

public static String buildPosterUrl(String imagePath) {
return build(imagePath, RestConfigs.IMAGE_SIZE_POSTER);
}

private static String build(String imagePath, String imageSize) {
return RestConfigs.SERVER_IMAGE_URL + imageSize + imagePath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ private static Movie extractMovieFromCursor(@NonNull Cursor cursor) {
Double popularity = cursor.getDouble(cursor.getColumnIndex(FavoriteMovieEntry.COLUMN_POPULARITY));
Double voteAverage = cursor.getDouble(cursor.getColumnIndex(FavoriteMovieEntry.COLUMN_VOTE_AVERAGE));
String posterPath = cursor.getString(cursor.getColumnIndex(FavoriteMovieEntry.COLUMN_POSTER_PATH));
String backdropPath = cursor.getString(cursor.getColumnIndex(FavoriteMovieEntry.COLUMN_BACKDROP_PATH));
Date releaseDate = mapDateFromDatabaseString(cursor.getString(
cursor.getColumnIndex(FavoriteMovieEntry.COLUMN_RELEASE_DATE)));

return new Movie
.Builder(id, originalTitle)
return Movie.builder()
.setId(id)
.setOriginalTitle(originalTitle)
.setOverview(overview)
.setPopularity(popularity)
.setPosterPath(posterPath)
.setBackdropPath(backdropPath)
.setReleaseDate(releaseDate)
.setVoteAverage(voteAverage)
.build();
Expand Down Expand Up @@ -90,6 +93,7 @@ static ContentValues mapContentValuesFrom(Movie movie) {
contentValues.put(FavoriteMovieEntry.COLUMN_POPULARITY, movie.popularity());
contentValues.put(FavoriteMovieEntry.COLUMN_VOTE_AVERAGE, movie.voteAverage());
contentValues.put(FavoriteMovieEntry.COLUMN_POSTER_PATH, movie.posterPath());
contentValues.put(FavoriteMovieEntry.COLUMN_BACKDROP_PATH, movie.backdropPath());

return contentValues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public static final class FavoriteMovieEntry {

public static final String COLUMN_POSTER_PATH = "poster_path";

public static final String COLUMN_BACKDROP_PATH = "backdrop_path";

public static final String SQL_CREATE_FAVORITE_MOVIE_TABLE =
"CREATE TABLE " + FavoriteMovieEntry.TABLE_NAME + " (" +
FavoriteMovieEntry.COLUMN_ID + " INTEGER UNIQUE, " +
Expand All @@ -64,7 +66,8 @@ public static final class FavoriteMovieEntry {
FavoriteMovieEntry.COLUMN_RELEASE_DATE + " TEXT NOT NULL, " +
FavoriteMovieEntry.COLUMN_POPULARITY + " REAL NOT NULL, " +
FavoriteMovieEntry.COLUMN_VOTE_AVERAGE + " REAL NOT NULL, " +
FavoriteMovieEntry.COLUMN_POSTER_PATH + " TEXT NOT NULL " +
FavoriteMovieEntry.COLUMN_POSTER_PATH + " TEXT NOT NULL, " +
FavoriteMovieEntry.COLUMN_BACKDROP_PATH + " TEXT NOT NULL " +
");";

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ private static UriMatcher buildUriMatcher() {
FavoriteMovieEntry.COLUMN_RELEASE_DATE,
FavoriteMovieEntry.COLUMN_POPULARITY,
FavoriteMovieEntry.COLUMN_VOTE_AVERAGE,
FavoriteMovieEntry.COLUMN_POSTER_PATH
FavoriteMovieEntry.COLUMN_POSTER_PATH,
FavoriteMovieEntry.COLUMN_BACKDROP_PATH
};

private static final SQLiteQueryBuilder allFavoriteInformationQueryBuilder;
Expand Down Expand Up @@ -176,6 +177,9 @@ private ContentValues extractMovieInformation(ContentValues values) {
contentValues.put(FavoriteMovieEntry.COLUMN_POSTER_PATH,
values.getAsString(FavoriteMovieEntry.COLUMN_POSTER_PATH));

contentValues.put(FavoriteMovieEntry.COLUMN_BACKDROP_PATH,
values.getAsString(FavoriteMovieEntry.COLUMN_BACKDROP_PATH));

contentValues.put(FavoriteMovieEntry.COLUMN_RELEASE_DATE,
values.getAsString(FavoriteMovieEntry.COLUMN_RELEASE_DATE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@SerializedName("vote_average") public abstract Double voteAverage();
@SerializedName("popularity") public abstract Double popularity();
@SerializedName("poster_path") public abstract String posterPath();
@SerializedName("backdrop_path") public abstract String backdropPath();

public static TypeAdapter<MovieDetailResponse> typeAdapter(Gson gson) {
return new AutoValue_MovieDetailResponse.GsonTypeAdapter(gson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
public class RestMovieMapper {

public static Movie transformFrom(Result restMovieResult) {
return new Movie
.Builder(restMovieResult.id(), restMovieResult.originalTitle())
return Movie.builder()
.setId(restMovieResult.id())
.setOriginalTitle(restMovieResult.originalTitle())
.setOverview(restMovieResult.overview())
.setPopularity(restMovieResult.popularity())
.setPosterPath(restMovieResult.posterPath())
.setBackdropPath(restMovieResult.backdropPath())
.setReleaseDate(RestDateMapper.transformFrom(restMovieResult.releaseDate()))
.setVoteAverage(restMovieResult.voteAverage())
.build();
}

public static Movie transformFrom(MovieDetailResponse movieDetailResponse) {
return new Movie
.Builder(movieDetailResponse.id(), movieDetailResponse.originalTitle())
return Movie.builder()
.setId(movieDetailResponse.id())
.setOriginalTitle(movieDetailResponse.originalTitle())
.setOverview(movieDetailResponse.overview())
.setPopularity(movieDetailResponse.popularity())
.setPosterPath(movieDetailResponse.posterPath())
.setBackdropPath(movieDetailResponse.backdropPath())
.setReleaseDate(RestDateMapper.transformFrom(movieDetailResponse.releaseDate()))
.setVoteAverage(movieDetailResponse.voteAverage())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.google.auto.value.AutoValue;

import java.util.Calendar;
import java.util.Date;

import br.com.ecarrara.popularmovies.core.utils.datetime.DateUtils;

@AutoValue public abstract class Movie {
@AutoValue
public abstract class Movie {

public static final int INVALID_ID = -1;
public static final String NO_TITLE = "";
Expand All @@ -19,63 +19,48 @@
public static final String NO_POSTER_PATH = "";

public abstract Integer id();

public abstract String originalTitle();

public abstract String overview();

public abstract Date releaseDate();

public abstract Double popularity();

public abstract Double voteAverage();

public abstract String posterPath();

public static class Builder {
private Integer id = INVALID_ID;
private String originalTitle = NO_TITLE;
private String overview = NO_OVERVIEW;
private Date releaseDate = INVALID_DATE;
private Double popularity = NO_POPULARITY;
private Double voteAverage = NO_VOTE_AVERAGE;
private String posterPath = NO_POSTER_PATH;

public Movie build() {
return new AutoValue_Movie(
this.id,
this.originalTitle,
this.overview,
this.releaseDate,
this.popularity,
this.voteAverage,
this.posterPath
);
}

public Builder(int id, String originalTitle) {
this.id = id;
this.originalTitle = originalTitle;
}

public Builder setOverview(String overview) {
this.overview = overview;
return this;
}

public Builder setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
return this;
}

public Builder setPopularity(Double popularity) {
this.popularity = popularity;
return this;
}

public Builder setVoteAverage(Double voteAverage) {
this.voteAverage = voteAverage;
return this;
}

public Builder setPosterPath(String posterPath) {
this.posterPath = posterPath;
return this;
}
public abstract String backdropPath();

public abstract Builder toBuilder();

public static Builder builder() {
return new AutoValue_Movie.Builder();
}

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder setId(Integer id);

public abstract Builder setOriginalTitle(String title);

public abstract Builder setOverview(String overview);

public abstract Builder setReleaseDate(Date releaseDate);

public abstract Builder setPopularity(Double popularity);

public abstract Builder setVoteAverage(Double voteAverage);

public abstract Builder setPosterPath(String posterPath);

public abstract Builder setBackdropPath(String backdropPath);

public abstract Movie build();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public abstract class MovieDetailViewModel {

public abstract String posterPath();

public abstract String backdropPath();

public abstract Double voteAverage();

public abstract String plotSynopsis();
Expand All @@ -30,19 +32,23 @@ public MovieDetailViewModel withIsFavorite(boolean isFavorite) {

@AutoValue.Builder
abstract static class Builder {

abstract Builder setTitle(String title);

abstract Builder setReleaseDate(String releaseDate);

abstract Builder setPosterPath(String posterPath);

abstract Builder setBackdropPath(String backdropPath);

abstract Builder setVoteAverage(Double voteAverage);

abstract Builder setPlotSynopsis(String plotSynopsis);

abstract Builder setIsFavorite(boolean isFavorite);

abstract MovieDetailViewModel build();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static MovieDetailViewModel transformFrom(Movie movie, boolean isFavorite
return MovieDetailViewModel.builder()
.setTitle(movie.originalTitle())
.setReleaseDate(SimpleDateFormat.getDateInstance().format(movie.releaseDate()))
.setPosterPath(RestImageUrlBuilder.build(movie.posterPath()))
.setPosterPath(RestImageUrlBuilder.buildPosterUrl(movie.posterPath()))
.setBackdropPath(RestImageUrlBuilder.buildBackdropUrl(movie.backdropPath()))
.setVoteAverage(movie.voteAverage())
.setPlotSynopsis(movie.overview())
.setIsFavorite(isFavorite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

public abstract Integer movieId();
public abstract String posterPath();
public abstract String title();

public static MovieListItemViewModel create(int movieId, String posterPath) {
return new AutoValue_MovieListItemViewModel(movieId, posterPath);
public static MovieListItemViewModel create(int movieId, String posterPath, String title) {
return new AutoValue_MovieListItemViewModel(movieId, posterPath, title);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class MovieListItemViewModelMapper {

private static MovieListItemViewModel transformFrom(Movie movie) {
return MovieListItemViewModel.create(movie.id(),
RestImageUrlBuilder.build(movie.posterPath()));
RestImageUrlBuilder.buildPosterUrl(movie.posterPath()),
movie.originalTitle()
);
}

public static List<MovieListItemViewModel> transformFrom(List<Movie> movies) {
Expand Down
Loading

0 comments on commit d899f75

Please sign in to comment.