Office Hours — Today, November 20

Yesterday, November 19

Nov 20
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
Jiri
has entered the room
Mark M.
hello, Jiri!
how can I help you today?
Jiri
Hi
thank you
i wish to thank you for your great book and content
really nice. money well spent
Mark M.
thanks for the kind words!
Jiri
anyway. im a hobby programmer and had some questions about best practices on android architecture with room etc
Mark M.
go right ahead!
Jiri
what are my options in terms of background service (downloading data) and putting it in a database (room)
and the rest of the program in a MVVM way
9:05 AM
Jiri
its about updating the UI
9:05 AM
Jiri
from the viewmodel
Mark M.
well, Room does not care whether you use it in a service or not, and a service does not care whether you use Room or not
Jiri
i tried livedata
Mark M.
so, those decisions are largely decoupled
Jiri
i tried rxjava
true. but your book helped me with the clear use cases of flowable and maybe of a list of type x
it turns out that flowable is useless for me
Mark M.
personally, with a service, I prefer something more loosely coupled, like an event bus, but that's just me
Jiri
ok i didnt look into this yet but i will
lets say i do an async call to a webservice
write to the db
all fine
but the service need to signal in the backend to the viemmodel/recyclerview that a new async call neeeds to be launched
to fetch the data in the db
this messaging would be done through the evenbus
Mark M.
IMHO, the service needs to signal to the repository, not to the viewmodel
Jiri
eventbus
this is done like this
yes repository
but as i dont use flowable
i will not get notified
...
of updates
when i need to pull
Mark M.
I am not quite certain why you cannot use an Rx type for your communications out of your repository
the fact that a service is involved would be an implementation detail of the repository, not visible to the UI layer
Jiri
View paste (5 more lines)
    public void loadOrders()
    {
        obs_orders = orderRepository.getOrdersDetailedMaybe();

        disp_obs_orders =
                obs_orders
                        .flattenAsObservable(e->e)
                        .filter(e->odf.test(e))
                        .toList()
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(
                                value -> {
                                    orders.setValue(value);
                                    System.out.println("update rcvd");
...
9:10 AM
Jiri
this is specific for the updating the viewmodel which is pushed to the view
Mark M.
um, well, I'm not really in position to comment on that particular code snippet
Jiri
but its a one time off
Mark M.
I am sorry, but I do not understand your question
Jiri
I dont know how i can word it i guess
the tests that i have done alreayd
view - viewmodel with livedata only
all works fine
but missing a lot of functionality from rxjava for filtering etc
not an optin
option
Mark M.
you can map Rx types into LiveData using LiveDataReactiveStreams
Jiri
i understand (i read on SO:-) but as i understand i never get an oncomplete with flowable
so filter doesnt execute
9:15 AM
Jiri
tried with flowable only
maybe streams is different
this is why i ended up with maybe based on your book
but maybe is one time only
or i have to update/poll the viewmodel data every 30s or so to see if theres new data
Mark M.
what data type is obs_orders?
(referring back to your code snippet)
Jiri
List<DetailedOrders>
its a POJO of table joins
Mark M.
that's not possible
List does not have flattenAsObservable()
Jiri
huh?
Mark M.
your RxJava chain starts with obs_orders.flattenAsObservable(e->e)
Jiri
let me check
Mark M.
what is the data type of obs_orders?
Jiri
View paste
    @Query("select ord.*,cp.symbolPair,c1.code as baseCode, c2.code as counterCode from orders as ord " +
            "inner join currencypairs as cp on ord.currencypairId=cp.id " +
            "inner join currencies as c1 on cp.baseId=c1.id " +
            "inner join currencies as c2 on cp.counterId=c2.id " +
            "order by opentimestamp desc")
    public abstract Maybe<List<OrderDetailed>> getOrdersDetailedMaybe();
Mark M.
if you have that return Observable<List<OrderDetailed>>, AFAIK you should get updates pushed to you
though your query may be too complex for Room to handle
9:20 AM
Mark M.
I don't know how sophisticated their SQL parser is to track what table changes need to trigger updates to reactive return values
Jiri
hmm not sure. my chain would break
filter didnt work
no oncomplete
rxjava itself would break
not the return from db
Mark M.
there has to be an Rx operator that filters in onNext() rather than onComplete()
Jiri
well...
i used a subject to force a publish of next and oncomplete
but that gave other problems
i have tried a lot. this is why i came to the Guru
:-)
Mark M.
well, it's difficult for me to help you, given that I don't have your project to run
this is the sort of thing that I'd sit and have to experiment with
Jiri
sure I understand
i think based on your book and feedback i think Maybe is the thing that would work best as i need all data to process anyways
i will look into this event bus for signalling
as an idea
Mark M.
OK
Jiri
ok thanks for your time and feedback
9:25 AM
Mark M.
sorry I could not be of greater assistance
9:25 AM
Jiri
ah maybe on more
if i can
Mark M.
go right ahead!
Jiri
i've looked into this predicate / filter setup. it works smoothly
do you think there's a way to create dynamic evaluation of these boolean construct ?
lets say i would like 5 fields
which could be all null or any combination of search filters
instead of manually combining them with if / else etc
is there a way to construct it dynamically based on non-null
i have seen there are scripting evaluation libraries which can be used in java
maybe that would work
Mark M.
I am not sure what "it" is in "is there a way to construct it dynamically based on non-null"
Jiri
let me show you
9:30 AM
Jiri
as an example
what i mean is the more fields you get the more boolean && or || you need
can you construct this dynamically based on the paramaters passed in the function
Mark M.
what boolean combinations are you trying to support?
Jiri
just and / or
Mark M.
you might be able to use the decorator pattern, to build up a Predicate that does one test plus chains to a wrapped Predicate
Jiri
hmmm ok need to look into that
decorator is this like a combination of predication
sub-predicts
predicates
9:35 AM
Jiri
i have seen this somewhere
Mark M.
or, use the composite pattern
in your code, for example, you could have a TypeIdFilter that just checks for typeId rules, an OrderTypeIdFilter that just checks for orderTypeId, and so forth
then have a CompositeFilter that has a collection of filters and knows the rule to use to combine their results
Jiri
hmm ok. interesting
Mark M.
adding a scripting language feels like a very heavyweight solution
Jiri
i will look into it
yeah true
its only for "internal use" not user facing
but you are right
overkill
Mark M.
middle ground would be an expression evaluator, though I don't know if any of the classic Java ones work on Android
Jiri
ok thanks
i will check it after the more basic stuff works
thanks and probably talk to you someday for some more q.
have a nice day
Mark M.
you too!
10:00 AM
Jiri
has left the room
Mark M.
turned off guest access

Yesterday, November 19

 

Office Hours

People in this transcript

  • Jiri
  • Mark Murphy

Files in this transcript