Android MVP implementation - android

i came across a few articles talking about the subject but i cannot understand how to apply MVP on my app code. is there any specific guidelines for a clean MVP implementation for android.
thank you

Checkout this link:
Material movies
MVPAndroidBootstrap
Clean-Contacts
MvpCleanArchitecture
Android-CleanArchitecture
At this links you will find a lot of MVP implementations for android
UPDATED:
mosby - A Model-View-Presenter library for modern Android apps
ThirtyInch - A new MVP library for Android
Moxy - Android MVP library without problems of lifecycle and boilerplate code
UPDATED:
Interesting-Android-repositories - contains a lot MVP implementations for Android.

Here on github
https://github.com/saksham24/Android-Firebase-Mvp-Mvc-Mvvm-chat
i made a repo containing 3 applications with same functionality but written in 3 different android patterns(Mvc, Mvp, Mvvm)
Understanding three different pattern is quite easy if we get a simple good example on them so i made a repo to contribute my knowledge to this developer community.
Also the repository is written using proper java guidelines and conventions(including naming and packages, modules) so people looking for such project can also view this repository.

I've recently created lightweight (with no overhead dependencies) MVP library in Kotlin. It also supports LiveData subscription between Presenter and Model under the hood.
Please find detailed "how-to" and sources here: https://github.com/smaslenko/instant-mvp

Related

References for MVP for Android

I want to implement MVP pattern for my Android application along with Dagger and RealmDB. I am a complete noob in these concepts. I have referred https://android.jlelse.eu/mvp-dagger-2-rx-clean-modern-android-app-code-74f63c9a6f2f . The blog post though good lacks a bit of explanation about the code demonstrated.
Can anyone recommend good blog posts with explanations which I can follow to implement MVP, Dagger and RealmDb in my app? Any help is highly appreciated.
first I say check ORM's benchmark and choice your decide about your ORM. Don't worry about learning new ORM because it's too easy. here is a benchmark of ORM's ORM's benchmark
Architecture One
first choice is using MVVM. This is a good architecture that you can find many article and blogs in internet. The best benefit if MVVM is you can use is beside data binding that is a great library that support by google and is very useful. Databinding make your project more scale-able and easy to maintenance.
Architecture two
Second Article is going beyond MVVM and databinding. It's using Android Architecture Components . It's couples of component's that introduce and support by google. this components include Databinding,LiveData,Lifecycle,ViewModel,RoomDB,... that google has a good documentation for them and how to use them together.
benefits of this architecture can find in this sentence from google:
Android architecture components are a collection of libraries that
help you design robust, testable, and maintainable apps

Which is better for Android MVVM package by feature or package by layer?

Another "which is better" question, I know these are highly subjective. My definition for better would be:
Being used by the best dev teams
Best for unit testing
Most modular / easiest to build out a prod app
What Google recommends (this is where I'm most confused)
All of the Android blueprints use package-by-feature:
https://github.com/googlesamples/android-architecture
/tasks
/addedittask
/taskdetail
and all of the architecture components samples using package by layer:
https://github.com/googlesamples/android-architecture-components
/db
/model
/ui
/persistence
I'm confused because at the bottom of the Architecture Components site, it actually has links to the Android MVP and MVVM blueprint samples, which seems to me to be contradictory.
Based on Android Architecture guide, and on Clean Architecture, I would suggest this approach
data/
model/
remote/
local/
Repository
domain/
usecases/
GetUserListUseCase
presentation/
screen1/
screen1Activity
screen1Fragment
screen1ViewModel
screen2/
screen2Activity
screen2Fragment
screen2ViewModel
core
common/
di/
More here: https://www.toptal.com/android/android-apps-mvvm-with-clean-architecture
I think it depends on project size. Also in different companies team use different approaches.
I prefer to use in a small project second type of package managing.
If you want to reuse ModelView component, just keep them in feature packages. And maybe with this type:
/db
feature1/
feature2/
/model
feature1/
feature2/
/ui
/persistence
feature1/
feature2/

Files structure in MVVM (Android)

using MVVM or MVP should i name packages like model, viewmodel, view and put proper classes and interfaces there or is it just a logical structure that should not be visible in classes structure?
If you want to go by the book, the current "correct" way to implement MVVM in Android is the Android Architecture Components set of libraries.
Read more about it here, and try this code lab. These will also show you how to name and place your classes.
But in general, you should go with what matches your app best. For smaller apps I would recommend going with M V P folders, while for bigger, more long-term ones tend to work better with folder-per-feature structure.
Google in it's sample Android Architecture project uses Model(Data) V(views) VM(view-models) file structure
Google sample sunflower app to show architecture components
Probably that's the best approach
Additionnaly you may find this resource interesting https://overflow.buffer.com/2016/09/26/android-rethinking-package-structure/
An implementation is visible here https://github.com/SamYStudiO/beaver
I also would like to indicate watching this TUTORIAL.
This guy goes well on teaching about the Architecture MVVM and also uses the ROOM Persistence Library.
It is worth giving a look at it.

Android architecture components with MVP

New Android Architecture Components released on google IO 17.
So should we use MVP with architecture components and MVVM?
In google sample on Github, they have used the MVVM model.
Google Sample
About the selection of architectural pattern and its implementation, it always depends on many factors such as team members, app's types, and so on.
In Google's blog post, they have already said that Architecture Components are mainly
Opinions not Prescriptions.
However, three main components (Room, ViewModel, ViewData) are developed with wide-range usage but not focus on any specific pattern.
For example,
If you are using SQLite to persist local data in your app, you can
you Room no matter what kind of pattern you are using, it is really a
great library with a lot of benefits such as reducing boiler plate
codes, validating SQLite syntax in compilation time, etc.
Besides, LifeCycle, LiveData, and ViewModel have their own strong
points. Especially, they address lifecycle-handling issues really well.
LiveData gives you one more tool of observer pattern which handles data stream reactively. (Like a great feature RxJava provides us).
...
At the end, for your question.
So should we use MVP with architecture components?
The answer is "it's nice part of Android framework, so why not".
Updated:
If you want to see how a MVP pattern project works with new Architecture Components, please checkout my repository on Github. In which I enhance previous MVP model by using Room for local persistence and LifeCycle to create lifecycle-aware Presenter.
I'm currently building a template project that uses MVP pattern along with Google Architecture components (Room, LiveData), and compare to mix version of Realm and LiveData:
https://github.com/duyp/mvp-template
I think some of Google Architecture Components are compatible with MVP Pattern, not only for MVVM :D
You can check out 2 following branches:
realm_livedata: MVP with Realm and LiveData
room_livedata: MVP with Room persistence library and LiveData
It's much more complex than Google sample project (I used Dagger 2, RxAndroid, Retrofit, Gson, and clean architecture) hope you find a better solution for your work. If any question or suggestion, you can leave comments or issues on my github project.
I also created a project using MVVM with new Google architecture components with Realm, Dagger 2, Live data: https://github.com/duyp/mvvm-template
Happy coding!

Is Model View Presenter and Dependency Injenction becoming a new Standard for Android Development?

In the last period i am having the chance to develop some apps for personal reason, and taking a look to what today the companies are organizing their work in the Android Ecosystem i encountered many and many times this kind of project configuration:
MVP (Model-View-Presenter) as Design Pattern for app architecture;
RxJava for Reactive programming event-based;
Dagger2 for dependency injection;
ButterKnife for fields binding with annotations, used in combo with Dagger2 in order to make your life simplier;
Espresso and Mockito for testing (really nice to use in this kind of environment with this kind of settings)
So, is this becoming a new standard, in your opinion? If so, do you think that is a good idea apply this (relatively) new guidelines and you usually use this kind of project tools/pattern/libraries into your apps or you think there is something better? If you don't like, it, why? What do you think could be a better approach?
(Obviously each project is different, and for each project is always better engineerize the best solution/architecture possible for the kind of users/team/dev involved. I am trying to understand/discuss this kind of model that seems to become widely used in his concept in many, many companies)
Thank you for your time, i hope to create an interesting discussion on the argument in order to all improve our skillset/projects.
Enjoy your day!
We can not say above methods as standard because Android-Sdk does not have any official support from its Libraries and API's. But As far as development environment is considered now a days Developers are using these methods for writing better code base for their apps, better understanding for future development.
As per my knowledge using these libraries is useful only if they have good support from developers as these are open source libraries. For example I am using AndroidMVC right now for MVP pattern. As per my knowledge this is very good library as I am using it since last year but As there is only one developer working on that library, it's very hard to get support for bug fixes(forget about enhancements).
So while selecting any open source library you should always look all the parameters like support, enhancements, bugs etc.
Libraries like Glide, ButterKnife, OkHttp, Couchbase lite, retrofit, Volley etc are some evergreen libraries of Android.
But again OkHttp, Retrofit and Volley are used for similar purpose i.e. for networking. Now developer have to choose according to pros and cons of each library.
As far as question - should we use libraries or not? is considered. I think YES. We should use these kind of libraries which are stable because it saves lot of time and it's not of use rewriting the code if we already have it in form of library.

Categories

Resources