Dec 2 | 8:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Dec 2 | 9:00 AM |
Johnny | has entered the room |
Mark M. |
hello, Johnny!
|
Mark M. |
how can I help you today?
|
Johnny |
Hi Mark
|
Johnny |
I'm currently building a new app and it requires dealing with prices. I've looked at SO and you mentioned that storing prices as an int value seems to be the best so, $5.30 as 530 etc. Is this still true?
|
Mark M. |
compared to using something like float, yes
|
Johnny |
I've used BigDecimal before but I think this seems cleaner
|
Dec 2 | 9:05 AM |
Mark M. |
BigDecimal is great for Zuckerberg-sized prices :-)
|
Mark M. |
for more... conventional monetary amounts, you will probably find int to be faster
|
Johnny |
Haha thanks, gottcha
|
Mark M. |
they key is to set the units to be something that cannot be subdivided
|
Mark M. |
so, for example, in the US, *usually* things are priced to the cent ($5.30)
|
Mark M. |
gallons of gas, however, tend to get priced to the tenth of a cent
|
Mark M. |
if your currency is Bitcoin, things get priced to a very small decimal fraction of a Bitcoin
|
Mark M. |
so, you choose the "atomic" unit for the currency, and skip trying to do anything sub-atomic
|
Johnny |
Interesting. Though since this is a budget app, I think it should be ok to leave it in cents. And I understand other currencies have different decimal precisions
|
Johnny |
Yep cool
|
Mark M. |
yeah, your case is probably one of the simpler ones
|
Dec 2 | 9:10 AM |
Johnny |
In the same app I'm dealing with time. Would you say a pure Unix timestamp is best? Instead of Joda Time etc.
|
Mark M. |
in terms of what you persist, a Unix millliseconds-since-the-epoch value is reasonable
|
Mark M. |
in terms of what you use in Java to represent that, that's up to you
|
Mark M. |
I haven't used Joda Time personally
|
Mark M. |
and I seem to recall that Jake Wharton released a slimmer date/time library for Android relatively recently
|
Mark M. |
yup, here it is: https://github.com/JakeWharton/ThreeTenABP
|
Johnny |
Ah right, will check that out. Thanks
|
Dec 2 | 9:15 AM |
Mark M. |
if you have any additional questions, go right ahead -- it is a quiet chat room today
|
Dec 2 | 9:20 AM |
Johnny |
View paste
|
Mark M. |
personally, I override one or the other, not both, for a given fragment, usually
|
Mark M. |
if I am inheriting onCreateView() (e.g., ListFragment), I override onViewCreated()
|
Mark M. |
if I am implementing onCreateView(), I just do all the work in there
|
Mark M. |
now, if I were writing a library, where I was expecting others to extend *my* fragments, I would want to think through what the best solution would be
|
Mark M. |
and that might vary by circumstance
|
Johnny |
Ah right. Guess it really doesn't matter that much. Though oncreateview() shouldn't return the inflated view as fast as possible right? Might be a misconception I have
|
Mark M. |
I doubt that it makes a significant difference
|
Mark M. |
it's not going to show up until both methods have been invoked anyway
|
Mark M. |
unless the implementation is a lot screwier than I think it is
|
Dec 2 | 9:25 AM |
Johnny |
haha yeah. I'm just guessing the internal workings of it at the moment. Thanks though
|
Johnny |
If you don't mind, I got another question
|
Mark M. |
go right ahead
|
Dec 2 | 9:30 AM |
Johnny |
View paste
|
Mark M. |
well, I haven't messed with CoordinatorLayout and the like
|
Mark M. |
and I have not really pondered what that sort of parallax behavior would be like on a tablet
|
Mark M. |
from what you describe, it sounds like the Toolbar should be owned by the fragment
|
Mark M. |
at least until you come up with some compelling scenario that forces your hand in another direction
|
Johnny |
Ah ok. I've currently got it as part of the Fragment and it works, but haven't tried for tablet and not needed at the moment
|
Dec 2 | 9:35 AM |
Johnny |
How would you handle threading in a Service? Firing off an IntentService, using Executor or RxJava even?
|
Mark M. |
I have not used RxJava
|
Mark M. |
of the first two options, it depends on the threading model I need
|
Mark M. |
IntentService is great, but there's only the one thread
|
Mark M. |
if I need parallel work, I'd create my own Executor-based Service
|
Mark M. |
one of these days, I'll have the itch to scratch and will create the MultiIntentService or ThreadPoolIntentService or something
|
Dec 2 | 9:40 AM |
Johnny |
Interesting. Sounds pretty neat. Thanks
|
Johnny |
That's all the questions I got. Thanks so much Mark
|
Mark M. |
you are very welcome
|
Johnny |
Enjoy the rest of your day :)
|
Mark M. |
you too!
|
Dec 2 | 10:00 AM |
Johnny | has left the room |
Mark M. | turned off guest access |