https://kotlinlang.org logo
#android
Title
# android
n

nicktz

09/12/2017, 11:42 PM
also whats the general consensus on MVP vs MVVM + data-binding?
k

kagomez

09/13/2017, 12:07 AM
like an official consensus?
g

gildor

09/13/2017, 1:50 AM
There is no consensus. Use what is better for you. Actually even with data-binding you can use Presenters and it’s good practice. This is some kind of official position, but not a rule:

https://youtu.be/Ts-uxYiBEQ8?list=PLOU2XLYxmsIJz-cYWfjQP8SV7n8C-PTVm&t=545

My IMHO that data-binding library is great and helps a lot, you just need some rules like “do not leak context to ViewModel”, “keep ViewModel clean” etc. But it removes a lot of code and make your code more testable, much less pain and boilerplate code comparing with MVP
🎖️ 1
s

sss

09/13/2017, 7:08 AM
@gildor is there a starter-project to see the idiomatic usage of Architecture Components with Rx and Dagger ? Have been struggling to see how they fit together
g

gildor

09/13/2017, 7:09 AM
But Dagger and Rx don’t have anything related, I don’t see how they should fit
Architecture Components is a set of libraries, depending on what you want to use
s

sss

09/13/2017, 7:13 AM
well - its not fit together in the hard sense, but more on how they are layered together and used. All of these are not just plain libraries, but also a way of thinking about structure - and that's where im stuck. (if that makes sense ?)
g

gildor

09/13/2017, 7:15 AM
Dagger is just DI framework, you can use it almost with any library and I don’t see any incompatibilities. And yes, it’s one of layers of your app that does dependency injection and gives you inversion of control, nothing related to RxJava, Room or any other library
Architecture Components is not one library, depending on your case Room has RxJava2 support out of the box RxLifecycle provides adapter for AC Lifecycle, if you want to use it for resource managing LiveData is of course some kind light reactive library but with very specific domain. You can check video, that I posted above, they have a few words how do they see LiveData and Rx work in the same app, of course if you have Rx
So I think your question is too abstract to answer on it. I just don’t see any specific issues. If you need RxJava just use it, if you don’t need, don’t use Same for Dagger or any other library
s

sss

09/13/2017, 7:31 AM
well my question comes off like that because we have a large legacy codebase that already uses Dagger and RxJava. So we are beginning by asking the question "how should we refactor it". That's why my question is more around "how do these libraries fit together". For a person beginning a new project, you are right - your answer makes perfect sense
g

gildor

09/13/2017, 7:35 AM
how should we refactor it
Dagger and RxJava fit perfectly, because they responsible for completely different things If you have problems with your legacy code, I think you should solve those problems, instead of replacing one library with another or thinking about possible library incompatibility, especially if they already in your code
You can replace some parts written on RxJava with LiveData, but only some of them, and you actually need real reason for that
s

sss

09/13/2017, 7:37 AM
im kind of not asking what to replace it with - my doubt came from the introduction of viewmodels. so I see lots of newer articles on the web about how rxjava and viewmodels work together, so was kind of unsure on how these things work together. so i was hoping there was kind of a nice starter project with all of these components which i can see and learn from.
for example - take a look at this thread and see how many people dispute the right patterns. so i was wondering what does the kotlin community think of it. https://github.com/googlesamples/android-architecture/issues/138
g

gildor

09/13/2017, 7:42 AM
This thread about very particular architecture: MVVM with RxJava, without databindings. It’s one of possible ways, same as many others. I know people who use it, but personally don’t like this, MVVM based on databindings looks better for me
And I don’t see anything related to Kotlin in this particular discussion about architecture approach
s

sss

09/13/2017, 7:46 AM
some others would refuse to do it this way and highly recommend Anko. I dont see any problem in asking this from a kotlin perspective.
g

gildor

09/13/2017, 7:48 AM
Anko is just way to build UI, you can use any architecture with it
s

sss

09/13/2017, 7:49 AM
a lot of people say that Anko is not fairly current - and is lagging quite a bit. what do you think ?
g

gildor

09/13/2017, 7:50 AM
I don’t use Anko, I’m fine with xml, especially with DataBinding
s

sss

09/13/2017, 7:51 AM
thanks ! that was useful info.
g

gildor

09/13/2017, 7:52 AM
But not sure about lagging, because it’s just a way to build view hierarchy, and it should be faster, then xml inflating (that uses reflections), after View hierarchy creation I don’t think that any difference between anko, xml or view creation from code without dsl
d

dave08

09/13/2017, 6:00 PM
I use thirtyinch mvp lib, make all ui components into obsevables in the view, and all model functions return observables (singles or completables), then use the presenter as a glue to subscribe to view actions and model results and set view set as a result...