Nov 20 | 8:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Nov 20 | 9:00 AM |
Jiri | has entered the room |
Mark M. |
hello, Jiri!
|
Mark M. |
how can I help you today?
|
Jiri |
Hi
|
Jiri |
thank you
|
Jiri |
i wish to thank you for your great book and content
|
Jiri |
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)
|
Jiri |
and the rest of the program in a MVVM way
|
Nov 20 | 9:05 AM |
Jiri |
its about updating the UI
|
Nov 20 | 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
|
Jiri |
true. but your book helped me with the clear use cases of flowable and maybe of a list of type x
|
Jiri |
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
|
Jiri |
lets say i do an async call to a webservice
|
Jiri |
write to the db
|
Jiri |
all fine
|
Jiri |
but the service need to signal in the backend to the viemmodel/recyclerview that a new async call neeeds to be launched
|
Jiri |
to fetch the data in the db
|
Jiri |
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
|
Jiri |
this is done like this
|
Jiri |
yes repository
|
Jiri |
but as i dont use flowable
|
Jiri |
i will not get notified
|
Jiri |
...
|
Jiri |
of updates
|
Jiri |
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
|
Mark M. |
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)
|
Nov 20 | 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
|
Jiri |
the tests that i have done alreayd
|
Jiri |
view - viewmodel with livedata only
|
Jiri |
all works fine
|
Jiri |
but missing a lot of functionality from rxjava for filtering etc
|
Jiri |
not an optin
|
Jiri |
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
|
Jiri |
so filter doesnt execute
|
Nov 20 | 9:15 AM |
Jiri |
tried with flowable only
|
Jiri |
maybe streams is different
|
Jiri |
this is why i ended up with maybe based on your book
|
Jiri |
but maybe is one time only
|
Jiri |
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?
|
Mark M. |
(referring back to your code snippet)
|
Jiri |
List<DetailedOrders>
|
Jiri |
its a POJO of table joins
|
Mark M. |
that's not possible
|
Mark M. |
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
|
Mark M. |
if you have that return Observable<List<OrderDetailed>>, AFAIK you should get updates pushed to you
|
Mark M. |
though your query may be too complex for Room to handle
|
Nov 20 | 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
|
Jiri |
filter didnt work
|
Jiri |
no oncomplete
|
Jiri |
rxjava itself would break
|
Jiri |
not the return from db
|
Mark M. |
there has to be an Rx operator that filters in onNext() rather than onComplete()
|
Jiri |
well...
|
Jiri |
i used a subject to force a publish of next and oncomplete
|
Jiri |
but that gave other problems
|
Jiri |
i have tried a lot. this is why i came to the Guru
|
Jiri |
:-)
|
Mark M. |
well, it's difficult for me to help you, given that I don't have your project to run
|
Mark M. |
this is the sort of thing that I'd sit and have to experiment with
|
Jiri |
sure I understand
|
Jiri |
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
|
Jiri |
i will look into this event bus for signalling
|
Jiri |
as an idea
|
Mark M. |
OK
|
Jiri |
ok thanks for your time and feedback
|
Nov 20 | 9:25 AM |
Mark M. |
sorry I could not be of greater assistance
|
Nov 20 | 9:25 AM |
Jiri |
ah maybe on more
|
Jiri |
if i can
|
Mark M. |
go right ahead!
|
Jiri |
i've looked into this predicate / filter setup. it works smoothly
|
Jiri |
do you think there's a way to create dynamic evaluation of these boolean construct ?
|
Jiri |
lets say i would like 5 fields
|
Jiri |
which could be all null or any combination of search filters
|
Jiri |
instead of manually combining them with if / else etc
|
Jiri |
is there a way to construct it dynamically based on non-null
|
Jiri |
i have seen there are scripting evaluation libraries which can be used in java
|
Jiri |
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
|
Nov 20 | 9:30 AM |
Jiri | |
Jiri |
as an example
|
Jiri |
what i mean is the more fields you get the more boolean && or || you need
|
Jiri |
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
|
Jiri |
decorator is this like a combination of predication
|
Jiri |
sub-predicts
|
Jiri |
predicates
|
Nov 20 | 9:35 AM |
Jiri |
i have seen this somewhere
|
Mark M. |
or, use the composite pattern
|
Mark M. |
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
|
Mark M. |
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
|
Jiri |
yeah true
|
Jiri |
its only for "internal use" not user facing
|
Jiri |
but you are right
|
Jiri |
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
|
Mark M. |
something like https://github.com/uklimaschewski/EvalEx
|
Jiri |
ok thanks
|
Jiri |
i will check it after the more basic stuff works
|
Jiri |
thanks and probably talk to you someday for some more q.
|
Jiri |
have a nice day
|
Mark M. |
you too!
|
Nov 20 | 10:00 AM |
Jiri | has left the room |
Mark M. | turned off guest access |