package com.daksh.tmdbsample.data.model;

import android.databinding.BindingAdapter;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.ImageView;

import com.google.gson.annotations.SerializedName;
import com.squareup.picasso.Picasso;

import java.util.Date;

/**
 * Created by daksh on 03-Sep-16.
 */
public class Movie implements Parcelable {

    public static final Parcelable.Creator<Movie> CREATOR = new Parcelable.Creator<Movie>() {
        @Override
        public Movie createFromParcel(Parcel source) {
            return new Movie(source);
        }

        @Override
        public Movie[] newArray(int size) {
            return new Movie[size];
        }
    };
    private final String title;
    @SerializedName("poster_path")
    private final String imageUrl;
    @SerializedName("overview")
    private final String synopsis;
    @SerializedName("vote_average")
    private final double userRating;
    private final Date releaseDate;

    public Movie(String title, String imageUrl, String synopsis, double userRating, Date releaseDate) {
        this.title = title;
        this.imageUrl = imageUrl;
        this.synopsis = synopsis;
        this.userRating = userRating;
        this.releaseDate = releaseDate;
    }

    protected Movie(Parcel in) {
        this.title = in.readString();
        this.imageUrl = in.readString();
        this.synopsis = in.readString();
        this.userRating = in.readDouble();
        long tmpReleaseDate = in.readLong();
        this.releaseDate = tmpReleaseDate == -1 ? null : new Date(tmpReleaseDate);
    }

    @BindingAdapter({"bind:imageUrl"})
    public static void loadImage(ImageView view, String imageUrl) {
        //TODO add placeholder
        Picasso.with(view.getContext())
                .load(imageUrl)
                .into(view);
    }

    public String getTitle() {
        return title;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public String getSynopsis() {
        return synopsis;
    }

    public double getUserRating() {
        return userRating;
    }

    public Date getReleaseDate() {
        return releaseDate;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.title);
        dest.writeString(this.imageUrl);
        dest.writeString(this.synopsis);
        dest.writeDouble(this.userRating);
        dest.writeLong(this.releaseDate != null ? this.releaseDate.getTime() : -1);
    }
}

@@ -367,16 +367,323 @@
 able %7B%0A%0A
+    /**%0A     * Image Quality in terms of width in px%0A     */%0A    public static final int IMAGE_QUALITY = 400;%0A%0A    /**%0A     * Full Image URL of a specific quality, %7B@value IMAGE_QUALITY%7Dpx in this case%0A     */%0A    private static final String IMAGE_BASE_URL = %22http://image.tmdb.org/t/p/w%22 + IMAGE_QUALITY;%0A%0A
     publ
@@ -764,24 +764,24 @@
 %3CMovie%3E() %7B%0A
-
         @Ove
@@ -1005,16 +1005,17 @@
 %0A    %7D;%0A
+%0A
     priv
@@ -1897,24 +1897,158 @@
 te);%0A    %7D%0A%0A
+    /**%0A     * Function used by DataBinding to load a poster image into an ImageView%0A     * by calling %7B@link Movie#imageUrl%7D%0A     */%0A
     @Binding
@@ -2213,16 +2213,16 @@
 text())%0A
-
         
@@ -2235,16 +2235,33 @@
   .load(
+IMAGE_BASE_URL + 
 imageUrl

Add Base URL for Image Loading