Oct 10 | 8:25 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
puneet | has entered the room |
Mark M. |
hello, puneet!
|
Mark M. |
how can I help you today?
|
puneet |
hello sir
|
puneet |
i am new to learn kotlin for android development
|
Oct 10 | 8:30 AM |
puneet |
i want to know some tricks to understand more
|
Mark M. |
ummmm... can you be more specific?
|
puneet |
like kpotlin courotines
|
puneet |
coroutines
|
Mark M. |
I wrote about coroutines in *Elements of Kotlin Coroutines* -- you have access to that as part of your Warescription
|
Mark M. |
future updates to that book will include some Android-specific applications of coroutines
|
puneet |
ok sir
|
Mark M. |
also, the *Exploring Android* tutorials use coroutines
|
Mark M. |
and there are a few samples in *Elements of Android Jetpack* that use coroutines
|
puneet |
ok sir
|
Mark M. |
in those cases, it is mostly using coroutines with Room, for local database access
|
puneet |
thank you very much
|
Oct 10 | 8:35 AM |
Mark M. |
if you have specific questions, you can use these office hours chats, or the other options that I have in the "Ask" menu of the Warescription site
|
puneet |
ok sir
|
Oct 10 | 8:40 AM |
Mark M. |
if you have any specific questions now, I can try to answer them -- these office hours chats are mostly for people with particular questions for which they are looking for my help
|
Oct 10 | 8:45 AM |
Ed | has entered the room |
Ed |
Good morning sir
|
Mark M. |
hello, Ed!
|
Mark M. |
how can I help you today?
|
Ed |
Your SimplePrefs demo, I have a question about that....
|
Mark M. |
are you referring to the one in *Elements of Android Jetpack*?
|
Ed |
HomeMotor extends AndroidViewModel
|
Mark M. |
we need a Context to get at SharedPreferences, so I used AndroidViewModel
|
Ed |
androidx.lifecycle.ViewModelProviders made me think there was something else there...
|
Ed |
haven't played with the lifecycle api to any extent
|
Oct 10 | 8:50 AM |
Ed |
the Android docs really suck big time on SharedPreferences right now
|
Mark M. |
I haven't looked recently, but that does not surprise me
|
Ed |
android.content.SharedPreferences doesn't throw any exceptions and looks callable from Android 10
|
Mark M. |
you may be better served looking at the SharedPreferences material in *The Busy Coder's Guide to Android Development*, insofar as it does not assume that you are familiar with the ViewModel stuff
|
Ed |
if they want me to call a different API you would think they would do an API check and then throw a RunTimeException telling me to do it differently
|
Ed |
thanks for the tip
|
Mark M. |
well, the SharedPreferences class itself has been around since API Level 1
|
Ed |
correct but they moved it to AndroidX
|
Mark M. |
not
|
Mark M. |
not really
|
Mark M. |
they moved the UI pieces to AndroidX
|
Mark M. |
SharedPreferences itself is still a framework class
|
Ed |
androidx.preference.PreferenceManager
|
Mark M. |
yes, but that still returns a framework SharedPreferences
|
Mark M. |
and it has the same basic API as the framework PreferenceManager
|
Ed |
interesting... good point... just drilled down and found...
|
Ed |
View paste
|
Mark M. |
PreferenceManager.getDefaultSharedPreferences(...), where ... is a Context, gives you the default SharedPreferences for your app
|
Oct 10 | 8:55 AM |
Ed |
final question for you and I can wait for puneet
|
Ed |
if they want to ask you something
|
Mark M. |
puneet: do you have another question?
|
Mark M. |
Ed: go ahead with your next question, and I'll take a question from puneet if one gets posted
|
Ed |
I'm going to ask my last question really quick if that is ok.... I'll try to be quicker than in the past. :-)
|
Ed |
View paste
|
Ed |
that is my RecyclerView row
|
Ed |
then I'm creating two columns like so...
|
Ed |
View paste
|
Oct 10 | 9:00 AM |
puneet | has left the room |
Ed |
View paste
|
Ed |
you with me so far or should I show more?
|
Mark M. |
I'm with you, though I'm not certain where this is going
|
Ed |
the two columns don't 'cleanly' tack across phones
|
Ed |
oop... track
|
Mark M. |
"tack"?
|
Ed |
so on a Google pixel is looks great
|
Ed |
on another device with a bigger screen there is more spacing and it is not as tight
|
Mark M. |
you have match_parent for the width of your RelativeLayout
|
Mark M. |
I'm not certain that is a good idea for a grid
|
Ed |
what I want is 2 vertical columns where col A and col B both take 50% of the width
|
Ed |
so do a List of Lists?
|
Mark M. |
other than the 2dp padding, is there a particular reason for having that RelativeLayout?
|
Ed |
none
|
Ed |
So do a Vertical List that contains a Horizontal list of two items?
|
Mark M. |
you might try removing it, adding 2dp margin to the ImageView instead, and using wrap_content for the ImageView size
|
Ed |
ok
|
Mark M. |
your grid should be OK
|
Mark M. |
it is your cells that is your problem
|
Mark M. |
hard-coding image dimensions guarantees that on larger screens "there is more spacing and it is not as tight"
|
Oct 10 | 9:05 AM |
Mark M. |
so you need to do something to allow the image sizes to adapt to the environment
|
Mark M. |
if you stick with the grid, wrap_content for the image size may suffice
|
Ed |
so instead do this...
|
Ed |
View paste
|
Mark M. |
View paste
|
Mark M. |
the RelativeLayout is not doing anything
|
Mark M. |
if you get frustrated with the grid, you could use ConstraintLayout for a row in a list-style RecyclerView, with each row having two images
|
Mark M. |
as ConstraintLayout gives you lots of control for setting up your 50% sizing, maintaining the aspect ratios, etc.
|
Ed |
That seems like the better choice
|
Mark M. |
however, you'll need to handle the case where there are an odd number of images, so your last row looks the way that you want
|
Ed |
correct
|
Ed |
so in my adapter I would just grab two at a time and handle the issue where I might have a 1/2 image
|
Ed |
oops.. I mean 1/2 row... or 1 image
|
Mark M. |
that could be a matter of just loading a transparent image into the second position as a placeholder
|
Ed |
thanks Mark!
|
Mark M. |
you're welcome!
|
Oct 10 | 9:10 AM |
Ed |
have a great day
|
Mark M. |
you too!
|
Ed |
cheers
|
Ed | has left the room |
Oct 10 | 9:25 AM |
Mark M. | turned off guest access |