-
Notifications
You must be signed in to change notification settings - Fork 0
/
Movie.java
55 lines (46 loc) · 1.71 KB
/
Movie.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.example.flixster2;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.parceler.Parcel;
import java.util.ArrayList;
import java.util.List;
@Parcel
public class Movie {
String posterPath;
String backdropPath;
String title;
String overview;
Double vote_average;
Double popularity;
public Movie(){}
public Movie(JSONObject jsonObject) throws JSONException{
posterPath = jsonObject.getString("poster_path");
backdropPath = jsonObject.getString("backdrop_path");
title = jsonObject.getString("title");
overview = jsonObject.optString("overview");
vote_average = jsonObject.getDouble("vote_average");
popularity = jsonObject.getDouble("popularity");
}
public static List<Movie> fromJsonArray(JSONArray movieJsonArray) throws JSONException {
List<Movie> movies = new ArrayList<>();
for(int i = 0; i < movieJsonArray.length(); i++) {
movies.add(new Movie(movieJsonArray.getJSONObject(i))) ;
}
return movies;
}
public String getPosterPath() {
return String.format("https://image.tmdb.org/t/p/w342/%s" , posterPath); //https://image.tmbd.org/t/p[IMAGE_SIZE]
} //"https://image.tmdb.org/t/p/w342/%s"
public String getBackdropPath() {
return String.format("https://image.tmdb.org/t/p/w342/%s" , backdropPath); //https://image.tmbd.org/t/p[IMAGE_SIZE]
}
public String getTitle() {
return title;
}
public String getOverview() {
return overview;
}
public Double getVoteAverage() { return vote_average; }
public Double getPopularity() { return popularity;}
}