{"id":13473762,"url":"https://github.com/ahmedeltaher/Android-MVP-Architecture","last_synced_at":"2025-03-26T19:34:42.256Z","repository":{"id":134521466,"uuid":"76900756","full_name":"ahmedeltaher/Android-MVP-Architecture","owner":"ahmedeltaher","description":"MVP + Kotlin + Retrofit2 + Dagger2 + Coroutines + Anko + Kotlin-Android-Extensions + RX-java + Mockk + Espresso + Junit5","archived":false,"fork":false,"pushed_at":"2019-11-06T21:39:32.000Z","size":424,"stargazers_count":100,"open_issues_count":1,"forks_count":26,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T08:11:17.581Z","etag":null,"topics":["android","android-architecture","android-cleanarchitecture","android-mvp","clean-architecture","clean-code","dagger2","dagger2-mvp","mvp","mvp-architecture","retrofit2","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmedeltaher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-19T22:01:01.000Z","updated_at":"2024-11-18T02:37:21.000Z","dependencies_parsed_at":"2023-06-17T06:00:30.838Z","dependency_job_id":null,"html_url":"https://github.com/ahmedeltaher/Android-MVP-Architecture","commit_stats":null,"previous_names":[],"tags_count":1,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedeltaher%2FAndroid-MVP-Architecture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedeltaher%2FAndroid-MVP-Architecture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedeltaher%2FAndroid-MVP-Architecture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedeltaher%2FAndroid-MVP-Architecture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmedeltaher","download_url":"https://codeload.github.com/ahmedeltaher/Android-MVP-Architecture/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245722917,"owners_count":20661849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-architecture","android-cleanarchitecture","android-mvp","clean-architecture","clean-code","dagger2","dagger2-mvp","mvp","mvp-architecture","retrofit2","unit-testing"],"created_at":"2024-07-31T16:01:06.638Z","updated_at":"2025-03-26T19:34:39.488Z","avatar_url":"https://github.com/ahmedeltaher.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# [Model–view–presenter (MVP)](https://github.com/ahmedeltaher/Android-MVP-Architecture)\n  \n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-android--best--practices-brightgreen.svg?style=flat)](https://android-arsenal.com/details/3/4975)  [![kotlin](https://img.shields.io/badge/Kotlin-1.3.xxx-brightgreen.svg)](https://kotlinlang.org/)  [![coroutines](https://img.shields.io/badge/coroutines-asynchronous-red.svg)](https://kotlinlang.org/docs/reference/coroutines-overview.html) [![ANKO](https://img.shields.io/badge/Anko-commons-blue.svg)](https://github.com/Kotlin/anko) [![Mockk](https://img.shields.io/badge/Mockk-testing-yellow.svg)](https://mockk.io/)      [![Junit5](https://img.shields.io/badge/Junit5-testing-yellowgreen.svg)](https://junit.org/junit5/)   [![Espresso](https://img.shields.io/badge/Espresso-testing-lightgrey.svg)](https://developer.android.com/training/testing/espresso/)  [![Dagger 2](https://img.shields.io/badge/Dagger-2.xx-orange.svg)](https://google.github.io/dagger/)  [![Kotlin-Android-Extensions ](https://img.shields.io/badge/Kotlin--Android--Extensions-plugin-red.svg)](https://kotlinlang.org/docs/tutorials/android-plugin.html) [![MVVM ](https://img.shields.io/badge/Clean--Code-MVVM-brightgreen.svg)](https://github.com/googlesamples/android-architecture)  ![MVP ](https://img.shields.io/badge/Clean--Code-MVP-brightgreen.svg)  \n  \n  \n![androkotlin](https://user-images.githubusercontent.com/1812129/68315997-facddf80-00b8-11ea-81f7-64980da690f1.png)![android-mvp-flow](https://user-images.githubusercontent.com/1812129/68316088-1e912580-00b9-11ea-9a1d-717afa920318.png)  \n  \nModel–view–presenter (MVP) is a derivation of the model–view–controller (MVC) architectural pattern which mostly used for building user interfaces. In MVP, the presenter assumes the functionality of the “middle-man”. In MVP, all presentation logic is pushed to the presenter.\nCheck here for [MVVM](https://github.com/ahmedeltaher/Android-MVVM-architecture)   \n  \n**What is Coroutines ?**  \n-------------------  \n **Coroutines :**  \nIs light wight threads for asynchronous programming, Coroutines not only open the doors to  \nasynchronous programming, but also provide a wealth of other possibilities such as concurrency, actors, etc.  \n  \n**Coroutines VS RXJava**  \n-------------------  \nThey're different tools with different strengths. Like a tank and a cannon, they have a lot of overlap but are more or less desirable under different circumstances.  \n        - Coroutines Is light wight threads for asynchronous programming.  \n        - RX-Kotlin/RX-Java is functional reactive programming, its core pattern relay on  \n        observer design pattern, so you can use it to handle user interaction with UI while you  \n        still using coroutines as main core for background work.  \n  \n**How does Coroutines concept work ?**  \n------------  \n - Kotlin coroutine is a way of doing things asynchronously in a sequential manner. Creating a coroutine is a lot cheaper vs creating a thread.  \n  \n  \n**When I can choose Coroutines or RX-Kotlin to do some behaviour ?**  \n--------------------------  \n - Coroutines : *When we have concurrent tasks , like you would fetch data from Remote connections  \n , database , any background processes , sure you can use RX in such cases too, but it looks like  \n  you use a tank to kill ant.*  \n - RX-Kotlin : *When you would to handle stream of UI actions like : user scrolling , clicks ,  \n update UI upon some events .....ect .*  \n  \n  \n**What is the Coroutines benefits?**  \n-----------------------------  \n  \n - Writing an asynchronous code is sequential manner.  \n - Costing of create coroutines are much cheaper to crate threads.  \n - Don't be over engineered to use observable pattern, when no need to use it.  \n - parent coroutine can automatically manage the life cycle of its child coroutines for you.  \n  \n  \n**Handle Retrofit with Coroutines**  \n-----------------------------  \n![8399](https://user-images.githubusercontent.com/1812129/68318999-e93b0680-00bd-11ea-9d76-058222c7a654.png)\n  \n - Add Coroutines to your gradle file  \n  \n\u003e     // Add Coroutines  \n\u003e     implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'  \n\u003e     implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'  \n\u003e     implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.2'  \n\u003e     // Add Retrofit2  \n\u003e     implementation 'com.squareup.retrofit2:retrofit:2.6.2'  \n\u003e     implementation 'com.squareup.retrofit2:converter-gson:2.6.2'  \n\u003e     implementation 'com.squareup.okhttp3:okhttp:4.2.2'  \n  \n  \n- Make Retrofit Calls.  \n  \n\u003e     @GET(\"topstories/v2/home.json\")  \n\u003e     fun fetchNews(): Call\u003cNewsModel\u003e  \n  \n  \n - With ```async``` we create new coroutine and returns its future result as an implementation of [Deferred].  \n - The coroutine builder called ```launch``` allow us to start a coroutine in background and keep working in the meantime.  \n - so async will run in background then return its promised result to parent coroutine which  \n created by launch.  \n - when we get a result, it is up to us to do handle the result.  \n  \n  \n  \n  \n  \n\u003e     launch {  \n\u003e       try {  \n\u003e             val serviceResponse: Data? = withContext(Dispatchers.IO) { dataRepository.requestNews()  \n\u003e            }  \n\u003e       if (serviceResponse?.code == Error.SUCCESS_CODE) {  \n\u003e                 val data = serviceResponse.data  \n\u003e                 callback.onSuccess(data as NewsModel)  \n\u003e             } else {  \n\u003e                 callback.onFail(serviceResponse?.error)  \n\u003e             }  \n\u003e         } catch (e: Exception) {  \n\u003e                 callback.onFail(Error(e))  \n\u003e         }  \n\u003e     }  \n  \n  \n**Keep your code clean according to MVP**  \n-----------------------------  \n - yes , RXAndroid is easy , powerful , but you should know in which MVP  \n          layer you will put it .  \n - for observables which will emit data stream , it has to be in your  \n   data layer , and don't inform those observables any thing else like  \n   in which thread those will consume , cause it is another  \n   responsibility , and according to `Single responsibility principle`  \n  in `SOLID (object-oriented design)` , so don't break this concept by  \n   mixing every thing due to RXAndroid ease .  \n  \n  \n![MVP](https://user-images.githubusercontent.com/1812129/68315449-14baf280-00b8-11ea-99ff-8dcfc4dfdcd3.jpg)  \n  \n  \n  \n----------  \n**LICENSE**  \n-------------------  \n  \n  \nCopyright [2016] [Ahmed Eltaher]  \n  \nLicensed under the Apache License, Version 2.0 (the \"License\");  \nyou may not use this file except in compliance with the License.  \nYou may obtain a copy of the License at  \n  \n http://www.apache.org/licenses/LICENSE-2.0  \nUnless required by applicable law or agreed to in writing, software  \ndistributed under the License is distributed on an \"AS IS\" BASIS,  \nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  \nSee the License for the specific language governing permissions and  \nlimitations under the License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedeltaher%2FAndroid-MVP-Architecture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmedeltaher%2FAndroid-MVP-Architecture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedeltaher%2FAndroid-MVP-Architecture/lists"}