MVP Android Example

Overview
Comments
  • Is this package structure correct?

    Is this package structure correct?

    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?

    udklip

    opened by Muddz 6
  • More advanced use cases

    More advanced use cases

    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.

    opened by Knight704 6
  • Interactor being instantiated in the View

    Interactor being instantiated in the View

    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!

    opened by noloman 4
  • DI with your MVP example

    DI with your MVP example

    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:

    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:

    image

    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 :(

    opened by juliolopeztorres 2
  • Where to reach domain layer from MVP

    Where to reach domain layer from MVP

    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 :

    • my pres layer with MVP
    • my domain layer, pure Java classes, no Android sdk classes

    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 ^^'

    opened by mfrachet 2
  • Small thing but critical issue. Added 'return' in if--else logic in LoginInteractorImpl.java

    Small thing but critical issue. Added 'return' in if--else logic in LoginInteractorImpl.java

    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.

    opened by TakeoffAndroid 2
  • Scrren rotation

    Scrren rotation

    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

    opened by spartacus777 2
  • Add formatter to main presenter

    Add formatter to main presenter

    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.

    opened by danielgomezrico 2
  • Import this project

    Import this project

    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

    opened by simonides 2
  • inject LoginInteractorImpl

    inject LoginInteractorImpl

    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

    opened by Sanpetch 1
  • Mvp with dagger2

    Mvp with dagger2

    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.

    opened by alinhayati 1
Owner
Antonio Leiva
Freelance trainer. I help you and your company to become Kotlin experts. GDE and Jetbrains Training Partner.
Antonio Leiva
🎓 Learning Kotlin Coroutines for Android by example. 🚀 Sample implementations for real-world Android use cases. 🛠 Unit tests included!

Kotlin Coroutines - Use Cases on Android ?? Learning Kotlin Coroutines for Android by example. ?? Sample implementations for real-world Android use ca

Lukas Lechner 2.1k Jan 3, 2023
Example of Android project showing integration with Kotlin and Dagger 2

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

Damian Petla 533 Nov 11, 2022
📌This repo contains the kotlin implementation of TensorflowLite Example Android Apps🚀

TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java

Sunit Roy 28 Dec 13, 2022
Android Example project

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

null 0 Nov 21, 2021
A clean architecture example. Using Kotlin Flow, Retrofit and Dagger Hilt, etc.

android-clean-architecture A clean architecture example. Using Kotlin Flow, Retrofit and Dagger Hilt, etc. Intro Architecture means the overall design

Prieyudha Akadita S. 69 Dec 21, 2022
Spring Boot Example with Kotlin and Domain Driven Design

Spring Boot Kotlin Domain Driven Design Example Just an example project where ddd is implemented with some other great patterns and architecture from

Fernando Guevara Sanchez 16 Jun 29, 2022
This is an example of a simple application with layered software base on clean-architecture as application architecture and mvvm as presentation architecture

This is an example of a simple application with layered software base on clean-architecture as application architecture and mvvm as presentation archi

null 3 Jul 2, 2021
A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations.

kotlin-ktor-rest-api A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations. F

Selim Atasoy 32 Dec 20, 2022
An example project for configuring Rust with Java 18's Panama/jextract

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

Aidan 14 Jul 5, 2022
FunFacts is an example of Modular architecture

FunFacts FunFacts is an example of Modular architecture This Project is built using Kotlin,we will use in this App : Modular architecture Dependency I

Sachin Rajput 48 Jan 1, 2023
Example project for using the Selenium toolkit with Kotlin, Maven, TestNg and the config is managed via a property file.

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

Selenium Consulting 0 Dec 15, 2021
Spring for Kotlin Example

Spring for Kotlin Example This project is for studying the spring using by kotlin. Required docker-compose Running project docker-compose -f docker-co

null 0 Nov 10, 2021
grpc stream fullstack example(spring+kotlin / next.js + typescript)

grpc-stream-fullstack chat application build with grpc named qhat Prerequisites server sync .proto files on src/main/proto/grpc/qhat/ $ ./gradlew sync

Dave Kwon 5 Nov 14, 2022
Hexagonal Architecture Java Example

Hexagonal Architecture Dev.to Hexagonal Architecture Article I have been working on many projects that claim to be using the Hexagonal Architecture St

null 17 Dec 21, 2022
R2DBC Sharding Example with Kotlin Coroutine

R2DBC Sharding Example with Kotlin Coroutine A minimal sharding example with R2DBC and coroutine, where user table is divided into 2 different shards.

K.S. Yim 0 Oct 4, 2021
An example of a SQS consumer using Micronaut

Micronaut 3.0.3 Documentation User Guide API Reference Configuration Reference Micronaut Guides Feature http-client documentation Micronaut HTTP Clien

Matheus Ferreira 1 Apr 1, 2022
Spring boot kotlin example

Spring Boot Kotlin Example Gradle 配置 代理配置 当内网环境需要代理时,在项目根目录添加文件 gradle.propertie

null 0 Jan 17, 2022
Webclient-kotlin-sample - An example of using the http web client to promote synchronous and asynchronous https calls

Web Client Consumer Kotlin Sample The project is an example of using the http we

null 1 May 1, 2022
Muhammad Valian Masdani 2 Jul 5, 2022