我正在创建一个非常简单的应用程序(目前用于播放)来自Giantbomb.com网站的视频。他们有一个公共API,所以我正在使用它。我正在使用Retrofit,OkHttp,RxJava和Dagger2在MVP中构建应用程序。对于我的应用程序的简单性,这可能有点过分,但我想学习这些库和架构。
现在它是一个单一的活动应用程序,我想要包含一个可滚动的网站顶级视频的磁贴/卡片列表。在每张卡片中,我想要包括缩略图和视频标题。当您单击磁贴/卡时,它会播放视频。我认为这会产生一个新的活动(或片段?),它将保存下面的视频和描述,并可以选择全屏显示。
所以,尽管如此。现在我正在使用http://www.giantbomb.com/api/videos/?api_key=[my_api_key]&format=json
作为我最初的api调用。它返回以下内容(有更多“结果”,我将其减少为2)。
{
"error": "OK",
"limit": 100,
"offset": 0,
"number_of_page_results": 100,
"number_of_total_results": 11376,
"status_code": 1,
"results": [{
"api_detail_url": "http:\/\/www.giantbomb.com\/api\/video\/2300-11935\/",
"deck": "Rorie fights killer robots, Brad jams discs, Jeff breaks the law, and Jason can't put his phone away.",
"hd_url": "https:\/\/giantbomb-pdl.akamaized.net\/2017\/03\/18\/mc_upf_031717_4000.mp4",
"high_url": "https:\/\/giantbomb-pdl.akamaized.net\/2017\/03\/18\/mc_upf_031717_3200.mp4",
"low_url": "https:\/\/giantbomb-pdl.akamaized.net\/2017\/03\/18\/mc_upf_031717_1800.mp4",
"embed_player": "http:\/\/www.giantbomb.com\/videos\/embed\/11935\/",
"id": 11935,
"length_seconds": 7921,
"name": "Unprofessional Fridays: 03\/17\/2017",
"publish_date": "2017-03-17 17:33:00",
"site_detail_url": "http:\/\/www.giantbomb.com\/videos\/unprofessional-fridays-03172017\/2300-11935\/",
"url": "mc_upf_031717.mp4",
"image": {
"icon_url": "http:\/\/www.giantbomb.com\/api\/image\/square_avatar\/2926581-upf031717.jpg",
"medium_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_medium\/2926581-upf031717.jpg",
"screen_url": "http:\/\/www.giantbomb.com\/api\/image\/screen_medium\/2926581-upf031717.jpg",
"small_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_small\/2926581-upf031717.jpg",
"super_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_large\/2926581-upf031717.jpg",
"thumb_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_avatar\/2926581-upf031717.jpg",
"tiny_url": "http:\/\/www.giantbomb.com\/api\/image\/square_mini\/2926581-upf031717.jpg"
},
"user": "unastrike",
"video_type": "Premium",
"video_show": null,
"video_categories": [{
"api_detail_url": "http:\/\/www.giantbomb.com\/api\/video_category\/2320-10\/",
"id": 10,
"name": "Premium",
"site_detail_url": "http:\/\/www.giantbomb.com\/videos\/premium\/"
}
],
"youtube_id": null
}, {
"api_detail_url": "http:\/\/www.giantbomb.com\/api\/video\/2300-11933\/",
"deck": "Will this be the end of our robot nightmare or will we succumb to the onslaught of the dreaded boss rush?",
"hd_url": "https:\/\/giantbomb-pdl.akamaized.net\/2017\/03\/17\/mc_bluebombin_03172017_4000.mp4",
"high_url": "https:\/\/giantbomb-pdl.akamaized.net\/2017\/03\/17\/mc_bluebombin_03172017_3200.mp4",
"low_url": "https:\/\/giantbomb-pdl.akamaized.net\/2017\/03\/17\/mc_bluebombin_03172017_1800.mp4",
"embed_player": "http:\/\/www.giantbomb.com\/videos\/embed\/11933\/",
"id": 11933,
"length_seconds": 5700,
"name": "Blue Bombin': Mega Man 4 - Part 04",
"publish_date": "2017-03-17 16:18:00",
"site_detail_url": "http:\/\/www.giantbomb.com\/videos\/blue-bombin-mega-man-4-part-04\/2300-11933\/",
"url": "mc_bluebombin_03172017.mp4",
"image": {
"icon_url": "http:\/\/www.giantbomb.com\/api\/image\/square_avatar\/2926565-cp_megaman_04_part04.00_24_27_54.still001.jpg",
"medium_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_medium\/2926565-cp_megaman_04_part04.00_24_27_54.still001.jpg",
"screen_url": "http:\/\/www.giantbomb.com\/api\/image\/screen_medium\/2926565-cp_megaman_04_part04.00_24_27_54.still001.jpg",
"small_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_small\/2926565-cp_megaman_04_part04.00_24_27_54.still001.jpg",
"super_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_large\/2926565-cp_megaman_04_part04.00_24_27_54.still001.jpg",
"thumb_url": "http:\/\/www.giantbomb.com\/api\/image\/scale_avatar\/2926565-cp_megaman_04_part04.00_24_27_54.still001.jpg",
"tiny_url": "http:\/\/www.giantbomb.com\/api\/image\/square_mini\/2926565-cp_megaman_04_part04.00_24_27_54.still001.jpg"
},
"user": "vinny",
"video_type": "Premium",
"video_show": {
"api_detail_url": "http:\/\/www.giantbomb.com\/api\/video_show\/2340-9\/",
"id": 9,
"title": "Blue Bombin'",
"position": 0,
"site_detail_url": "http:\/\/www.giantbomb.com\/shows\/blue-bombin\/"
},
"video_categories": [{
"api_detail_url": "http:\/\/www.giantbomb.com\/api\/video_category\/2320-10\/",
"id": 10,
"name": "Premium",
"site_detail_url": "http:\/\/www.giantbomb.com\/videos\/premium\/"
}
],
"youtube_id": null
}
],
"version": "1.0"
}
当我使用http://www.jsonschema2pojo.org/来创建表示这个的类时,我得到:
-----------------------------------com.app.int_a.giantbombforandroid.Image.java-----------------------------------
package com.app.int_a.giantbombforandroid;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Image {
@SerializedName("icon_url")
@Expose
private String iconUrl;
@SerializedName("medium_url")
@Expose
private String mediumUrl;
@SerializedName("screen_url")
@Expose
private String screenUrl;
@SerializedName("small_url")
@Expose
private String smallUrl;
@SerializedName("super_url")
@Expose
private String superUrl;
@SerializedName("thumb_url")
@Expose
private String thumbUrl;
@SerializedName("tiny_url")
@Expose
private String tinyUrl;
public String getIconUrl() {
return iconUrl;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
public String getMediumUrl() {
return mediumUrl;
}
public void setMediumUrl(String mediumUrl) {
this.mediumUrl = mediumUrl;
}
public String getScreenUrl() {
return screenUrl;
}
public void setScreenUrl(String screenUrl) {
this.screenUrl = screenUrl;
}
public String getSmallUrl() {
return smallUrl;
}
public void setSmallUrl(String smallUrl) {
this.smallUrl = smallUrl;
}
public String getSuperUrl() {
return superUrl;
}
public void setSuperUrl(String superUrl) {
this.superUrl = superUrl;
}
public String getThumbUrl() {
return thumbUrl;
}
public void setThumbUrl(String thumbUrl) {
this.thumbUrl = thumbUrl;
}
public String getTinyUrl() {
return tinyUrl;
}
public void setTinyUrl(String tinyUrl) {
this.tinyUrl = tinyUrl;
}
}
-----------------------------------com.app.int_a.giantbombforandroid.Result.java-----------------------------------
package com.app.int_a.giantbombforandroid;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Result {
@SerializedName("api_detail_url")
@Expose
private String apiDetailUrl;
@SerializedName("deck")
@Expose
private String deck;
@SerializedName("hd_url")
@Expose
private String hdUrl;
@SerializedName("high_url")
@Expose
private String highUrl;
@SerializedName("low_url")
@Expose
private String lowUrl;
@SerializedName("embed_player")
@Expose
private String embedPlayer;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("length_seconds")
@Expose
private Integer lengthSeconds;
@SerializedName("name")
@Expose
private String name;
@SerializedName("publish_date")
@Expose
private String publishDate;
@SerializedName("site_detail_url")
@Expose
private String siteDetailUrl;
@SerializedName("url")
@Expose
private String url;
@SerializedName("image")
@Expose
private Image image;
@SerializedName("user")
@Expose
private String user;
@SerializedName("video_type")
@Expose
private String videoType;
@SerializedName("video_show")
@Expose
private VideoShow videoShow;
@SerializedName("video_categories")
@Expose
private List<VideoCategory> videoCategories = null;
@SerializedName("youtube_id")
@Expose
private Object youtubeId;
public String getApiDetailUrl() {
return apiDetailUrl;
}
public void setApiDetailUrl(String apiDetailUrl) {
this.apiDetailUrl = apiDetailUrl;
}
public String getDeck() {
return deck;
}
public void setDeck(String deck) {
this.deck = deck;
}
public String getHdUrl() {
return hdUrl;
}
public void setHdUrl(String hdUrl) {
this.hdUrl = hdUrl;
}
public String getHighUrl() {
return highUrl;
}
public void setHighUrl(String highUrl) {
this.highUrl = highUrl;
}
public String getLowUrl() {
return lowUrl;
}
public void setLowUrl(String lowUrl) {
this.lowUrl = lowUrl;
}
public String getEmbedPlayer() {
return embedPlayer;
}
public void setEmbedPlayer(String embedPlayer) {
this.embedPlayer = embedPlayer;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getLengthSeconds() {
return lengthSeconds;
}
public void setLengthSeconds(Integer lengthSeconds) {
this.lengthSeconds = lengthSeconds;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPublishDate() {
return publishDate;
}
public void setPublishDate(String publishDate) {
this.publishDate = publishDate;
}
public String getSiteDetailUrl() {
return siteDetailUrl;
}
public void setSiteDetailUrl(String siteDetailUrl) {
this.siteDetailUrl = siteDetailUrl;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getVideoType() {
return videoType;
}
public void setVideoType(String videoType) {
this.videoType = videoType;
}
public VideoShow getVideoShow() {
return videoShow;
}
public void setVideoShow(VideoShow videoShow) {
this.videoShow = videoShow;
}
public List<VideoCategory> getVideoCategories() {
return videoCategories;
}
public void setVideoCategories(List<VideoCategory> videoCategories) {
this.videoCategories = videoCategories;
}
public Object getYoutubeId() {
return youtubeId;
}
public void setYoutubeId(Object youtubeId) {
this.youtubeId = youtubeId;
}
}
-----------------------------------com.app.int_a.giantbombforandroid.Video.java-----------------------------------
package com.app.int_a.giantbombforandroid;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Video {
@SerializedName("error")
@Expose
private String error;
@SerializedName("limit")
@Expose
private Integer limit;
@SerializedName("offset")
@Expose
private Integer offset;
@SerializedName("number_of_page_results")
@Expose
private Integer numberOfPageResults;
@SerializedName("number_of_total_results")
@Expose
private Integer numberOfTotalResults;
@SerializedName("status_code")
@Expose
private Integer statusCode;
@SerializedName("results")
@Expose
private List<Result> results = null;
@SerializedName("version")
@Expose
private String version;
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public Integer getLimit() {
return limit;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getOffset() {
return offset;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getNumberOfPageResults() {
return numberOfPageResults;
}
public void setNumberOfPageResults(Integer numberOfPageResults) {
this.numberOfPageResults = numberOfPageResults;
}
public Integer getNumberOfTotalResults() {
return numberOfTotalResults;
}
public void setNumberOfTotalResults(Integer numberOfTotalResults) {
this.numberOfTotalResults = numberOfTotalResults;
}
public Integer getStatusCode() {
return statusCode;
}
public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}
public List<Result> getResults() {
return results;
}
public void setResults(List<Result> results) {
this.results = results;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
-----------------------------------com.app.int_a.giantbombforandroid.VideoCategory.java-----------------------------------
package com.app.int_a.giantbombforandroid;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class VideoCategory {
@SerializedName("api_detail_url")
@Expose
private String apiDetailUrl;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("name")
@Expose
private String name;
@SerializedName("site_detail_url")
@Expose
private String siteDetailUrl;
public String getApiDetailUrl() {
return apiDetailUrl;
}
public void setApiDetailUrl(String apiDetailUrl) {
this.apiDetailUrl = apiDetailUrl;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSiteDetailUrl() {
return siteDetailUrl;
}
public void setSiteDetailUrl(String siteDetailUrl) {
this.siteDetailUrl = siteDetailUrl;
}
}
-----------------------------------com.app.int_a.giantbombforandroid.VideoShow.java-----------------------------------
package com.app.int_a.giantbombforandroid;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class VideoShow {
@SerializedName("api_detail_url")
@Expose
private String apiDetailUrl;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("title")
@Expose
private String title;
@SerializedName("position")
@Expose
private Integer position;
@SerializedName("site_detail_url")
@Expose
private String siteDetailUrl;
public String getApiDetailUrl() {
return apiDetailUrl;
}
public void setApiDetailUrl(String apiDetailUrl) {
this.apiDetailUrl = apiDetailUrl;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getPosition() {
return position;
}
public void setPosition(Integer position) {
this.position = position;
}
public String getSiteDetailUrl() {
return siteDetailUrl;
}
public void setSiteDetailUrl(String siteDetailUrl) {
this.siteDetailUrl = siteDetailUrl;
}
}
我想知道这是否是设置类的实用方法。我认为这里的“视频”课程是我的最高级别课程吗?我是否通过获取Video
课程的结果列表与视频进行互动?这是否有意义,还是我离开基地?
我意识到这是相当开放的,但我只是在寻找想法。同时寻找任何阅读建议,以更好地理解这些关系。
谢谢!
编辑:当我看到这个时,我想知道我是否可以将Result
重命名为Video
并直接处理结果对象,就像它们是视频一样(它们全部都是的属性)。否则我在整个地方处理List<Video>
,我将不得不在Video
上调用'getResults()'来获取新的`List',然后我就可以开始使用视频的属性了。我没有看到第二层的原因。