Mark M. | has entered the room |
Mark M. | turned on guest access |
Sep 13 | 8:05 PM |
Aaron | has entered the room |
Aaron |
hey Mark, I hope you are having a good week! I have 4 questions for you today. Here they are:
|
Mark M. |
hello, Aaron!
|
Mark M. |
go right ahead!
|
Aaron |
View paste
|
Mark M. |
1. Adapter is a static class defined inside of RecyclerView. If you look at the RecyclerView source code, you will find Adapter defined inside of it.
|
Mark M. |
2. That does not sound familiar, sorry.
|
Mark M. |
3. Off the top of my head, I cannot think of any, though ConstraintLayout is a complex beast, and so I cannot rule out other scenarios.
|
Mark M. |
4. You could consider the SharedPreferences to be purely a backing store, with some object holding a cached value for your ongoing use.
|
Sep 13 | 8:10 PM |
Mark M. |
I'm guessing you'll want clarification on some of those :-)
|
Aaron |
1-3 are clear, my main followup question would be, in general, which approach would you suggest for 4 and why? The amount of data being written is very tiny and shouldn't block the thread for very long. I guess the question is just whether there is a best practice, and how naughty it is to fall back to commit()
|
Mark M. |
well, ideally, you don't call commit() on the main application thread
|
Mark M. |
it's not terribly evil (like, say, network I/O on the main application thread)
|
Mark M. |
but it's not that hard to avoid, either
|
Aaron |
OK, that answers it, I will figure out another way
|
Mark M. |
so, I'd have some sort of singleton (a "repository" in the current popular terminology) that represents your app's access to this data
|
Mark M. |
that singleton in turn writes to the SharedPreferences and gets its initial value from those same SharedPreferences
|
Sep 13 | 8:15 PM |
Mark M. |
but the singleton also caches the value, so it can asynchronously write while still handing over that value on other threads (e.g., main application thread) as needed
|
Aaron |
OK that makes sense
|
Aaron |
let me check to see if I have any other questions, as I just noticed it is 5 days until the next chat
|
Mark M. |
yeah, sorry, I'm tied up this weekend
|
Aaron |
no worries
|
Aaron |
ok I have a couple other quick ones
|
Mark M. |
fire away!
|
Aaron |
there have been a couple of times I wanted to find the source code for some class in the framework, or the support library, and Google was not always helpful for pulling it up. In general can you describe the process for tracking down any given source file? I'm not even sure which website to use, it seems like Google has some code on github, and some on a website called googlesource.com... not sure where to begin
|
Mark M. |
first, in the SDK Manager, you have the options for downloading the source code for different API levels, as part of downloading the other SDK bits for those API levels
|
Aaron |
ooh, ok
|
Mark M. |
if you do that, and you're using Android Studio, just put the text cursor in a keyword of interest and press Ctrl-B
|
Sep 13 | 8:20 PM |
Mark M. |
and the source will be opened in another editor tab
|
Mark M. |
works for libraries too, if the library packages source code along with the compiled bits
|
Aaron |
ok great
|
Mark M. |
beyond that, I tend to use the GitHub mirror of the AOSP source code
|
Mark M. |
so, for example, this will contain directories that look familiar: https://github.com/aosp-mirror/platform_framewo...
|
Mark M. |
different releases are tagged, so you can view the source for specific OS releases
|
Mark M. |
and if you need full-text search, use http://aosp.opersys.com/
|
Mark M. |
so, lots of options
|
Aaron |
great, another question:
|
Sep 13 | 8:25 PM |
Aaron |
some of the HTML fields I get back from the reddit API are unescaped and they also contain some special entity characters, for example: <, >, and & replaced with <, >, and &
|
Mark M. |
Html.fromHtml() will clean those up
|
Mark M. |
you'll see that I use that in the various book examples that show lists of questions from Stack Overflow, because their API does the same thing
|
Aaron |
right, but the weird thing is, I have to run it through fromHtml twice to properly display the content formatted in a TextView
|
Aaron |
as in, piping the output of the first call, back into another fromHtml call
|
Aaron |
I am guessing it has something to do with the special entities?
|
Mark M. |
that seems strange
|
Mark M. |
no, a single call would suffice
|
Aaron |
yes, I thought it was strange as well
|
Aaron |
ok, I don't have any more data handy, I just wanted to see if that rang a bell
|
Mark M. |
so, if I get a question title that has "something something & something", a single call to Html.fromHtml() converts that into "something something & something", which TextView can display
|
Mark M. |
requiring two Html.fromHtml() calls implies that your data somehow wound up double-encoded
|
Mark M. |
"something something &amp; something"
|
Mark M. |
so the first Html.fromHtml() turns that into "something something & something"
|
Mark M. |
and the second one gives you "something something & something"
|
Mark M. |
so, either use logging or breakpoints to see what the data is, and see if that double-encoding is indeed what's happening
|
Aaron |
hmm OK I'll take another look
|
Aaron |
ok thanks! Have a good weekend!
|
Mark M. |
if it is, I don't know why it would be, but you might be able to track down the rationale, or if it is something about how you're using the API
|
Mark M. |
you too!
|
Aaron |
will do
|
Sep 13 | 8:30 PM |
Mark M. |
the next chat is Tuesday also at 7:30pm US Eastern
|
Mark M. |
I'll have the transcript of this one up at https://commonsware.com/office-hours/ shortly
|
Mark M. |
see ya!
|
Aaron | has left the room |
Mark M. | turned off guest access |