androidmvp
MVP Android Example used to explain how to use this pattern in our Android apps. This code was created to support an article explanation:
MVP Android Example used to explain how to use this pattern in our Android apps. This code was created to support an article explanation:
In my attempt to understand MVP I have structured the classes in their own package, where each packaged is named as: model, view, presentor, in respect to the classes role. Is it correctly done?
Could you share some tips for more advanced scenarios. By this I mean cases, when we should somehow interact with android framework layer. Let's say we wanted to login via Google Signin (from Google Play Services), this approach requires GoogleApiClient and tightly coupled to method onActivityResult. This is just an example, for simplicity it could be slightly changed.
From my point of view example provided is great, very simple and intuitive, but when it comes to real use cases, questions appears.
Cheers.
In the MainActivity you're creating the Presenter by passing in a new instance of the interactor. That means that the view knows about an inner layer of the app, which is that interactor. Should it be like that? In theory, the view should only know about its closest inner layer, which is the presenter, but it shouldn't know about that interactor.
Thanks and good job!
Hi there!
First of all, very nice and clear example of how MVC could be implemented. I have a couple of questions about it.
On one hand, as we can see in the following image:
I usually create/inject/use Domain Classes (my use cases) in Framework Layer directly. The above image show us that we could reach Domain Layer from Framework. I have re-structured your example in order to clarify C.A. concepts, thinking about Login component, as follow:
Now we can see how Framework (Android) has view components and "speaks" with Domain through LoginViewInterface, how Domain "talks" to Data Layer through LoginInteractorInterface (I usually call this Repositories/Services).
Communication is made through interfaces so that we are not violating any C.A. principles.
In your opinion, is that correct?
On the other hand, how could we implement DI (with Dagger 2 i.e.) in this example?
Let say, I would like to make a HTTP POST to BE in order to log me in. I would create a client (Retrofit + Okhttp i.e.) in Application Context and I would inject this client to Data Layer. Should I call Dagger in Data layer? Shoud I pass client's instance through from some where inside Framework Layer (Activity)?
Thank you in advance!
P.D.: I have tried to push a new branch with these changes and made a PR but I couldn't :(
I'm trying to understand this pattern, and it seems clearer and clearer. Im a javascript developer, and React Native made me want to learn more about native android dev.
I've got the point that MVP resides in the pres' layer. I've got the point that we also reach backend data thanks to interactors and getting some DTOs (aka model in our cases).
I use to work with remote domain layer, using REST APIs entrypoints. But sometime, I've to deal with client side logic for offline treats or state mutations, some stuff like that.
I know that I shouldn't put this kind of computation inside of the presentation layer, and I was thinking of "deduping" (not really, but using a simplified version of my remote domain) in another module my business domain.
But the problem still exists, I have now two modules :
But I don't know where to connect both of these to create a scaling architecture. Like, where should I call my domain services ? In interactor ? In presenter ?
I m a bit confused for this part ^^'
I have added 'return' in if--else logic in LoginInteractorImpl.java. I was doing null logic check for 5 to 6 edittext and it was throwing error in the 6th edittext because without return the if logic was executing till last. So i have added 'return' to return back when the error exists in the first loop. Please find the screens shot below. Awesome repo, thanks for this wonderful project.
What about screen rotation scenario? MVP helps majorly with it, and you did not implement it. Would be great if presenters would be saved during activity recreation (rotation) with the help, for ex. retainedFragment. I implemented on your example my MVP model, if it is right and you have time, implement it, please, your repo really hepls peaople understand mvp consept repo - https://github.com/spartacus777/MvpSample
The idea is to invert responsabilities so presenter dont know which format should be putted to view, just orchestrate' did not match any file(s) known to git.
Also may help to unit test it.
Are you still maintaining this code? I was not able to import this project into a IDE (Eclipse, Android studio) because there seems to be a problem with the src files. They are in the wrong directory. thx fridolin
I think in LoginPresenterImpl Class should inject LoginInteractorImpl in constructor because First, it will not make that constructor depend on another instance.Second, it will easy to mock and test
Thanks for your wonderful and pioneering work on MVP in android.
Having gone through your implementation, I found out that there is a direct coupling between View and Model in Line 48 of MainActivity.class
, which is not advisable in MVP pattern. I later realized that this was not written originally like this, but later added as a workaround to avoid using reflection in the unit testing of MainPresenterTest.class
.
To resolve both of the above issues, I refactored the code using Dependency Injection with Dagger 2 and used MainActivity.class
as the composition root along with Fragment to handle the view. I also revised the MainPresenterTest.class
to test the same five predefined tests without reflection.
I think the code is now even clearer to read and understand, thanks to your original prominent work.
Kotlin Coroutines - Use Cases on Android ?? Learning Kotlin Coroutines for Android by example. ?? Sample implementations for real-world Android use ca
kotlin-dagger-example This project demonstrate how to setup an Android Project with Kotlin and Dagger 2. It's based on Dagger 2 example ##Known issues
TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java
Example project for the employers. I created this project for the employers because I often get demands about showing some of my code. Patterns: MVP C
android-clean-architecture A clean architecture example. Using Kotlin Flow, Retrofit and Dagger Hilt, etc. Intro Architecture means the overall design
Spring Boot Kotlin Domain Driven Design Example Just an example project where ddd is implemented with some other great patterns and architecture from
This is an example of a simple application with layered software base on clean-architecture as application architecture and mvvm as presentation archi
kotlin-ktor-rest-api A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations. F
rust-panama A template project for setting up both Rust and the Java 18 Panama Foreign Linker API (via jextract). How to Setup Clone the repo. Modify
FunFacts FunFacts is an example of Modular architecture This Project is built using Kotlin,we will use in this App : Modular architecture Dependency I
Selenium-Java-Toolkit-TestNg-Playground This is the sample-Project and show you how to use the Selenium-Toolkit. The Selenium-Toolkit is a Java based
Spring for Kotlin Example This project is for studying the spring using by kotlin. Required docker-compose Running project docker-compose -f docker-co
grpc-stream-fullstack chat application build with grpc named qhat Prerequisites server sync .proto files on src/main/proto/grpc/qhat/ $ ./gradlew sync
Hexagonal Architecture Dev.to Hexagonal Architecture Article I have been working on many projects that claim to be using the Hexagonal Architecture St
R2DBC Sharding Example with Kotlin Coroutine A minimal sharding example with R2DBC and coroutine, where user table is divided into 2 different shards.
Micronaut 3.0.3 Documentation User Guide API Reference Configuration Reference Micronaut Guides Feature http-client documentation Micronaut HTTP Clien
Spring Boot Kotlin Example Gradle 配置 代理配置 当内网环境需要代理时,在项目根目录添加文件 gradle.propertie
Web Client Consumer Kotlin Sample The project is an example of using the http we
What is this Microservice gRPC demonstration w/incrementing state in multiple la