Office Hours — Today, January 12

Tuesday, January 10

Jan 12
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
midas
has entered the room
Mark M.
hello, midas!
midas
hey mark
Mark M.
how can I help you today?
4:00 PM
midas
Im having a hell of a time getting an image to fit properly into a recyclerview grid cell
I want the width to match the cell width
and the height can vary
I have tried so many scale types and etc
just cant get it to work
any suggestions?
Mark M.
is the cell width a known fixed value, or is the cell width dynamic (e.g., available space divided into four columns)?
midas
width is dynamic
Mark M.
OK, and how are you defining the size of the ImageView itself?
midas
hold on let me bring that up
Ankur
has entered the room
midas
match_parent
fr the width
Mark M.
(hello, Ankur -- I will be with you shortly!)
midas
and wrap_content for height
Mark M.
midasL hmmm...
Ankur
Heya folks. No worries, I can wait.
Mark M.
er, midas: hmmmm...
is the ImageView the cell itself, or is it contained in something else?
midas
its a vertical Linear Layout consisting of the ImageView and a TextView
the LinearLayout is also width = match_parent and height = wrap_content
4:05 PM
Mark M.
I have this sneaking suspicion that the height of wrap_content will be a problem
midas
interesting. so I should try match parent?
or give it 0dp and a weight?
Mark M.
I'd try the latter first
the problem there is that the LinearLayout itself is deriving its size from its contents
midas
Aha. And the image isnt loading fast enough to get an accurate height?
Mark M.
possibly
what you might want to do is temporarily fix the size of the ImageLayout to specific dimensions
use that to figure out the right scaleType for your needs
then, once the scaleType is established, work on making the size more flexible, in accordance with the cell width
midas
yeah ok, that makes sense. Ill try it now and get back if that doesnt do the job. thanks.
Mark M.
OK, I'll switch to Ankur for a while, and I'll check in with you in a bit
Ankur: your turn! do you have a question?
midas
thanks
Ankur
Yes. Hoping you can help me spot a flaw in my thinking before I spend a bunch of time building something.
4:10 PM
Ankur
We're building an offline-first app, intended for deployment in places with poor connectivity. Fairly simple CRUD, but I'd like to have everything happen locally in SQLite, with periodic syncs to the server (that we also control and can build in whatever way is most convenient)
Mark M.
only if you tell me what you're thinking :-)
Ankur
I'd expected to find some well-understood framework for making local changes and syncing to remote servers (similar to git / couchbase / etc), but there appears to be nothing much in that space for Android that I can find. I'm happy to go build it, but I imagine there's a reason why that doesn't exist that I might be missing.
Mark M.
partly, that's because there are few standards on the server side
Ankur
Have you heard of any projects in this space? Or alternatively, are there things you'd be wary of before building your own?
Mark M.
well, the only things that can really do what you're asking have to be opinionated on both sides, client and server
so, for example, you cited Couchbase
they offer syncing, but it requires Couchbase on both sides
Ankur
Right, since it'll need to hook into data-change events on both sides.
Mark M.
a lot of Android apps don't have that degree of flexibility on the server side, because the same server is handling other cases (e.g., Web apps)
Ankur
Fair enough
4:15 PM
Ankur
And it's not clear that there's a simple way to handle merge conflicts across problem spaces...
Mark M.
right
that's why offline-first isn't super-common, unless the users are fairly independent of each other
Ankur
I guess I'm just concerned about building sync naively. Sync can go very wrong in subtle ways, and I'd prefer to use an existing battle-tested implementation, but can't find one.
Mark M.
I'm not aware of any that are publicly available
outside of Couchbase Mobile (and git, though I'm not sure if there's a decent native Android git library...)
however, I don't have the world's Android frameworks memorized anymore
(I ran out of fingers a few years ago)
Ankur
So if you were trying to solve for the same need, you'd build it yourself? Or is there something that you think is close enough that would be a good starting point to explore?
Mark M.
so, it's entirely possible something is kicking around that I just haven't run across yet
Ankur
I just saw this but haven't played with it yet: https://github.com/NYTimes/Store
Mark M.
off the cuff, that seems one-way, server to client
Ankur
Yeah, it doesn't appear to have a solution for writes.
Mark M.
that's one of the sorts of puzzle pieces that I mentioned
though I haven't seen that particular library before, which is interesting since it's from a "name brand"
4:20 PM
Mark M.
anyway, it is difficult for me to answer what I would do, since the problem space is a bit nebulous
Ankur
i think its 'days old'
fair enough, many thanks.
Mark M.
sorry I wasn't of greater use on that one
Ankur
i've other things i'd love your take on, but happy to wait
Mark M.
let me see if midas has another question first
Ankur
sure
Mark M.
midas: back to you! do you have another question?
midas: if you have another question, chime in
Ankur: in the meantime, back to you!
midas
still working on the imageview in the grid
gosh this is FRUSTRATING
Ankur
:/ sorry midas. i didn't catch the problem you were working on, but 'styling android' is a frustration i am familiar with.
midas
haha thanks Ankur
4:25 PM
Ankur
Mark -- do you use much in the way of ORMs?
Mark M.
no, sorry
Ankur
Are they overkill for Android, or just haven't found a good one yet?
Mark M.
um, it's more that my work tends to be a bit esoteric
for example, in book chapters, the only reason I would use an ORM is to demonstrate using an ORM
Ankur
Right.
4:30 PM
Mark M.
other work involves things like SQLCipher, for which there is limited ORM support
Ankur
We tried out SQLDelight for this project, and it's been less useful than we were hoping.
Mark M.
I played with that some, then ran into the not-flexible-enough-to-use-SQLCipher situation
midas
hey Mark?
Ankur
It also doesn't seem to accomplish much more than 'SQL-without-the-actual-SQL'
Mark M.
midas: go ahead!
midas
thanks
so I fixed the height of the ImageView
Mark M.
(Ankur: yes, it's designed to be a fairly thin layer over the SQL)
midas
and found that centercrop works the best, but as soon as I give it a wrap content or 0dp + weight it breaks
Mark M.
did you set the dimensions to match the aspect ratio of your test image?
midas
well as I said the width of the cell is unknown
Mark M.
understood
never mind
4:35 PM
Mark M.
so, what does "it breaks" entail?
midas
the height gets clipped
Mark M.
do the images all have the same aspect ratio, or will they vary?
midas
same
1 h : 1.5 w
Mark M.
then you might switch to use PercentRelativeLayout or ConstraintLayout, instead of LinearLayout
those have options for you to indicate that a particular child should maintain its aspect ratio
midas
ok Ill give that a shot
oooh
thats interesting
thanks
Mark M.
midas
your encyclopedic knowledge astounds!
Mark M.
I try to be useful
midas
ha! thats an understatement. thanks again
Mark M.
in that layout, I have an ImageView in a ConstraintLayout, where the height is 0dp (ConstraintLayout equivalent to match_parent, roughly) and the width is constrained via app:layout_constraintDimensionRatio="4:3"
I don't have a PercentRelativeLayout sample that uses aspect ratio handy, though I recall that it supports it
if you run into further difficulties, chime in
Ankur: do you have another question?
4:40 PM
Ankur
Yes actually, though I'll try to make this my last one :P
Is AccountManager the best option for storing API tokens and such these days?
Mark M.
I've never been an AccountManager fan, personally
so it depends a lot on the nature of the token and the threat vectors that concern you
if you're not worried about people rooting the device and getting the token, just using internal storage suffices for a lot of developers
if rooting is a concern, I'm not sure how much AccountManager helps, as I haven't researched how it stores the data
4:45 PM
Ankur
that's not a huge concern for us for this project, but i'd generally like to understand that better. is there something that's resilient to rooting?
Mark M.
using KeyStore (directly or simply for encrypting the internal storage) would be better, but it fails if the user changes their lockscreen type
I thought that had been fixed with Android 5.0, but I'm seeing reports that it still can occur
I haven't done a lot of research recently on this topic, so I'm a bit stale
Ankur
interesting. independent of the data storage location, is there any value in the authenticator + accountmanager framework? (for instance, is that backed up with your google identity for reuse across devices, or similar?)
Mark M.
I would assume that gets backed up by Google, which is a double-edged sword
(at least -- there might be more than two edges)
on the one hand, it gets backed up
on the other hand, you're trusting Google
4:50 PM
Ankur
eh, any time the tokens leave the device (for whatever reason) that's a whole other can of worms to worry about
4:50 PM
midas
Mark. You rock. ConstraintLayout saved the day
thanks a ton
Mark M.
midas: there's probably solutions that work with the classic containers, but they tried to make this use case simpler with these newer libraries
it just dawns on me that I have my own AspectLockedFrameLayout in cwac-layouts, that was targeting this sort of scenario too
midas
Ill check it out. But for now... if it aint broke dont fix it
Mark M.
anyway, we're running low on chat time, so if either of you have any remaining questions, ask!
midas
nope Im good. Have a good one
midas
has left the room
Ankur
Just a future chapter request -- I'd be very curious to know which plugins / tools you use in your own production projects. If you were to ever add a chapter about that, that'd be fascinating.
But that's it. Thanks for everything!
Mark M.
you are very welcome!
4:55 PM
Ankur
has left the room
Mark M.
turned off guest access

Tuesday, January 10

 

Office Hours

People in this transcript

  • Ankur
  • Mark Murphy
  • midas