Mar 15 | 7:20 PM |
Mark M. | has entered the room |
Mar 15 | 7:25 PM |
Mark M. | turned on guest access |
Mar 15 | 7:30 PM |
Moe | has entered the room |
Mark M. |
hello, Moe!
|
Mark M. |
how can I help you today?
|
Moe |
Hi Mark
|
Moe |
I was the one asked the Retorfit 2 question in SO
|
Mark M. |
um, I recall there being a Retrofit question
|
Mark M. |
but, I see a *lot* of questions
|
Mark M. |
:-)
|
Moe |
I'm sure
|
Moe |
I'll post the url
|
Mark M. |
was this the synchronous versus asynchronous one?
|
Moe |
Not that one
|
Moe |
View paste
|
Mark M. |
ah! that one!
|
Moe |
So my last comment was
|
Moe |
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
|
Mark M. |
you have some JSON
|
Mark M. |
that dictates what the POJOs should look like
|
Mark M. |
you have a URL to get that JSON
|
Moe |
sure
|
Mark M. |
that dictates what the Retrofit interface should look like
|
Mark M. |
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
|
Mar 15 | 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
|
Moe |
so basically I have the VideoInfo POJO, that has a list of ITEMS
|
Moe |
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
|
Moe |
in the implmentation
|
Moe |
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
|
Mark M. |
VideoResponse does not have an Item
|
Mark M. |
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)
|
Mar 15 | 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
|
Mark M. |
and I cannot imagine any modern programming scenario where that will be useful
|
Mark M. |
part of my problem is that I have no idea how you are using these objects
|
Mark M. |
suppose you make your Retrofit call, and you have a fully-populated tree of these objects
|
Mark M. |
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
|
Moe |
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
|
Moe |
so the thumbnal url, video url , title
|
Mark M. |
you will need more than that
|
Mark M. |
Item has List<Rendition>
|
Mark M. |
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
|
Mark M. |
or at least the subset of renditions that Android can play, based on filtering by codec and stuff
|
Mar 15 | 7:45 PM |
Moe |
The renditions I believe have all the info
|
Mark M. |
they do not have the title, for one
|
Mark M. |
that is on Item
|
Moe |
View paste
(20 more lines)
|
Moe |
this is an item with it's Renditon
|
Mark M. |
for a particular Item that has only one Rendition
|
Mark M. |
what if there are two? or three? or twenty?
|
Moe |
yes there are 2 , but I'm only intrested in the one called Rendition
|
Moe |
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
|
Mark M. |
your model is the List<Item>
|
Mark M. |
where you add some code to Item for the find-the-rendition logic
|
Mark M. |
whether that is getTheOneTrueRendition(), or getThumbnailUrl() and kin, is up to you
|
Mar 15 | 7:50 PM |
Moe | |
Moe |
So this is a screenshot from a Retrofit 2 video tutorial
|
Moe |
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
|
Moe |
as the JSON
|
Mark M. |
his JSON doesn't have collections, then
|
Moe |
let me check
|
Mar 15 | 7:55 PM |
Moe |
I think it does , will upload a screenshot
|
Moe | |
Moe |
I think Result is a collection
|
Moe | |
Mark M. |
results is an object, so getChannel() is a regular getter
|
Mark M. |
channel is an object, so getItem() is a regular getter
|
Mark M. |
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
|
Mark M. |
mostly because Retrofit has nothing to do with it
|
Mark M. |
Gson is *giving you the collections*
|
Mark M. |
Gson has no way to know what those collections will look like
|
Mark M. |
and so it gives you getters to retrieve the collection
|
Moe |
yes, I have Gson as the parser
|
Mar 15 | 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() :-(
|
Moe |
or somethign to that tune
|
Moe |
method call I meant
|
Mark M. |
well, again, it comes back to what you are doing with the data
|
Mark M. |
for example, earlier, I said to create an ItemAdapter, wrapped around a List<Item>, for your ListView/RecyclerView/etc.
|
Mark M. |
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
|
Mark M. |
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
|
Mar 15 | 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
|
Mark M. |
while POJOs might be part of an event payload, they otherwise are not involved in an event bus, IMHO
|
Mark M. |
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?
|
Moe |
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?
|
Mar 15 | 8:10 PM |
Moe |
for the list yes, for the payer no
|
Moe |
player
|
Mark M. |
then you should not need to make it Parcelable
|
Mark M. |
just pass the URL, whether as the data portion of the Intent, or as a string extra
|
Moe |
ok
|
Moe |
One last thing
|
Moe |
Expoplayer need to extend a class
|
Moe |
but i want it to be inside a fragment
|
Moe |
is there any tricks to get around extending 2 classes
|
Moe |
int his case the player class and the fragment class?
|
Mark M. |
well, the player class itself should be some form of View, right?
|
Mark M. |
if so, a fragment manages Views, but it is not itself a View
|
Moe |
View paste
|
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
|
Mark M. |
regardless, you cannot have a single class be both a fragment and an activity, even if Java would let you (which it won't)
|
Mar 15 | 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
|
Moe |
will be looking into that
|
Moe |
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!
|
Mark M. |
BTW, barring problems, a book update should be out early next week
|
Moe |
7.2
|
Moe |
eagerly waiting
|
Mark M. |
yes
|
Moe |
the apk will update the book automatically
|
Mark M. |
no
|
Moe |
or will i need to redoanload?
|
Moe |
ok
|
Mark M. |
you will need to download a fresh APK
|
Moe |
that's easy enough
|
Moe |
thanks again Mark
|
Moe |
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
|
Mar 15 | 8:20 PM |
Moe |
cool
|
Moe |
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
|
Moe |
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
|
Moe |
great chatting with you, have a great evening
|
Mark M. |
you too!
|
Moe | has left the room |
Mar 15 | 8:30 PM |
Mark M. | turned off guest access |