Apr 20 | 8:25 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Apr 20 | 8:35 AM |
Kumar V. | has entered the room |
Kumar V. |
Hi Mark.
|
Mark M. |
hello, Kumar!
|
Mark M. |
how can I help you today?
|
Kumar V. |
View paste
|
Mark M. |
by "use Handler", do you mean that is what you were using for the timeout (e.g., postDelayed())? if not, what are you using for the timeout?
|
Kumar V. |
Yes Handler with postDelayed
|
Apr 20 | 8:40 AM |
Mark M. |
you would probably need to cancel the postDelayed() via removeCallbacks() and make note of how much time is remaining -- then, when appropriate, call postDelayed() for that remaining time
|
Kumar V. |
Okay. This seems to be common use case, is there any elegant, standard way that you are aware of, to get this done.
|
Mark M. |
"This seems to be common use case" -- um, I'll take your word for that
|
Mark M. |
there are many ways of implementing a timer, including options in reactive frameworks (e.g., RxJava, Kotlin coroutines)
|
Eric | has entered the room |
Eric |
morning mark!
|
Mark M. |
I do not know of any off the top of my head with built in pause/resume logic
|
Shikhar D. | has entered the room |
Mark M. |
(BTW, hello, Eric -- I will be with you shortly!)
|
Mark M. |
(hello, Shikhar! I will be with you in a bit, after Kumar and Eric!)
|
Kumar V. |
Okay. But do you see any issues if I go ahead with Handler with background thread ?
|
Mark M. |
personally, I would be using RxJava or coroutines
|
Mark M. |
I have never tried Handler in a ViewModel
|
Mark M. |
I do not know of any problems with that, but I do not have practical experience with that combination
|
Kumar V. |
What should I be looking in coroutines for this ?
|
Apr 20 | 8:45 AM |
Mark M. |
delay() in a suspend function, or I think there is also a delay() operator on Flow
|
Mark M. |
let me take questions from the others, and I will come back to you in a little while
|
Mark M. |
Eric: your turn! how can I help you today?
|
Kumar V. | |
Eric |
You mentioned using paging library version 3 with rxjava. Can you refer me to an example, or is it in your commonsware material?
|
Mark M. |
neither -- it is in a project that I working on for a consulting client
|
Mark M. |
(er, I am working on)
|
Eric |
ok, yea I didn't see it iin elements of jetpack so far
|
Mark M. |
I will add some Paging 3 material to *Elements of Android Room* eventually, though not pertaining to RxJava
|
Eric |
ok
|
Eric |
I will look online instead
|
Eric |
I appreciate it, take it easy :)
|
Mark M. |
you too!
|
Eric |
bye
|
Mark M. |
Shikhar: your turn! how can I help you today?
|
Eric | has left the room |
Shikhar D. |
Hey Mark, 1st time using chat option. Thanks for the opportunity
|
Mark M. |
I'm happy to try to help!
|
Shikhar D. |
my question is related to ScopeStorage policy. Are you aware of the deadline. I got a mail which says May5 but target android 11 is Nov21
|
Apr 20 | 8:50 AM |
Mark M. |
I personally have not received the email, as I do not distribute anything myself on the Play Store -- however, I have seen copies of that email
|
Shikhar D. |
I have some materials with me. Shall I send it to you now?
|
Mark M. |
I am uncertain what you mean by "materials", sorry
|
Mark M. |
I assume you are referring to an email like the one posted at: https://www.reddit.com/r/androiddev/comments/mq...
|
Shikhar D. |
So the thing is ours is a chat App and we are still targeting api29 and using requestLegacyStorage flag
|
Shikhar D. |
excatly..oh by materials I mean the things I googled related to policy
|
Shikhar D. | |
Shikhar D. |
above is the policy mail screenshot
|
Mark M. |
as is noted in that Reddit thread, the email is very poorly written
|
Mark M. |
and android:requestLegacyExternalStorage="true" is specifically supposed to be usable for Android 10
|
Shikhar D. |
yes. email is not clear whether it applies when you target android 11 as well as when you ask for all files permission
|
Shikhar D. |
because if May5 is the deadline then I have to start the migration work right now
|
Apr 20 | 8:55 AM |
Mark M. |
I have no visibility into Google's decision-making process, nor how they intend to act on May 5
|
Shikhar D. |
I understand. Still, What's your suggestion ?
|
Mark M. |
if your targetSdkVersion is still 29, though, https://support.google.com/googleplay/android-d... indicates that you should still be OK for now
|
Shikhar D. |
that was also my assumption, but I got confused when I saw the mail in my play console. As I am not targeting android 11, then I dont know why they sent me the mail. May be they have sent it to all dev accounts
|
Mark M. |
well, at some point, you are going to need to do the work to deal with android:requestLegacyExternalStorage no longer being honored once your targetSdkVersion reaches 30
|
Shikhar D. |
there is some preserveFlag as well. I still dont understand its use
|
Mark M. |
I think that they sent it to all dev accounts -- my customer's app has targetSdkVersion 29, and the person handling the Play Store distribution received this email
|
Mark M. |
I do not understand that preserve flag either
|
Mark M. |
anyway, if you have the time in your development schedule to try to expedite no longer needing android:requestLegacyExternalStorage in the next few weeks, that would be the safest course of action
|
Mark M. |
so for example, we will be double-checking things in my customer's project, though we should be close to OK in our current state
|
Shikhar D. |
almost most of the answers on StackOverflow has same description of that flag which is written in official documentation
|
Apr 20 | 9:00 AM |
Mark M. |
let me take another question from Kumar, and I will be back with you in a bit
|
Mark M. |
Kumar: back to you! do you have another question?
|
Shikhar D. |
thanks for the suggestion. I will start working on the migration then. Will you be checking more on this?
|
Shikhar D. |
sure
|
Kumar V. |
View paste
|
Mark M. |
that will depend on what you want to do with things like text flow control (e.g., word-wrapping)
|
Mark M. |
if the two pieces of text are truly independent, having two TextView widgets should be fine
|
Kumar V. |
It is a short one, a single line.
|
Mark M. |
well, "single line" might depend on screen size, font scale, etc.
|
Kumar V. |
It is a single text, they aren't indepedent.
|
Mark M. |
if you are absolutely certain that either you will not need word-wrapping, or you are willing to consider this text as two separate pieces for word-wrapping, then two TextViews should be fine
|
Apr 20 | 9:05 AM |
Kumar V. |
I mean the text is very short, of 3 words with default font size
|
Mark M. |
then probably you can get away with two TextViews
|
Kumar V. |
Okay.
|
Kumar V. |
Can I get reference point for that coroutines / flow with timer
|
Mark M. |
OK, I must have have mis-remembered -- I do not see a delay() operator for Flow
|
Kumar V. |
With the coroutine ?
|
Mark M. |
I show delay() in a coroutine in many examples in *Elements of Kotlin Coroutines*
|
Mark M. |
including the very first one: https://klassbook.commonsware.com/lessons/Corou...
|
Kumar V. |
Okay, will check and try that.
|
Mark M. |
delay() is a top-level function, available inside of any suspend function, to delay for a period of time
|
Apr 20 | 9:10 AM |
Mark M. |
let me take another question from Shikhar, and I will try to get back to you before the end of the chat
|
Mark M. |
Shkihar: over to you! do you have another question?
|
Kumar V. |
but does it have pause / resume functionality ?
|
Mark M. |
(Kumar: no, but as I said, I do not know of anything that does -- you would have to implement that sort of logic yourself, such as by cancelling the coroutine and scheduling it later for the remaining time)
|
Shikhar D. |
1 more. So in MVVM java project how do you communicate between Repo and ViewModel
|
Shikhar D. |
For simplicity, lets consider Repo doesn't have caching and it fetches data from API
|
Shikhar D. |
I am using Rx. So the Repo should return Single<>, Observable<>
|
Mark M. |
for work that takes time, have the repository return something reactive, such as an RxJava Observable/Single/Completable
|
Mark M. |
correct, and which of those depends on whether the repository will be publishing changes over time
|
Shikhar D. |
I was under the impression that subsribeOn(), observeOn() which we write in Rx pipeline should be in Repo
|
Mark M. |
so, for example, a simple Web service call probably would get modeled as a Single or Completable, depending on whether you are expecting any results back
|
Mark M. |
I have seen that code either be in the repository or the viewmodel
|
Shikhar D. |
but if its in Repo then how will you communicate the result back to ViewModel
|
Mark M. |
return the Single, etc.
|
Mark M. |
subscribe {} would be in the ViewModel
|
Mark M. |
subscribeOn() != subscribe {}
|
Apr 20 | 9:15 AM |
Mark M. |
subscribeOn() says "this is the Scheduler that should be used for the work"
|
Mark M. |
subscribe() says "OK, send me the results"
|
Shikhar D. |
so this is how I am doing
|
Mark M. |
if the repository calls subscribeOn() and observeOn(), it controls the choice of schedulers, but it still has a Single, Observable, etc. to return to the viewmodel
|
Shikhar D. |
View paste
(15 more lines)
|
Shikhar D. |
View paste
|
Shikhar D. |
View paste
|
Mark M. |
no
|
Mark M. |
View paste
|
Mark M. |
subscribeOn() returns the Single
|
Mark M. |
observeOn() returns the Single
|
Mark M. |
so getSentUsers() returns the Single
|
Mark M. |
the subscribe() call remains in the viewmodel
|
Shikhar D. |
ok...subscribe(new SingleObserver<> with override callbacks will be in ViewModel
|
Mark M. |
correct
|
Apr 20 | 9:20 AM |
Shikhar D. |
is there any issue if ViewModel controls the Schedulers. Which way you will suggest
|
Mark M. |
I have seen both be used
|
Mark M. |
mostly, I have put the schedulers in the viewmodel
|
Shikhar D. |
same..Most of the code samples I found uses the same approach. But I was confused because of theory which says Repo should fetch the data and If repo is fetching the data then I was assuming that it should be handling schedulers and just returning the results to ViewModel
|
Mark M. |
I would argue that the code with the subscribe() call should be the one with the observeOn() call, to control what thread is used for those subscribe() callbacks
|
Mark M. |
that implies that observeOn() would be handled by the viewmodel
|
Mark M. |
I can see arguments for why subscribeOn() should be handled by the repository
|
Mark M. |
but, I cannot tell you that there is One True Correct Answer for this -- mostly, it seems to be a matter of project style
|
Mark M. |
OK, at this point, if either of you have any questions, go ahead! I will try to answer whatever I can in the remaining time
|
Shikhar D. |
I am done. Thanks for the help. Really appreciate it
|
Apr 20 | 9:25 AM |
Mark M. |
you're welcome!
|
Kumar V. |
That's it Mark. Still unclear about which one to use Handlers / Coroutines for that timer thing.
|
Mark M. |
BTW, the chat transcript will be posted to https://commonsware.com/office-hours/ shortly after the end of the chat
|
Mark M. |
Kumar: if you are using coroutines for other stuff, I would stick to coroutines over a Handler for the timer
|
Shikhar D. | has left the room |
Mark M. | |
Kumar V. |
Yes we are using coroutines.
|
Kumar V. |
Okay, will first try with coroutines.
|
Kumar V. |
Thanks for the help Mark.
|
Mark M. |
you're welcome!
|
Kumar V. |
Good day. Bye.
|
Mark M. |
have a pleasant day!
|
Kumar V. | has left the room |
Apr 20 | 9:30 AM |
Mark M. | turned off guest access |