Jul 2 | 7:15 PM |
Mark M. | has entered the room |
Jul 2 | 7:20 PM |
Mark M. | turned on guest access |
Jul 2 | 7:35 PM |
ansh s. | has entered the room |
Mark M. |
hello, ansh!
|
Mark M. |
how can I help you today?
|
ansh s. |
greetings sir, how are you doing?
|
Mark M. |
OK, and you?
|
ansh s. |
i am good. got a couple of questions
|
ansh s. |
first was regarding that mediator live data i asked via community forum
|
ansh s. |
I had this query regarding filtering a livedata, like changing its source, and you suggested i should use mediator livedata. i looked into and was able to sucessfully implement that feature
|
Mark M. |
cool!
|
Jul 2 | 7:40 PM |
ansh s. |
But here is a thing: mediator livedata can take many sources and does not have a getSource function. So when i apply mediatorObj.removeSource(<oldSource>) , i actually don't know what to pass as 'oldSource'
|
Mark M. |
you have to track that on your own, in another field/property
|
ansh s. |
so how to get old source it is observing?
|
ansh s. |
oh, like a global variable?
|
ansh s. |
well, that was what i applied too
|
Mark M. |
no, in the same scope as the MediatorLiveData
|
Mark M. |
so, if your MediatorLiveData is held by a ViewModel, the ViewModel would also hold onto the oldSource
|
Mark M. |
https://issuetracker.google.com/issues/131738009 is where I asked for an improved API here
|
ansh s. |
yes, that's where i have created a function for updating source, and there i am tracking the old source via a global private variable
|
Mark M. |
the word "global" worries me :-)
|
Mark M. |
keep it in the same scope as the MediatorLiveData itself
|
Mark M. |
see https://gitlab.com/commonsguy/cw-jetpack-java/b... for example
|
Mark M. |
there, lastSave is your oldSource
|
Mark M. |
I hold onto the MediatorLiveData (saveEvents) and the last source (lastSave) in the ViewModel (MainMotor)
|
ansh s. |
well, i did just like that and am calling my oldSource as 'global', am i using the word wrong hehe
|
Mark M. |
ah, OK
|
Jul 2 | 7:45 PM |
ansh s. |
okay, next doubt.. i can't seem to find much resources on Executor , and i have came across a piece of code , that looks extremely cool. woul like to know how is it working
|
ansh s. |
would*
|
ansh s. |
View paste
|
ansh s. |
sorry the comments are by me for the 'dumb' me
|
Mark M. |
I suspect that does not work the way that you are thinking
|
Mark M. |
from the comments, I assume that you are looking to execute this code on the main application thread.
|
Mark M. |
get() will block that thread
|
Mark M. |
which means the background thread was pointless
|
ansh s. |
the dao.getRandomTea() is a call to rooms dao... and it should be asynchronous... and when i click a button this returns the query immediately, so that's why i assumed that
|
ansh s. |
oh, so basically my main thread is blocked?
|
Mark M. |
yes
|
Mark M. |
submit() returns a Future and has your dao.getRandomTea() call be executed on a background thread, which is fine
|
ansh s. |
so this means that query is being executted on the main thread? then how come my room db allows it without getting blasted?
|
Jul 2 | 7:50 PM |
Mark M. |
the *query* itself is being executed on a background thread
|
Mark M. |
you are blocking the main application thread by calling get() on the Future
|
Mark M. |
get() is a blocking call, tying up the current thread until the background thread completes its work and updates the Future to reflect that
|
ansh s. |
oh, so 2 threads are being used, and for the time till the background thread runs, my main thread is blocked?
|
Mark M. |
correct
|
Mark M. |
so, this gets you past Room's "do not do operations on the main application thread" error
|
ansh s. |
wow, so second thread is really pointless, and i thought this code is cool
|
Mark M. |
if it makes you feel better, lots of people come to the same conclusion
|
ansh s. |
and this sure is going to give me an ANR if i perform a long running operation,right
|
Mark M. |
so, you are far from alone
|
Mark M. |
if the operation is long enough, yes
|
Mark M. |
for shorter operations, your UI is frozen
|
Mark M. |
that's why Room yells at you if you try doing database I/O on the main application thread
|
ansh s. |
have you covered the executors in any book? i can't seem to find it as a solo topic
|
ansh s. |
i checked busy coder
|
Mark M. |
that is a Java thing
|
Mark M. |
not an Android thing
|
ansh s. |
oh okay
|
Mark M. |
so, I use Executor in some places, but I do not explain its operation
|
ansh s. |
next was regarding paging library
|
Mark M. |
I have not worked with that in ~18 months, so my memory may be fuzzy
|
Jul 2 | 7:55 PM |
ansh s. |
i have checked their videos and many code samples, they seem to be showing a great way of loading data, and in their illustrations, they show gifs which indicate that when loading data via paging library, we won't even have to use some shimmer loading, because the ui is itself getting created if you handle the null cases correctly
|
ansh s. |
i tried with a lot of sample projects with paging library, yet i can't seem to get that shimmer loading like animation
|
Mark M. |
I do not know what you mean by "shimmer loading like animation"
|
ansh s. |
i am sorry i am running out of english words, not my best language. its like that placeholder to actual data convertion, like you see when using picasso or glide library
|
Mark M. |
OK
|
Mark M. |
particularly with Room, the paging often is fast enough that it is difficult to see a RecyclerView row with your placeholder content
|
Jul 2 | 8:00 PM |
Mark M. |
so, personally, I have not worried about it much -- I make sure the placeholders work in testing
|
ansh s. |
yes,exactly... the data is getting loaded fluently and all, but i can't see the animation that i expected.. i thought that it is sending a list of null values at first, nd quickly changing it to actual data values, triggering the code in my holder
|
ansh s. |
i even tried with network as resource, yet nothing... infact this time the recycler view scrolling was not that fluent
|
ansh s. |
because downloadng was from the network, so the whole process was taking some time
|
Mark M. |
¯\_(ツ)_/¯
|
Mark M. |
I have not used the paging stuff very much, and I was not worrying about this aspect of the behavior at that time
|
Mark M. |
and, as I mentioned, it was a while ago when I last used it
|
Mark M. |
so, I do not recall the exact behavior, in terms of when we get null values for our data
|
Mark M. |
sorry!@
|
ansh s. |
no worries ..i just like how glide/picasso update the placeholder to actual data... was wishing if their was a way to do the same for text data
|
ansh s. |
ok next doubt
|
ansh s. |
how can i test my job schedular is working?
|
Jul 2 | 8:05 PM |
ansh s. |
do i have to sit in front of whole day to look to the logs
|
ansh s. |
in front of adb
|
Mark M. |
there are two aspects to this: is the actual job getting invoked, and is the work being done by the job doing what it should
|
Mark M. |
ideally, you should keep your JobService fairly thin, so you can test your actual work directly
|
Mark M. |
in terms of confirming that the jobs themselves get invoked, on a manual basis, manually change the time in your device or emulator
|
ansh s. |
actual job getting invoked i guess... my job is making a notification everytime it is called... nd its a periodic job, like running twice a day
|
ansh s. |
oh okay
|
ansh s. |
so this internally depends on system time... but isn't there is a thing with job like if it is scheduled for getting invoked every 30 minutes, it will get invoked anywhere between that time interval?
|
Mark M. |
yes, in principle
|
Mark M. |
from a battery standpoint, it is more efficient to wake up the device once and do a lot of work than it is to wake up the device lots of times and do a little work each time
|
Mark M. |
so JobScheduler tries to shift jobs around to wake up the device fewer times
|
Jul 2 | 8:10 PM |
ansh s. |
yes.. so if i got a notification(i.e an indicator that my job worked) like now, and i changed my phone time to 29 minutes( if my job is scheduled to get invoked every 30 mins) , would i immediately get a new notification>
|
Anshul V. | has entered the room |
Mark M. |
perhaps not "immediately", but I would expect it to trigger more quickly
|
Mark M. |
let me take a question from Anshul, and I'll return to you in a bit
|
Mark M. |
Anshul: hi! how can I help you today?
|
ansh s. |
Sure... hi anshul
|
Mark M. |
Anshul: do you have a question?
|
Anshul V. |
Hey everyone, I am working on re-architecting the app to make it multi-modular, and wanted to discuss the way in which we can achieve it. The requirement came when we decided to split the app into 3 different apps. I know there are plenty ideas floating around the web, I wanted your take on it, Mark.
|
Jul 2 | 8:15 PM |
Anshul V. |
Do you mention modularization somewhere in books? I may have missed it..
|
Mark M. |
no, sorry
|
Mark M. |
I talk some about modules in terms of app modules versus library modules, but I do not get into modularization strategies or anything like that
|
Mark M. |
I have... unusual experiences in that area, so I do not feel comfortable trying to offer advice on the subject
|
Mark M. |
the closer you get to "how do I organize this massive project?", the less likely it is that my experiences will line up with what ordinary developers encounter
|
Mark M. |
if you have very specific questions, I can try to answer them, but that's about it
|
ansh s. |
haha, you call that "alphabet soup" ;P
|
ansh s. |
the whole mvc mvvm mvp thing
|
Mark M. |
ansh: while GUI architecture is part of project organization, it's not strictly related to if and how you divide the app into modules, so Anshul's area of concern is a bit different
|
Anshul V. |
okay, thanks! I am also doing this the first time, so unsure about so many things. No worries, carry on. We are aware of all these ideas like Clean Architecture, and SOLID principles, and as Ansh mentioned, the "alphabet soup", but I guess I won't know enough until I implement and mess it up..
|
Jul 2 | 8:20 PM |
Mark M. |
for all of those things, do bear in mind that times and tastes change
|
ansh s. |
i have yet to explore all of those areas, hehe
|
Mark M. |
so today's GUI architecture buzzwords may be tomorrow's "tech debt"
|
ansh s. |
<can i post my last question?>
|
Mark M. |
yes, it's a free for all now, here in the last minutes -- if either of you have questions, go ahead!
|
Anshul V. |
Haha.. yep, that's what I am cleaning up right now, all my tickets are labelled "tech debt". More abstractions, more scalable, more testable sounds fun until you actually get down to the bare bones of what makes the app tick. And the biggest drawback is that user doesn't know the difference..
|
Anshul V. |
Go ahead, Ansh!
|
Mark M. |
Anshul: agreed -- that's why I recommend that teams focus first on having a documented, consistent implementation, *then* worry about refactoring for those sorts of concerns
|
Jul 2 | 8:25 PM |
Mark M. |
the point behind all of these things is long-term maintainability, but having a documented, consistent implementation is far more important for maintainability than are the details of the implementation itself, IMHO
|
ansh s. |
thankyou. Actually this is also more about general testing. I have to explore more of testing, but i can't understand how to test these background running tasks like work manager and jobschedular... the invoking part
|
ansh s. |
like you said, your way was okay, and i can try, but is there some official or more framework like thing that i can use?
|
Mark M. |
WorkManager has a dedicated testing artifact (androidx.work:work-testing), so I would check that out
|
Mark M. |
in terms of automated testing, I focus more on the work being done and less on the system-supplied trigger
|
Anshul V. |
Agreed! I am documenting as I go about refactoring. As always, thank you for your help, Mark!
|
Mark M. |
Anshul: you're welcome!
|
ansh s. |
oh okay. thanks sir
|
Mark M. |
you're welcome, too! :-)
|
Anshul V. | has left the room |
ansh s. |
"And that's the wrap for today" hehe
|
ansh s. | has left the room |
Mark M. |
nope, we have 51 seconds
|
Mark M. |
er, 46
|
Mark M. |
no, now 38
|
Mark M. |
:-)
|
Jul 2 | 8:30 PM |
Mark M. |
*now*, it's a wrap for today's chat
|
Mark M. |
the next chat is tomorrow at 9am US Eastern
|
Mark M. |
and the transcript of this chat will go up on https://commonsware.com/office-hours/ shortyl
|
Mark M. |
er, shortly
|
Mark M. |
have a pleasant day!
|
Mark M. | turned off guest access |