Mark M. | has entered the room |
Mark M. | turned on guest access |
Jun 10 | 4:00 PM |
Ashley | has entered the room |
Mark M. |
hello, Ashley!
|
Mark M. |
how can I help you today?
|
Ashley |
View paste
|
Mark M. |
um
|
Mark M. |
I cannot provide advice regarding internships and what people offering those might be seeking
|
Ashley |
Ok
|
Mark M. |
if you have technical questions about Android app development, I can try to help with that
|
Ashley |
I understand
|
Ashley | has left the room |
Jun 10 | 4:10 PM |
trocchietto_Ivano | has entered the room |
Mark M. |
hello, Ivano!
|
Mark M. |
how can I help you today?
|
trocchietto_Ivano |
HI Mark
|
trocchietto_Ivano |
I have two questions
|
trocchietto_Ivano |
the first one is a meta question, not sure if you can help
|
trocchietto_Ivano |
View paste
|
Mark M. |
you could write an Android app development book! :-)
|
Jun 10 | 4:15 PM |
trocchietto_Ivano |
ahahahah
|
trocchietto_Ivano |
do you have suggestion to use your git?
|
Mark M. |
more seriously, I don't really have such a snippet container in my Android work
|
trocchietto_Ivano |
I see thank you to share that
|
Mark M. |
so I do not have much in the way of practical suggestions for one
|
trocchietto_Ivano |
the second question is regarding SwitchMap
|
trocchietto_Ivano |
I saw a beautiful conference from Lylia from Google
|
trocchietto_Ivano |
but I am not sure my understanding is right
|
trocchietto_Ivano |
basically she said to use SwitchMap to substitute a previous LiveData call( for instance to the repository)
|
trocchietto_Ivano |
My question is SwitchMap in some way is like subscribe/unsubscribe with RXJava? I meam the LiveData's remain zombing around once created, and switch data is the way to Kill the previous instances making a "Transformation"?
|
Mark M. |
switchMap() is reminiscent of flatMap() in RxJava
|
Mark M. |
switchMap() is *very* reminiscent of switchMap() in RxJava
|
trocchietto_Ivano |
interesting this second one
|
trocchietto_Ivano |
or switchmap in rxjs i guess
|
Jun 10 | 4:20 PM |
Mark M. |
could be, I have not used RxJS
|
Mark M. |
both map() and switchMap() operate on objects emitted by a source LiveData
|
Mark M. |
map() says "convert these objects into some other ordinary type of object"
|
trocchietto_Ivano |
yep
|
Mark M. |
switchMap() says "convert these objects into LiveData streams"
|
trocchietto_Ivano |
while switch map converts all the livedata
|
trocchietto_Ivano |
yep
|
Mark M. |
for example, in "Android's Architecture Components", I have an example of searching a book via SQLite full-text searching
|
Mark M. |
I have two fragments, each with a ViewModel: one to show the whole book, one to show search results
|
Mark M. |
however, I want to use paging, as I don't want to load the whole book in at once
|
trocchietto_Ivano |
I see
|
Mark M. |
so, my repository is set up to offer that
|
Mark M. |
however, I *also* want to ship the prose of the book in the APK itself
|
Mark M. |
that makes things interesting, because I need to lazy-populate the database
|
trocchietto_Ivano |
mmh you cannot launch livedata to query
|
Mark M. |
so simply getting an instance of my RoomDatabase is expensive
|
trocchietto_Ivano |
I mean transformations
|
Jun 10 | 4:25 PM |
Mark M. |
so my repository does not offer DataSource.Factory<Integer, ParagraphEntity>, but rather Single<DataSource.Factory<Integer, ParagraphEntity>>, so we ensure all the I/O is done on a background thread
|
Mark M. |
in my ViewModel classes, I then "unwrap" this via Transformations.switchMap()
|
Mark M. |
I convert the Single to a Flowable via LiveDataReactiveStreams
|
Mark M. |
and switchMap() returns LiveData<PagedList<ParagraphEntity>>, to hand to my RecyclerView
|
Mark M. |
(and similarly for BookSearchResult instead of ParagraphEntity, for FTS searches)
|
Mark M. |
you will see this covered in the chapter on Room and FTS
|
Mark M. |
and the sample project using this is: https://github.com/commonsguy/cw-androidarch/tr...
|
trocchietto_Ivano |
I had a fast read already
|
trocchietto_Ivano |
I would take 5 min to have a look to your git
|
trocchietto_Ivano |
(btw nice name Time Machine, I need one as well to read all the book I desire instead of this devil coding)
|
Mark M. |
well, all credit for the name goes to H.G. Wells
|
Jun 10 | 4:30 PM |
trocchietto_Ivano |
(classics are everything)
|
trocchietto_Ivano |
btw with your repository, do I have to download all of them to try a single one? in git I do not have a clone link
|
Mark M. |
the GitHub repository is for all the book's samples
|
trocchietto_Ivano |
OK
|
Mark M. |
otherwise, I would have hundreds of GitHub repositories, across my books
|
Mark M. |
which would be unmanageable
|
trocchietto_Ivano |
I see, understandable indeed
|
Mark M. |
so if you want to load the code into an IDE, you would download or clone the book's repo
|
Mark M. |
the import the individual project of interest
|
Jun 10 | 4:35 PM |
trocchietto_Ivano |
OK, as you said and I can see in the ViewModel, you combined SIngle, Flowable and LiveData
|
trocchietto_Ivano |
this surprise me
|
trocchietto_Ivano |
surprises*
|
Mark M. |
um, OK
|
trocchietto_Ivano |
if you use RXJava I guess you do not need LiveData, because LiveData is an RXJava WITHOUT muscles in my opinion, you can do everything you do with LiveData using RXJava I guess
|
trocchietto_Ivano |
apart I guess the fact that LiveData is cycle Aware
|
Mark M. |
RxJava on its own knows nothing about Android's main application thread
|
trocchietto_Ivano |
mmh but you can use ObserveOn
|
Mark M. |
that requires RxAndroid to go along with RxJava
|
trocchietto_Ivano |
I see
|
Mark M. |
plus, as you note, LiveData is lifecycle-aware, though there are RxJava add-ons for that too
|
trocchietto_Ivano |
RXJava is 100 times more powerful imo
|
Mark M. |
you have two choices: use RxJava all the way through, or use RxJava for "back end" bits and convert to LiveData for the ViewModel layer
|
trocchietto_Ivano |
LiveData is perfect to use it togheter with the other components
|
Jun 10 | 4:40 PM |
Mark M. |
LiveData on its own isn't very powerful, and that's by design -- it's supposed to be simpler to use than RxJava
|
trocchietto_Ivano |
so I have a small curiosity
|
trocchietto_Ivano |
in your app when do you convert the Single/Flowable with a LiveData instance?
|
Mark M. |
the first parameter to both switchMap() calls is the output of LiveDataReactiveStreams.fromPublisher()
|
Mark M. |
this converts a Flowable or other Publisher into a LiveData
|
trocchietto_Ivano |
ah
|
trocchietto_Ivano |
wow
|
trocchietto_Ivano |
there is this factory pattern that makes things tougher to me
|
trocchietto_Ivano |
but will clone your project, will learn a lot
|
trocchietto_Ivano |
with a breakpoint in the VIewModel
|
trocchietto_Ivano |
thank you
|
trocchietto_Ivano |
uncle BOB is right, there is too much black magic around:(
|
Mark M. |
I'll admit that my use of switchMap() here is not very common
|
Mark M. |
however, it is the only switchMap() example in the book
|
trocchietto_Ivano |
I see
|
trocchietto_Ivano |
I have the feeling that Lylia uses in a much different use case
|
trocchietto_Ivano |
that make it almost compulsory, afaiUnderstood, LiveData instances remains around
|
Jun 10 | 4:45 PM |
trocchietto_Ivano |
SwitchMap allow you to do more Search queries
|
trocchietto_Ivano |
transforming the first query in an hypotetical edit text of a Search in a new one, in this way you do not have zombie processes around
|
trocchietto_Ivano |
https://www.youtube.com/watch?v=SlZVYkhoSq8 from 33:24
|
trocchietto_Ivano |
Mark thank you very much, was really informative to understand that I can combine Live Data and RxJava for more complex use cases
|
Mark M. |
you're welcome!
|
trocchietto_Ivano |
I wish you a pleasant time, moving forward, but also backward considering the Time Machine `magic`
|
Mark M. |
ha!
|
Jun 10 | 5:00 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ in a bit
|
trocchietto_Ivano |
have a nice time
|
Mark M. |
the next chat is Tuesday at 7:30pm US Easter
|
Mark M. |
er, US Eastern
|
trocchietto_Ivano |
OK
|
Mark M. |
have a pleasant day/evening/other day-part!
|
trocchietto_Ivano | has left the room |
Mark M. | turned off guest access |