Office Hours — Today, October 27

Saturday, October 24

Oct 27
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:30 PM
ani
has entered the room
Mark M.
hello, ani!
how can I help you today?
ani
View paste
Hey Mark,
This is Ani, I read your blogpost on play app signing and decided to be a member here. I also attended your session on App security android dev summit.
7:35 PM
Mark M.
thanks, thanks, and thanks! :-)
ani
Thanks for this platform, and what you have done for community :)
Mark M.
I try to be useful!
ani
View paste
I have SQLITE/Room related question.
In my app, I have many records, with potential of several thousands of them, stored in sqlite3.
The data is simple in itself, say _id (primary key, auto increment), _data (text, non null).
My question is, I want to sort the data on the basis of last updated item, say the recently updated items should come before the others.
I can manually enter the updated timestamp in sqlite, but wanted to avoid being in that situation for the following reasons:
1. I wanted to explore is there is any such support in sqlite. SO far I didn’t find it.
2. To avoid user resetting clock/timezone issues and what not, I wanted to resort to something more like Logical timestamp than actual time stamp.
Do you have any suggestions on how to go about it?
On top of it, since we are on a  mobile device, I dont want to fetch every record there is on the device, rather I want to be able to paginate.
If I pick option 2, I can then say:

First page : Select * from data_table where LOGICAL_TIMESTAMP > 0 LIMIT 25
Second page : Select * from data_table where LOGICAL_TIMESTAMP > {logical timestamp of last entry in previous query’s result} LIMIT 25
Mark M.
taking the latter part first, the Jetpack Paging component works with Room
I have an example of it in *Elements of Android Room*, part of your Warescription
that works well if your end target is to put the data in a RecyclerView
if you want to do anything else, you may be better off handling it yourself
in terms of your timestamp concerns, I am not certain what you mean by a "logical timestamp"
for data in a database, we normally think of the data having lifetimes measured in days/weeks/months/years, so we cannot use something like SystemClock.elapsedRealtime()
if you do not want to use the system clock as your time source, and your app needs Internet connectivity for other reasons, you could contact a time server and get a timestamp from it
or, if your app needs location access for other reasons, you could get a timestamp from GPS fixes
ani
I see.. sorry, I keep on getting thrown out of the chat by the system
7:40 PM
Mark M.
really? I'm not seeing that on this end
what happens when it throws you out?
ani
View paste
Logical timestamp: I meant something along the lines of Lamport Timestamp
Increment timestamp on every event..
I switched the tab and when I switched back to this tab, I was logged out
Mark M.
that's strange -- I have not heard anyone else report that problem
in terms of your timestamp, if all you want is a sequence number, you could track that yourself in a separate table, incrementing it as you go and using that value when you insert/update your "real" entities
while SQLite has its own ROWID, you are not guaranteed that they will be in chronological order
ani
Row ID: I see, thanks
7:45 PM
ani
About my own counter: I was thinking that but felt I may be a little crazy for thinking that.
Mark M.
it is a classic technique -- I think I first encountered it about 25 years ago
frequently, it only works when there is only program writing to the database, but in your case, only your app should be writing to it, so you are OK
ani
hahaha.. I bet it would be very interesting to hear you talk about similar stuff and stories that you would have
thanks Mark
Mark M.
happy to help!
ani
View paste
about your point `for data in a database, we normally think of the data having lifetimes measured in days/weeks/months/years, so we cannot use something like SystemClock.elapsedRealtime()`
Can you please elaborate a little?
Mark M.
SystemClock.elapsedRealtime() reports the number of milliseconds since the phone last rebooted
7:50 PM
ani
are you suggesting to not use "SystemClock.elapsedRealtime()" for the data lifecycle being long ?
Mark M.
well, in a days/weeks/months/years timeframe, the phone probably reboots a few times :-)
and that will reset the elapsedRealtime() counter to 0
which is not what you want for your use case
ani
ya, right
8:00 PM
ani
Here is another that you can suggest something fornif that is ok:
How would you go about changing the style on a button at runtime? I didn't find any API like setStyle..
Mark M.
AFAIK, that is not possible
you can adjust individual properties, and you can adjust the group of properties controlled by textAppearance
but you are correct, there is no setStyle()
this is one of the many annoying aspects of the View system that I look forward to getting away from once Jetpack Compose starts gaining momentum
ani
Ah.. thanks
8:05 PM
ani
Airbnb has a library called Pairs that claims to handle this but that didn't work in my case either
8:10 PM
ani
I would like to bump this question up on Stack overflow, can you please take a look once you get a chance please: https://stackoverflow.com/questions/63692210/wh...
8:15 PM
Mark M.
well, that question does not have the source code that triggered the crash
is this your question, or are you just interested in it?
ani
That's mine too 😀
Mark M.
The crash is coming from the Navigation component. If you are using the Navigation component to manage this DialogFragment, you would not call show() -- you would use a NavController to navigate to it
ani
I don't have the source but I can create a hello world with just that if that would help
Makes sense, I try both ways to make sure that's it.
Mark M.
if you have a sample project that demonstrates a DialogFragment that has nothing to do with the Navigation component, where the Navigation component then crashes... that is probably worth a post on the issue tracker, if nobody has reported it already
ani
Sounds good Mark, you are the best.
Mark M.
thanks for the kind words!
8:20 PM
ani
That's all I have for now Mark, stay safe and take care. Thanks again.
Mark M.
you're welcome!
8:30 PM
Mark M.
OK, that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is Thursday at 8:30am US Eastern
have a pleasant day!
ani
has left the room
Mark M.
turned off guest access

Saturday, October 24

 

Office Hours

People in this transcript

  • ani
  • Mark Murphy