Office Hours — Today, March 15

Thursday, March 10

Mar 15
7:20 PM
Mark M.
has entered the room
7:25 PM
Mark M.
turned on guest access
7:30 PM
Moe
has entered the room
Mark M.
hello, Moe!
how can I help you today?
Moe
Hi Mark
I was the one asked the Retorfit 2 question in SO
Mark M.
um, I recall there being a Retrofit question
but, I see a *lot* of questions
:-)
Moe
I'm sure
I'll post the url
Mark M.
was this the synchronous versus asynchronous one?
Moe
Not that one
View paste

http://stackoverflow.com/questions/35962112/retrofit-2-in-android-after-implementation-where-are-my-json-elements
Mark M.
ah! that one!
Moe
So my last comment was
Shall I move the getItem() method from the pojo Item to VideoResponse? and for this matter all the getters for the other JSON elements? my thinking is in Retrofit VideoResponse knows about VideoInfopojo which knows about the Item Objects list that knows about Rendition list, where it gets the URL of the video
Mark M.
well, the problem is that I can't really answer those questions
you have some JSON
that dictates what the POJOs should look like
you have a URL to get that JSON
Moe
sure
Mark M.
that dictates what the Retrofit interface should look like
but since I don't know the JSON, I can't advise you on moving stuff around in your Gson-annotated classes, because I don't know what that will break
7:35 PM
Mark M.
now, part of this may stem from your use of JSONschema2Pojo, which I haven't seen, let alone used
Moe
sure, but I was hoping if you could look at the 3 POJO I posted at the question
so basically I have the VideoInfo POJO, that has a list of ITEMS
then I have Items Pojo , that has a list of Renditions
Mark M.
yup
Moe
the last one has what I need, the IDs and the videos url
Mark M.
yup
Moe
all the examples I've seen , just call the getters directly
in the implmentation
I honestly don't fancy creating new getters for all those elements
Mark M.
um, they already have getters
Moe
when my POJOs already have all the getters
Mark M.
those were code-generated
Moe
yup
Mark M.
"Shall I move the getItem() method from the pojo Item to VideoResponse?" -- no, because you can't
VideoResponse does not have an Item
VideoResponse has a List<VideoInfo>
Moe
yes that has a list if ITems
Mark M.
VideoInfo has a List<Item>
Moe
exactly
Mark M.
a VideoInfo could have a getItem(int) method, for retrieving some item, though I don't know what that gains you over getItems().get(int)
7:40 PM
Mark M.
the only way VideoResponse could have a getItem() method would be if it were getItem(int, int), with one being the index of the VideoInfo, the other being the index in that VideoInfo of the Item
and I cannot imagine any modern programming scenario where that will be useful
part of my problem is that I have no idea how you are using these objects
suppose you make your Retrofit call, and you have a fully-populated tree of these objects
what are you doing with them?
Moe
Ok, so the JSON contain Items that contain Rendition , here I have all I want , the video ID, the video title , url , etc
so I'm looking to get the thumb nails, urls, titles etc, to build a video app
Mark M.
well, I would imagine that you need to present the rest of the tree to the user as well
Moe
Thumb nail, title, yes
so the thumbnal url, video url , title
Mark M.
you will need more than that
Item has List<Rendition>
I don't know much about this API, or where this data is coming from, but I would have to imagine that the user will care about Item and all the renditions
or at least the subset of renditions that Android can play, based on filtering by codec and stuff
7:45 PM
Moe
The renditions I believe have all the info
Mark M.
they do not have the title, for one
that is on Item
Moe
View paste (20 more lines)
{
"id":4796048518001,
"name":"Ghostbusters & Hollywood's race problem",
"shortDescription":"The Ghostbusters reboot is sparking a controversy over race and representation.",
"creationDate":"1457659249747",
"publishedDate":"1457659249747",
"linkURL":"http:\/\/ajplus.net\/",
"linkText":"For more, visit http:\/\/ajplus.net\/",
"tags":[
"arts-culture-entertainment_tv-film-music",
"empty",
"region1_united states"
],
"videoStillURL":"http:\/\/bc29.ajmn.me\/pd\/2848955552001\/201603\/3955\/2848955552001_4796159769001_RT-60-GHOSTBUSTERS-US-100316-FINAL-SUB-image.jpg?pubId=2848955552001",
"thumbnailURL":"http:\/\/bc29.ajmn.me\/pd\/2848955552001\/201603\/955\/2848955552001_4796159768001_RT-60-GHOSTBUSTERS-US-100316-FINAL-SUB-thumbnail.jpg?pubId=2848955552001",
...
this is an item with it's Renditon
Mark M.
for a particular Item that has only one Rendition
what if there are two? or three? or twenty?
Moe
yes there are 2 , but I'm only intrested in the one called Rendition
there's an IOSRendition that I don't care about
Mark M.
:: shrug ::
Moe
most of what I need to present thumbnails and videos with titles should be in the Rendition
Mark M.
if you think you can come up with an algorithm to suss out the One True Rendition for an Item, then create an ItemAdapter for your ListView/RecyclerView/whatever
your model is the List<Item>
where you add some code to Item for the find-the-rendition logic
whether that is getTheOneTrueRendition(), or getThumbnailUrl() and kin, is up to you
7:50 PM
Moe
So this is a screenshot from a Retrofit 2 video tutorial
you see the part where he's calling the weather
Mark M.
yes
Moe
his query is structured exactly as the weather API he's calling
as the JSON
Mark M.
his JSON doesn't have collections, then
Moe
let me check
7:55 PM
Moe
I think it does , will upload a screenshot
I think Result is a collection
Mark M.
results is an object, so getChannel() is a regular getter
channel is an object, so getItem() is a regular getter
I suspect that you will find that item is an object, so getCondition() is a regular getter, and that condition is an object, so getTemp() is a regular getter
Moe
So Retrofit 2 can't traverse the collections
Mark M.
sure it can
mostly because Retrofit has nothing to do with it
Gson is *giving you the collections*
Gson has no way to know what those collections will look like
and so it gives you getters to retrieve the collection
Moe
yes, I have Gson as the parser
8:00 PM
Mark M.
you're welcome to write your own methods for getFirstRendition() or something, if that's what you want
Moe
so my dream method is impossible? response.body().getItem().getID().getRendition().getUrl() :-(
or somethign to that tune
method call I meant
Mark M.
well, again, it comes back to what you are doing with the data
for example, earlier, I said to create an ItemAdapter, wrapped around a List<Item>, for your ListView/RecyclerView/etc.
you would need to write code, yourself, to aggregate all Item objects into a single list, from across all the VideoLists
Moe
ok
Mark M.
again, Gson isn't going to do that for you, because Gson is general-purpose, and most developers don't need that
Moe
ok, then from the items of the list I get the Rendition elements ?
Mark M.
yes, though you indicated that there is only one rendition that matters
you would have a method on Item to find that Rendition
Moe
and another to find the url and title inside the Rendition
Mark M.
so, between the Item (title, etc.) and the Rendition (duration, etc.), you would have the information to present
Moe
ok
Mark M.
whether you write a getUrl() on Item, or you just have getRendition().getUrl(), is up to you
Moe
yeah, the first one sounds more to the point
8:05 PM
Moe
Ok, so in your example in github I see that you use eventbus, my question is a general one, when do you feel you need to use eventbus , parecelable in your POJO?
Mark M.
um
Moe
or when to use non
Mark M.
an event bus is mostly for communications between components, such as services -> activities
while POJOs might be part of an event payload, they otherwise are not involved in an event bus, IMHO
Parcelable is only needed if the POJO needs to go into a Bundle, Intent extra, or something else that calls for a Parcelable
Moe
so I think in my case, Intent Extra to play the video, I should be using Parcelable?
list -> media player
Mark M.
when you say "play the video", are you writing the video player yourself (e.g., MediaPlayer, ExoPlayer), or are you launching the user's chosen video player app?
Moe
ExoPlayer, built into the app
Mark M.
do you need anything other than the video URL?
8:10 PM
Moe
for the list yes, for the payer no
player
Mark M.
then you should not need to make it Parcelable
just pass the URL, whether as the data portion of the Intent, or as a string extra
Moe
ok
One last thing
Expoplayer need to extend a class
but i want it to be inside a fragment
is there any tricks to get around extending 2 classes
int his case the player class and the fragment class?
Mark M.
well, the player class itself should be some form of View, right?
if so, a fragment manages Views, but it is not itself a View
Moe
View paste
so the player class starts with    -   public class MainActivity extends BrightcovePlayerActivity {
Mark M.
if they need a magic activity class, whether you can use fragments would depend on what that activity does and stuff
Moe
at least that's in their sample application
Mark M.
I have looked over ExoPlayer a bit, but I haven't used it
regardless, you cannot have a single class be both a fragment and an activity, even if Java would let you (which it won't)
8:15 PM
Moe
yeah, they keep updating the player SDK frequently, so probably will have to dig into that
Mark M.
since ExoPlayer is open source, look at BrightcovePlayerActivity, see what it does, and see whether you can create your own MoePlayerActivity fork that puts some of the guts into a fragment
Moe
I'm sure I won't be the first one to attempt that, most video playing apps have a list fragment
will be looking into that
so you might've noticed I'm new around here, I love your book and the way you're available from time to time for questions
Mark M.
thanks for the kind words!
BTW, barring problems, a book update should be out early next week
Moe
7.2
eagerly waiting
Mark M.
yes
Moe
the apk will update the book automatically
Mark M.
no
Moe
or will i need to redoanload?
ok
Mark M.
you will need to download a fresh APK
Moe
that's easy enough
thanks again Mark
those are all my questions for today
Mark M.
you are very welcome
Moe
have a great evening
Mark M.
BTW, the transcript will be posted to https://commonsware.com/office-hours/ shortly after the chat ends
8:20 PM
Moe
cool
will it be possible to make the transcripts searchable
Mark M.
ExoPlayer site:commonsware.com
Moe
I mean at some point int he future, saves you repeating questions, and could be a very valuable reference
Mark M.
(for example_)
Moe
oh, ok
perfect
Mark M.
I mean, I could roll some search thing myself, but I'm not sure what value it would add
Moe
as long as it's crawled by google, it should be fine
great chatting with you, have a great evening
Mark M.
you too!
Moe
has left the room
8:30 PM
Mark M.
turned off guest access

Thursday, March 10

 

Office Hours

People in this transcript

  • Mark Murphy
  • Moe