├── .gitignore ├── LICENSE ├── README.md ├── Untitled ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── in │ │ └── rrapps │ │ └── mvpdaggertesting │ │ └── movie │ │ └── MovieListActivityTest.java │ ├── debug │ ├── AndroidManifest.xml │ ├── java │ │ └── in │ │ │ └── rrapps │ │ │ └── mvpdaggertesting │ │ │ ├── DebugBaseApplication.java │ │ │ └── api │ │ │ ├── MockApiModule.java │ │ │ └── MockApiService.java │ └── res │ │ └── values │ │ └── strings.xml │ ├── debugProd │ └── res │ │ └── values │ │ └── strings.xml │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── in │ │ │ └── rrapps │ │ │ └── mvpdaggertesting │ │ │ ├── AppComponent.java │ │ │ ├── AppModule.java │ │ │ ├── BaseActivity.java │ │ │ ├── BaseApplication.java │ │ │ ├── BaseDrawerActivity.java │ │ │ ├── BaseFragment.java │ │ │ ├── BaseToolBarActivity.java │ │ │ ├── Constants.java │ │ │ ├── api │ │ │ ├── ApiModule.java │ │ │ └── ApiService.java │ │ │ ├── dao │ │ │ ├── DatabaseCallbacks.java │ │ │ ├── DatabaseInteractor.java │ │ │ ├── DatabaseWrapper.java │ │ │ └── MovieDataDao.java │ │ │ ├── database │ │ │ └── AppDatabase.java │ │ │ ├── dialogs │ │ │ ├── LoadingDialog.java │ │ │ └── ThemedInfoDialog.java │ │ │ ├── models │ │ │ ├── MovieData.java │ │ │ └── response │ │ │ │ ├── DiscoverResponse.java │ │ │ │ └── Result.java │ │ │ └── movie │ │ │ ├── Contracts.java │ │ │ ├── MovieComponent.java │ │ │ ├── MovieListActivity.java │ │ │ ├── MovieListAdapter.java │ │ │ ├── MovieListFragment.java │ │ │ ├── MovieListPresenter.java │ │ │ ├── MovieModule.java │ │ │ ├── MovieScope.java │ │ │ └── detail │ │ │ ├── Contracts.java │ │ │ ├── MovieDetailActivity.java │ │ │ ├── MovieDetailComponent.java │ │ │ ├── MovieDetailFragment.java │ │ │ ├── MovieDetailModule.java │ │ │ └── MovieDetailPresenter.java │ └── res │ │ ├── drawable-v21 │ │ ├── ic_menu_camera.xml │ │ ├── ic_menu_gallery.xml │ │ ├── ic_menu_manage.xml │ │ ├── ic_menu_send.xml │ │ ├── ic_menu_share.xml │ │ └── ic_menu_slideshow.xml │ │ ├── drawable-xxxhdpi │ │ └── ic_placeholder.png │ │ ├── layout │ │ ├── activity_base.xml │ │ ├── activity_base_drawer.xml │ │ ├── activity_base_toolbar.xml │ │ ├── activity_movie_detail.xml │ │ ├── activity_movie_list.xml │ │ ├── fragment_movie_detail.xml │ │ ├── fragment_movie_list.xml │ │ ├── fragment_themed_dialog.xml │ │ ├── layout_toolbar.xml │ │ ├── loading_dialog.xml │ │ ├── nav_header_base_drawer.xml │ │ └── view_movie_item.xml │ │ ├── menu │ │ ├── nav_drawer_menu.xml │ │ └── sort_menu.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── drawables.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── release │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── in │ └── rrapps │ └── mvpdaggertesting │ ├── APIAvailabilityTest.java │ └── MovieListPresenterTest.java ├── build.gradle ├── config └── quality │ ├── checkstyle.xml │ └── pmd.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── version.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | .DS_Store 6 | /build 7 | /captures 8 | /buildSrc/build 9 | 10 | !app/build-scripts.git/android/gradle-plugin/plugin/build 11 | !app/build-scripts.git/android/gradle-plugin/repo/com/chaione/build 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 moldedbits 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Android MVP Demo 2 | This project demonstrates Model-View-Presenter pattern in android. 3 | 4 | There are two screens in this demo app. 5 | First screen shows a list of movies using [The Movie Database](https://www.themoviedb.org/?language=en) open APIs. 6 | Second screen is a detail screen where user can see details about selected movie. This pretty much covers a real world scenario. 7 | 8 | Following notable libraries have been used in this project 9 | 1. [Retrofit 2](http://square.github.io/retrofit/) for API interaction 10 | 2. [Dagger 2](https://github.com/google/dagger) for dependency injection 11 | 3. [RxJava 2](https://github.com/ReactiveX/RxJava) for power of reactive programming 12 | 13 | I have used Dagger `SubComponents` to pass dependencies down in dependency graph. 14 | 15 | Here are some nice articles which helped me in learning `Dagger 2` and in building this demo project. 16 | 17 | 1. [Dependency Injection with Dagger 2- CodePath](https://guides.codepath.com/android/dependency-injection-with-dagger-2) 18 | 2. [Dependency injection with Dagger 2 - the API](http://frogermcs.github.io/dependency-injection-with-dagger-2-the-api/) 19 | 3. [Introduction to Dagger 2, Using Dependency Injection in Android: Part 2](https://blog.mindorks.com/introduction-to-dagger-2-using-dependency-injection-in-android-part-2-b55857911bcd) 20 | 4. [An Introduction to Dagger 2 (Android DI) – Part 1](https://dzone.com/articles/an-introduction-to-dagger-2-android-di-part-1-3) -------------------------------------------------------------------------------- /Untitled: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhishekBansal/android-mvp-retrofit2-dagger2-rxjava2-testing/a30f3c876ae4e7662b51fb29bb4df6a064359fe3/Untitled -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'checkstyle' 2 | apply plugin: 'com.android.application' 3 | 4 | checkstyle { 5 | toolVersion = '7.6.1' 6 | } 7 | 8 | preBuild.dependsOn 'checkstyle' 9 | check.dependsOn 'checkstyle' 10 | 11 | 12 | task checkstyle(type: Checkstyle) { 13 | configFile file("${project.rootDir}/config/quality/checkstyle.xml") 14 | source 'src' 15 | include '**/*.java' 16 | exclude '**/gen/**' 17 | exclude '**/test/java/in/rrapps/mvpdaggertesting/**' 18 | 19 | classpath = files() 20 | 21 | // set to false if you want to consider warning as error 22 | ignoreFailures = false 23 | } 24 | 25 | android { 26 | compileSdkVersion 27 27 | buildToolsVersion '27.0.0' 28 | 29 | final API_URL_DEV = "https://api.themoviedb.org/3/"; 30 | 31 | defaultConfig { 32 | applicationId "in.rrapps.mvpdaggertesting" 33 | minSdkVersion 23 34 | targetSdkVersion 27 35 | 36 | testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' 37 | 38 | // setting custom name for apk 39 | project.ext.set("archivesBaseName", "MVPDaggerTestingDemo-" + defaultConfig.versionName 40 | + "-vc" + defaultConfig.versionCode) 41 | } 42 | 43 | buildTypes { 44 | debug { 45 | minifyEnabled false 46 | buildConfigField 'String', 'API_URL', "\"" + API_URL_DEV + "\"" 47 | } 48 | } 49 | 50 | lintOptions { 51 | // set to true to turn off analysis progress reporting by lint 52 | quiet true 53 | // if true, stop the gradle build if errors are found 54 | abortOnError false 55 | // if true, only report errors 56 | ignoreWarnings false 57 | // if true, emit full/absolute paths to files with errors (true by default) 58 | //absolutePaths true 59 | // if true, check all issues, including those that are off by default 60 | checkAllWarnings true 61 | // if true, treat all warnings as errors 62 | warningsAsErrors false 63 | // turn off checking the given issue id's 64 | disable 'TypographyFractions', 'TypographyQuotes' 65 | // turn on the given issue id's 66 | enable 'RtlHardcoded', 'RtlCompat', 'RtlEnabled' 67 | // check *only* the given issue id's 68 | //check 'NewApi', 'InlinedApi' 69 | // if true, don't include source code lines in the error output 70 | noLines false 71 | // if true, show all locations for an error, do not truncate lists, etc. 72 | showAll true 73 | // Fallback lint configuration (default severities, etc.) 74 | lintConfig file("default-lint.xml") 75 | // if true, generate a text report of issues (false by default) 76 | textReport false 77 | // location to write the output; can be a file or 'stdout' 78 | textOutput 'stdout' 79 | // if true, generate an XML report for use by for example Jenkins 80 | xmlReport false 81 | // file to write report to (if not specified, defaults to lint-results.xml) 82 | xmlOutput file("build/reports/lint/lint-report.xml") 83 | // if true, generate an HTML report (with issue explanations, sourcecode, etc) 84 | htmlReport true 85 | // optional path to report (default will be lint-results.html in the builddir) 86 | htmlOutput file("build/reports/lint/lint-report.html") 87 | } 88 | 89 | compileOptions { 90 | targetCompatibility 1.8 91 | sourceCompatibility 1.8 92 | } 93 | } 94 | 95 | dependencies { 96 | implementation fileTree(include: ['*.jar'], dir: 'libs') 97 | implementation "com.android.support:appcompat-v7:$supportLibVersion" 98 | implementation "com.android.support:design:$supportLibVersion" 99 | implementation "com.android.support:support-v4:$supportLibVersion" 100 | 101 | // Use Retrofit for API interaction 102 | implementation 'com.squareup.retrofit2:retrofit:2.3.0' 103 | implementation 'com.squareup.retrofit2:converter-gson:2.3.0' 104 | implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0' 105 | 106 | // Lombok 107 | 108 | compileOnly 'org.projectlombok:lombok:1.16.18' 109 | annotationProcessor "org.projectlombok:lombok:1.16.18" 110 | 111 | // Timber for logging 112 | implementation 'com.jakewharton.timber:timber:4.5.1' 113 | 114 | // Butterknife for view injection 115 | implementation 'com.jakewharton:butterknife:8.8.1' 116 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 117 | 118 | // Dagger 2 119 | // Dagger 2 dependencies 120 | implementation 'com.google.dagger:dagger:2.11' 121 | annotationProcessor 'com.google.dagger:dagger-compiler:2.11' 122 | compileOnly 'org.glassfish:javax.annotation:10.0-b28' 123 | 124 | //Tests 125 | // Required -- JUnit 4 framework 126 | testImplementation 'junit:junit:4.12' 127 | androidTestImplementation "com.android.support:support-annotations:$supportLibVersion" 128 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 129 | androidTestImplementation 'com.android.support.test:rules:1.0.1' 130 | // Optional -- Mockito framework 131 | testCompile "org.mockito:mockito-core:2.10.0" 132 | // Optional -- UI testing with Espresso 133 | androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1' 134 | 135 | // RX Android 136 | implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion" 137 | implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion" 138 | implementation "io.reactivex.rxjava2:rxkotlin:$rxKotlinVersion" 139 | implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0" 140 | implementation 'com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:2.0.0' 141 | 142 | // Room 143 | implementation "android.arch.persistence.room:runtime:1.0.0" 144 | annotationProcessor "android.arch.persistence.room:compiler:1.0.0" 145 | implementation "android.arch.persistence.room:rxjava2:1.0.0" 146 | 147 | implementation 'jp.wasabeef:glide-transformations:3.0.1' 148 | 149 | compile 'com.github.bmarrdev:android-DecoView-charting:v1.2' 150 | androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2', { 151 | exclude group: 'com.android.support', module: 'support-annotations' 152 | exclude group: 'com.android.support', module: 'support-v4' 153 | exclude group: 'com.android.support', module: 'design' 154 | exclude group: 'com.android.support', module: 'recyclerview-v7' 155 | } 156 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/abhishek/Development/AndroidSDK/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | ## Retrofit 13 | -dontwarn retrofit2.** 14 | -keep class retrofit2.** { *; } 15 | -keepattributes Signature 16 | -keepattributes Exceptions 17 | 18 | ## butterknife 19 | -keep class butterknife.** { *; } 20 | -dontwarn butterknife.internal.** 21 | -keep class **$$ViewBinder { *; } 22 | 23 | -keepclasseswithmembernames class * { 24 | @butterknife.* ; 25 | } 26 | 27 | -keepclasseswithmembernames class * { 28 | @butterknife.* ; 29 | } 30 | 31 | ## Models 32 | -keepclassmembers class com.moldedbits.android.model.** { *; } 33 | 34 | ##Design library 35 | -dontwarn android.support.design.** 36 | -keep class android.support.design.** { *; } 37 | -keep interface android.support.design.** { *; } 38 | -keep public class android.support.design.R$* { *; } 39 | -dontwarn com.viewpagerindicator.** 40 | 41 | ## crashlytics 42 | -keep class com.crashlytics.** { *; } 43 | -dontwarn com.crashlytics.** 44 | 45 | ## Okio 46 | -dontwarn okio.** 47 | 48 | ## okhttp3 49 | -dontwarn okhttp3.** 50 | 51 | ## Rx Internal 52 | -dontwarn rx.internal.util.** 53 | -dontwarn rx.internal.schedulers.** 54 | 55 | ## glide 56 | 57 | -keep public class * implements com.bumptech.glide.module.GlideModule 58 | -keep public class * extends com.bumptech.glide.module.AppGlideModule 59 | -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { 60 | **[] $VALUES; 61 | public *; 62 | } 63 | 64 | # for DexGuard only 65 | -keepresourcexmlelements manifest/application/meta-data@value=GlideModule -------------------------------------------------------------------------------- /app/src/androidTest/java/in/rrapps/mvpdaggertesting/movie/MovieListActivityTest.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | 4 | import android.support.test.espresso.ViewInteraction; 5 | import android.support.test.rule.ActivityTestRule; 6 | import android.support.test.runner.AndroidJUnit4; 7 | import android.test.suitebuilder.annotation.LargeTest; 8 | 9 | import in.rrapps.mvpdaggertesting.movie.MovieListActivity; 10 | import in.rrapps.mvpdaggertesting.R; 11 | 12 | import org.junit.Rule; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | 16 | import static android.support.test.InstrumentationRegistry.getInstrumentation; 17 | import static android.support.test.espresso.Espresso.onView; 18 | import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu; 19 | import static android.support.test.espresso.action.ViewActions.click; 20 | import static android.support.test.espresso.matcher.ViewMatchers.withId; 21 | import static android.support.test.espresso.matcher.ViewMatchers.withText; 22 | import static org.hamcrest.Matchers.allOf; 23 | 24 | @LargeTest 25 | @RunWith(AndroidJUnit4.class) 26 | public class MovieListActivityTest { 27 | 28 | @Rule 29 | public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MovieListActivity.class); 30 | 31 | @Test 32 | public void movieListActivityTest() { 33 | 34 | openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext()); 35 | 36 | ViewInteraction appCompatTextView = onView( 37 | allOf(withId(R.id.title), withText("Most Popular"))); 38 | appCompatTextView.perform(click()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/debug/java/in/rrapps/mvpdaggertesting/DebugBaseApplication.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | 4 | //import in.rrapps.mvpdaggertesting.ApiComponent; 5 | //import in.rrapps.mvpdaggertesting.BaseApplication; 6 | 7 | public class DebugBaseApplication extends BaseApplication { 8 | // 9 | // ApiComponent apiComponent; 10 | // public void enableMockMode() { 11 | // apiComponent = DaggerMockApiComponent.create(); 12 | // } 13 | 14 | // @Override 15 | // public ApiComponent getApiComponent() { 16 | // return apiComponent; 17 | // } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/debug/java/in/rrapps/mvpdaggertesting/api/MockApiModule.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.api; 2 | 3 | import javax.inject.Singleton; 4 | 5 | import dagger.Module; 6 | import dagger.Provides; 7 | import in.rrapps.mvpdaggertesting.api.ApiService; 8 | 9 | @Module 10 | public class MockApiModule { 11 | 12 | @Provides 13 | @Singleton 14 | ApiService providesApiService() { 15 | return new MockApiService(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/debug/java/in/rrapps/mvpdaggertesting/api/MockApiService.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.api; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Map; 5 | 6 | import in.rrapps.mvpdaggertesting.models.response.DiscoverResponse; 7 | import io.reactivex.Observable; 8 | 9 | public class MockApiService implements ApiService { 10 | @Override 11 | public Observable getMoviesList(Map params) { 12 | DiscoverResponse response = new DiscoverResponse(); 13 | response.setResults(new ArrayList<>()); 14 | return Observable.just(response); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/debug/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MVPDaggerTestingDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/debugProd/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidJumpstart-DebugProd 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/AppComponent.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | import javax.inject.Singleton; 4 | 5 | import dagger.Component; 6 | import in.rrapps.mvpdaggertesting.api.ApiModule; 7 | import in.rrapps.mvpdaggertesting.movie.MovieComponent; 8 | import in.rrapps.mvpdaggertesting.movie.MovieModule; 9 | import in.rrapps.mvpdaggertesting.movie.detail.MovieDetailComponent; 10 | import in.rrapps.mvpdaggertesting.movie.detail.MovieDetailModule; 11 | 12 | /** 13 | * Created by abhishek 14 | * on 14/12/17. 15 | */ 16 | @Singleton 17 | @Component(modules = {AppModule.class, ApiModule.class}) 18 | public interface AppComponent { 19 | void inject(BaseApplication baseApplication); 20 | 21 | MovieComponent newMovieComponent(MovieModule movieModule); 22 | 23 | MovieDetailComponent newMovieDetailComponent(MovieDetailModule movieDetailModule); 24 | } -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/AppModule.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | import android.arch.persistence.room.Room; 4 | 5 | import javax.inject.Singleton; 6 | 7 | import dagger.Module; 8 | import dagger.Provides; 9 | import in.rrapps.mvpdaggertesting.dao.DatabaseInteractor; 10 | import in.rrapps.mvpdaggertesting.dao.DatabaseWrapper; 11 | import in.rrapps.mvpdaggertesting.database.AppDatabase; 12 | 13 | /** 14 | * Created by abhishek 15 | * on 14/12/17. 16 | * 17 | * Provides application class 18 | */ 19 | 20 | @Module 21 | public class AppModule { 22 | 23 | private final BaseApplication application; 24 | 25 | public AppModule(BaseApplication application) { 26 | this.application = application; 27 | } 28 | 29 | @Provides 30 | DatabaseInteractor providesDatabaseInteractor(AppDatabase appDatabase) { 31 | return new DatabaseWrapper(appDatabase); 32 | } 33 | 34 | @Provides 35 | @Singleton 36 | BaseApplication providesApplication () { 37 | return application; 38 | } 39 | 40 | @Provides 41 | @Singleton 42 | AppDatabase providesAppDatabase() { 43 | return Room.databaseBuilder(application, AppDatabase.class, "movieData").build(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.MenuItem; 6 | import android.widget.FrameLayout; 7 | 8 | import in.rrapps.mvpdaggertesting.api.ApiService; 9 | 10 | import javax.inject.Inject; 11 | 12 | public abstract class BaseActivity extends AppCompatActivity { 13 | 14 | @Inject 15 | ApiService apiService; 16 | 17 | private FrameLayout contentFrame; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | super.setContentView(in.rrapps.mvpdaggertesting.R.layout.activity_base); 23 | 24 | 25 | contentFrame = (FrameLayout) findViewById(in.rrapps.mvpdaggertesting.R.id.base_container); 26 | } 27 | 28 | @Override 29 | public void setContentView(int layoutResId) { 30 | getLayoutInflater().inflate(layoutResId, contentFrame, true); 31 | } 32 | 33 | @Override 34 | protected void onResume() { 35 | super.onResume(); 36 | } 37 | 38 | @Override 39 | protected void onPause() { 40 | super.onPause(); 41 | } 42 | 43 | @Override 44 | protected void onDestroy() { 45 | super.onDestroy(); 46 | } 47 | 48 | 49 | @Override 50 | public boolean onOptionsItemSelected(MenuItem item) { 51 | switch (item.getItemId()) { 52 | case android.R.id.home: 53 | onBackPressed(); 54 | return true; 55 | default: 56 | return super.onOptionsItemSelected(item); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/BaseApplication.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | import android.app.Application; 4 | 5 | import lombok.Getter; 6 | import timber.log.Timber; 7 | 8 | public class BaseApplication extends Application { 9 | @Getter 10 | private AppComponent appComponent; 11 | 12 | @Override 13 | public void onCreate() { 14 | super.onCreate(); 15 | 16 | if (BuildConfig.DEBUG) { 17 | Timber.plant(new Timber.DebugTree()); 18 | } 19 | 20 | appComponent = DaggerAppComponent.builder() 21 | .appModule(new AppModule(this)) 22 | .build(); 23 | 24 | appComponent.inject(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/BaseDrawerActivity.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.design.widget.NavigationView; 6 | import android.support.v4.view.GravityCompat; 7 | import android.support.v4.widget.DrawerLayout; 8 | import android.support.v7.app.ActionBarDrawerToggle; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.MenuItem; 11 | import android.widget.FrameLayout; 12 | 13 | public abstract class BaseDrawerActivity extends BaseActivity 14 | implements NavigationView.OnNavigationItemSelectedListener { 15 | 16 | private FrameLayout container; 17 | private DrawerLayout drawerLayout; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | super.setContentView(in.rrapps.mvpdaggertesting.R.layout.activity_base_drawer); 23 | Toolbar toolbar = (Toolbar) findViewById(in.rrapps.mvpdaggertesting.R.id.toolbar); 24 | setSupportActionBar(toolbar); 25 | 26 | container = (FrameLayout)findViewById(in.rrapps.mvpdaggertesting.R.id.drawer_container); 27 | drawerLayout = (DrawerLayout) findViewById(in.rrapps.mvpdaggertesting.R.id.drawer_layout); 28 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 29 | this, drawerLayout, toolbar, in.rrapps.mvpdaggertesting.R.string.navigation_drawer_open, in.rrapps.mvpdaggertesting.R.string.navigation_drawer_close); 30 | drawerLayout.setDrawerListener(toggle); 31 | toggle.syncState(); 32 | 33 | NavigationView navigationView = (NavigationView) findViewById(in.rrapps.mvpdaggertesting.R.id.nav_view); 34 | navigationView.setNavigationItemSelectedListener(this); 35 | } 36 | 37 | @Override 38 | public void setContentView(int layoutResId) { 39 | getLayoutInflater().inflate(layoutResId, container, true); 40 | } 41 | 42 | @Override 43 | public void onBackPressed() { 44 | if (drawerLayout.isDrawerOpen(GravityCompat.START)) { 45 | drawerLayout.closeDrawer(GravityCompat.START); 46 | } else { 47 | super.onBackPressed(); 48 | } 49 | } 50 | 51 | @SuppressWarnings("StatementWithEmptyBody") 52 | @Override 53 | public boolean onNavigationItemSelected(@NonNull MenuItem item) { 54 | // Handle navigation view item clicks here. 55 | int id = item.getItemId(); 56 | 57 | if (id == in.rrapps.mvpdaggertesting.R.id.nav_camera) { 58 | // Handle the camera action 59 | } else if (id == in.rrapps.mvpdaggertesting.R.id.nav_gallery) { 60 | 61 | } else if (id == in.rrapps.mvpdaggertesting.R.id.nav_slideshow) { 62 | 63 | } else if (id == in.rrapps.mvpdaggertesting.R.id.nav_manage) { 64 | 65 | } else if (id == in.rrapps.mvpdaggertesting.R.id.nav_share) { 66 | 67 | } else if (id == in.rrapps.mvpdaggertesting.R.id.nav_send) { 68 | 69 | } 70 | 71 | DrawerLayout drawer = (DrawerLayout) findViewById(in.rrapps.mvpdaggertesting.R.id.drawer_layout); 72 | drawer.closeDrawer(GravityCompat.START); 73 | return true; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | 6 | import in.rrapps.mvpdaggertesting.dialogs.LoadingDialog; 7 | 8 | public abstract class BaseFragment extends Fragment { 9 | 10 | @Override 11 | public void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | } 14 | 15 | @Override 16 | public void onActivityCreated(Bundle savedInstanceState) { 17 | super.onActivityCreated(savedInstanceState); 18 | 19 | //enabling toolbar to have menu items in fragment 20 | setHasOptionsMenu(true); 21 | } 22 | 23 | @Override 24 | public void onResume() { 25 | super.onResume(); 26 | } 27 | 28 | @Override 29 | public void onPause() { 30 | super.onPause(); 31 | } 32 | 33 | public void onDestroy() { 34 | super.onDestroy(); 35 | } 36 | 37 | 38 | private LoadingDialog loadingDialog; 39 | 40 | protected void cancelLoadingDialog() { 41 | if (loadingDialog != null 42 | && loadingDialog.getDialog() != null 43 | && loadingDialog.getDialog().isShowing()) { 44 | loadingDialog.getDialog().dismiss(); 45 | } 46 | } 47 | 48 | protected void showLoadingDialog(int stringResId) { 49 | loadingDialog = LoadingDialog.newInstance(getString(stringResId)); 50 | loadingDialog.show(getActivity().getSupportFragmentManager(), null); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/BaseToolBarActivity.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.Toolbar; 5 | import android.widget.FrameLayout; 6 | 7 | public abstract class BaseToolBarActivity extends BaseActivity { 8 | 9 | private FrameLayout contentFrame; 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | super.setContentView(in.rrapps.mvpdaggertesting.R.layout.activity_base_toolbar); 15 | 16 | Toolbar toolbar = findViewById(in.rrapps.mvpdaggertesting.R.id.toolbar); 17 | setSupportActionBar(toolbar); 18 | 19 | assert getSupportActionBar() != null; 20 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 21 | 22 | contentFrame = findViewById(in.rrapps.mvpdaggertesting.R.id.activity_content); 23 | } 24 | 25 | @Override 26 | public void setContentView(int layoutResId) { 27 | getLayoutInflater().inflate(layoutResId, contentFrame, true); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/Constants.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting; 2 | 3 | /** 4 | * @author shishank 5 | */ 6 | 7 | public class Constants { 8 | 9 | public static final String IMAGE_URL_BASE = "https://image.tmdb.org/t/p/w500"; 10 | 11 | public static final String API_KEY = "0c594548fb5cfb6bc6f353b5b10b9fc4"; 12 | public static final String MOVIE_DETAIL = "movie_detail"; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/api/ApiModule.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.api; 2 | 3 | import com.google.gson.FieldNamingPolicy; 4 | import com.google.gson.Gson; 5 | import com.google.gson.GsonBuilder; 6 | 7 | import in.rrapps.mvpdaggertesting.BaseApplication; 8 | import in.rrapps.mvpdaggertesting.BuildConfig; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import javax.inject.Singleton; 13 | 14 | import dagger.Module; 15 | import dagger.Provides; 16 | import io.reactivex.schedulers.Schedulers; 17 | import lombok.Getter; 18 | import okhttp3.OkHttpClient; 19 | import okhttp3.Request; 20 | import okhttp3.logging.HttpLoggingInterceptor; 21 | import retrofit2.Retrofit; 22 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; 23 | import retrofit2.converter.gson.GsonConverterFactory; 24 | 25 | @Module 26 | public class ApiModule { 27 | 28 | @Provides 29 | @Singleton 30 | ApiService providesApiService() { 31 | OkHttpClient.Builder builder = new OkHttpClient.Builder(); 32 | builder.hostnameVerifier((str, sslSession) -> true); 33 | 34 | builder.connectTimeout(30, TimeUnit.SECONDS); 35 | builder.readTimeout(30, TimeUnit.SECONDS); 36 | builder.writeTimeout(30, TimeUnit.SECONDS); 37 | 38 | // Add headers 39 | builder.interceptors().add(chain -> { 40 | Request request = chain.request(); 41 | 42 | request = request.newBuilder() 43 | .build(); 44 | return chain.proceed(request); 45 | 46 | }); 47 | 48 | // Logging 49 | HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 50 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 51 | builder.interceptors().add(interceptor); 52 | 53 | Gson gson = new GsonBuilder() 54 | .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) 55 | .setDateFormat("yyyy-MM-dd") 56 | .create(); 57 | 58 | RxJava2CallAdapterFactory rxAdapter = RxJava2CallAdapterFactory 59 | .createWithScheduler(Schedulers.io()); 60 | 61 | Retrofit retrofit = new Retrofit.Builder() 62 | .baseUrl(BuildConfig.API_URL) 63 | .client(builder.build()) 64 | .addConverterFactory(GsonConverterFactory.create(gson)) 65 | .addCallAdapterFactory(rxAdapter) 66 | .build(); 67 | return retrofit.create(ApiService.class); 68 | } 69 | } -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/api/ApiService.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.api; 2 | 3 | import in.rrapps.mvpdaggertesting.models.response.DiscoverResponse; 4 | 5 | import java.util.Map; 6 | 7 | import io.reactivex.Observable; 8 | import retrofit2.http.GET; 9 | import retrofit2.http.QueryMap; 10 | 11 | public interface ApiService { 12 | 13 | @GET("discover/movie") 14 | Observable getMoviesList(@QueryMap Map params); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/dao/DatabaseCallbacks.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.dao; 2 | 3 | import in.rrapps.mvpdaggertesting.models.MovieData; 4 | 5 | /** 6 | * @author shishank 7 | */ 8 | 9 | public interface DatabaseCallbacks { 10 | 11 | void onDataInserted(MovieData data); 12 | 13 | void onFailed(Throwable throwable); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/dao/DatabaseInteractor.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.dao; 2 | 3 | import in.rrapps.mvpdaggertesting.models.MovieData; 4 | 5 | import io.reactivex.Single; 6 | import lombok.NonNull; 7 | 8 | /** 9 | * @author shishank 10 | */ 11 | 12 | public interface DatabaseInteractor { 13 | 14 | void setMovieData(MovieData data); 15 | 16 | Single getMovieData(@NonNull int id); 17 | 18 | void setCallbacks(DatabaseCallbacks callbacks); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/dao/DatabaseWrapper.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.dao; 2 | 3 | import android.os.AsyncTask; 4 | 5 | import in.rrapps.mvpdaggertesting.database.AppDatabase; 6 | import in.rrapps.mvpdaggertesting.models.MovieData; 7 | import io.reactivex.Single; 8 | 9 | /** 10 | * @author shishank 11 | */ 12 | 13 | public class DatabaseWrapper implements DatabaseInteractor { 14 | 15 | private final AppDatabase appDatabase; 16 | private DatabaseCallbacks callbacks; 17 | 18 | public DatabaseWrapper(AppDatabase appDatabase) { 19 | this.appDatabase = appDatabase; 20 | } 21 | 22 | @Override 23 | public void setMovieData(MovieData data) { 24 | new AsyncTask() { 25 | @Override 26 | protected Void doInBackground(Void... voids) { 27 | appDatabase.movieDataDao().addMovieData(data); 28 | return null; 29 | } 30 | 31 | @Override 32 | protected void onPostExecute(Void aVoid) { 33 | super.onPostExecute(aVoid); 34 | callbacks.onDataInserted(data); 35 | } 36 | }.execute(); 37 | 38 | } 39 | 40 | @Override 41 | public Single getMovieData(int id) { 42 | return appDatabase.movieDataDao().getMovieData(id); 43 | } 44 | 45 | @Override 46 | public void setCallbacks(DatabaseCallbacks callbacks) { 47 | this.callbacks = callbacks; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/dao/MovieDataDao.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.dao; 2 | 3 | import android.arch.persistence.room.Dao; 4 | import android.arch.persistence.room.Insert; 5 | import android.arch.persistence.room.OnConflictStrategy; 6 | import android.arch.persistence.room.Query; 7 | import android.arch.persistence.room.Update; 8 | 9 | import in.rrapps.mvpdaggertesting.models.MovieData; 10 | 11 | import io.reactivex.Single; 12 | 13 | /** 14 | * @author shishank 15 | */ 16 | 17 | @Dao 18 | public interface MovieDataDao { 19 | 20 | @Query("SELECT * FROM MovieData WHERE id = :id") 21 | Single getMovieData(int id); 22 | 23 | @Insert(onConflict = OnConflictStrategy.REPLACE) 24 | void addMovieData(MovieData movieData); 25 | 26 | @Update 27 | void updateMovieData(MovieData movieData); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/database/AppDatabase.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.database; 2 | 3 | import android.arch.persistence.room.Database; 4 | import android.arch.persistence.room.RoomDatabase; 5 | 6 | import in.rrapps.mvpdaggertesting.models.MovieData; 7 | import in.rrapps.mvpdaggertesting.dao.MovieDataDao; 8 | 9 | /** 10 | * @author shishank 11 | */ 12 | 13 | @Database(entities = {MovieData.class}, version = 2) 14 | public abstract class AppDatabase extends RoomDatabase { 15 | public abstract MovieDataDao movieDataDao(); 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/dialogs/LoadingDialog.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.dialogs; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import in.rrapps.mvpdaggertesting.R; 11 | 12 | public class LoadingDialog extends android.support.v4.app.DialogFragment { 13 | 14 | public static final String TITLE = "title"; 15 | 16 | public static LoadingDialog newInstance(String title) { 17 | final LoadingDialog loadingDialog = new LoadingDialog(); 18 | Bundle bundle = new Bundle(); 19 | bundle.putString(TITLE, title); 20 | loadingDialog.setArguments(bundle); 21 | return loadingDialog; 22 | } 23 | 24 | @Nullable 25 | @Override 26 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 27 | View view = inflater.inflate(R.layout.loading_dialog, container, true); 28 | 29 | TextView tvTitleDesc = view.findViewById(R.id.tv_step_name); 30 | tvTitleDesc.setText(getArguments().getString(TITLE)); 31 | setCancelable(false); 32 | 33 | return view; 34 | } 35 | } -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/dialogs/ThemedInfoDialog.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.dialogs; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.DialogFragment; 6 | import android.text.TextUtils; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | import android.widget.TextView; 12 | 13 | import in.rrapps.mvpdaggertesting.R; 14 | 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | import butterknife.OnClick; 18 | import lombok.Getter; 19 | import lombok.Setter; 20 | 21 | public class ThemedInfoDialog extends DialogFragment { 22 | 23 | private static final String KEY_MESSAGE = "message"; 24 | private static final String KEY_TITLE = "title"; 25 | private static final String KEY_POSITIVE_BUTTON_TEXT = "positive_button_text"; 26 | private static final String KEY_NEGATIVE_BUTTON_TEXT = "negative_button_text"; 27 | private static final String KEY_SHOW_CANCEL_BUTTON = "show_cancel_button"; 28 | 29 | @Getter 30 | @Setter 31 | public View.OnClickListener okListener; 32 | 33 | @BindView(R.id.tv_title) 34 | TextView titleTv; 35 | 36 | @BindView(R.id.tv_message) 37 | TextView messageTv; 38 | 39 | @BindView(R.id.btn_ok) 40 | Button okButton; 41 | 42 | @BindView(R.id.btn_no) 43 | Button cancelButton; 44 | boolean button; 45 | 46 | 47 | public static ThemedInfoDialog newInstance(String title, String message, String positiveText, 48 | String negativeText, boolean cancelButton) { 49 | Bundle bundle = createBundle(title, message, positiveText, negativeText, cancelButton); 50 | ThemedInfoDialog dialog = new ThemedInfoDialog(); 51 | dialog.setArguments(bundle); 52 | return dialog; 53 | } 54 | 55 | protected static Bundle createBundle(String title, String message, 56 | String positiveButtonText, String negativeButtonText, boolean cancelButton) { 57 | Bundle args = new Bundle(); 58 | args.putString(KEY_MESSAGE, message); 59 | args.putString(KEY_TITLE, title); 60 | args.putString(KEY_POSITIVE_BUTTON_TEXT, positiveButtonText); 61 | args.putString(KEY_NEGATIVE_BUTTON_TEXT, negativeButtonText); 62 | args.putBoolean(KEY_SHOW_CANCEL_BUTTON, cancelButton); 63 | 64 | return args; 65 | } 66 | 67 | @Override 68 | public void onCreate(Bundle savedInstanceState) { 69 | super.onCreate(savedInstanceState); 70 | // Applying the theme 71 | setCancelable(true); 72 | } 73 | 74 | @Nullable 75 | @Override 76 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 77 | View rootView = inflater.inflate(R.layout.fragment_themed_dialog, container, false); 78 | ButterKnife.bind(this, rootView); 79 | getDialog().setCanceledOnTouchOutside(true); 80 | Bundle args = getArguments(); 81 | messageTv.setText(args.getString(KEY_MESSAGE)); 82 | titleTv.setText(args.getString(KEY_TITLE)); 83 | cancelButton.setVisibility(View.GONE); 84 | button = args.getBoolean(KEY_SHOW_CANCEL_BUTTON); 85 | if (button) { 86 | cancelButton.setVisibility(View.VISIBLE); 87 | } 88 | 89 | if (TextUtils.isEmpty(args.getString(KEY_POSITIVE_BUTTON_TEXT))) { 90 | okButton.setText(getString(android.R.string.ok)); 91 | } else { 92 | okButton.setText(args.getString(KEY_POSITIVE_BUTTON_TEXT)); 93 | } 94 | 95 | return rootView; 96 | } 97 | 98 | @OnClick(R.id.btn_ok) 99 | void onClickOk(View view) { 100 | dismiss(); 101 | if (okListener != null) { 102 | okListener.onClick(view); 103 | } 104 | } 105 | 106 | @OnClick(R.id.btn_no) 107 | public void onClickCancel() { 108 | dismiss(); 109 | } 110 | } -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/models/MovieData.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.models; 2 | 3 | import android.arch.persistence.room.ColumnInfo; 4 | import android.arch.persistence.room.Entity; 5 | import android.arch.persistence.room.PrimaryKey; 6 | 7 | /** 8 | * @author shishank 9 | */ 10 | 11 | @Entity 12 | public class MovieData { 13 | 14 | @PrimaryKey 15 | private int id; 16 | @ColumnInfo(name = "like") 17 | private boolean like; 18 | @ColumnInfo(name = "disLike") 19 | private boolean disLike; 20 | @ColumnInfo(name = "name") 21 | private String name; 22 | 23 | public int getId() { 24 | return id; 25 | } 26 | 27 | public void setId(int id) { 28 | this.id = id; 29 | } 30 | 31 | public boolean isLike() { 32 | return like; 33 | } 34 | 35 | public void setLike(boolean like) { 36 | this.like = like; 37 | } 38 | 39 | public boolean isDisLike() { 40 | return disLike; 41 | } 42 | 43 | public void setDisLike(boolean disLike) { 44 | this.disLike = disLike; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/models/response/DiscoverResponse.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.models.response; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.util.List; 7 | 8 | import lombok.Data; 9 | 10 | /** 11 | * @author shishank 12 | */ 13 | 14 | @Data 15 | public class DiscoverResponse implements Parcelable { 16 | 17 | private int page; 18 | private int totalResults; 19 | private int total_pages; 20 | private List results; 21 | 22 | protected DiscoverResponse(Parcel in) { 23 | page = in.readInt(); 24 | totalResults = in.readInt(); 25 | total_pages = in.readInt(); 26 | } 27 | 28 | public static final Creator CREATOR = new Creator() { 29 | @Override 30 | public DiscoverResponse createFromParcel(Parcel in) { 31 | return new DiscoverResponse(in); 32 | } 33 | 34 | @Override 35 | public DiscoverResponse[] newArray(int size) { 36 | return new DiscoverResponse[size]; 37 | } 38 | }; 39 | 40 | public DiscoverResponse() { 41 | } 42 | 43 | @Override 44 | public int describeContents() { 45 | return 0; 46 | } 47 | 48 | @Override 49 | public void writeToParcel(Parcel dest, int flags) { 50 | dest.writeInt(page); 51 | dest.writeInt(totalResults); 52 | dest.writeInt(total_pages); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/models/response/Result.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.models.response; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.util.List; 7 | 8 | import lombok.Data; 9 | 10 | @Data 11 | public class Result implements Parcelable{ 12 | 13 | private int voteCount; 14 | private int id; 15 | private boolean video; 16 | private double voteAverage; 17 | private String title; 18 | private double popularity; 19 | private String posterPath; 20 | private String originalLanguage; 21 | private String originalTitle; 22 | private Object backdropPath; 23 | private boolean adult; 24 | private String overview; 25 | private String releaseDate; 26 | private List genreIds; 27 | 28 | protected Result(Parcel in) { 29 | voteCount = in.readInt(); 30 | id = in.readInt(); 31 | video = in.readByte() != 0; 32 | voteAverage = in.readDouble(); 33 | title = in.readString(); 34 | popularity = in.readDouble(); 35 | posterPath = in.readString(); 36 | originalLanguage = in.readString(); 37 | originalTitle = in.readString(); 38 | adult = in.readByte() != 0; 39 | overview = in.readString(); 40 | releaseDate = in.readString(); 41 | } 42 | 43 | public static final Creator CREATOR = new Creator() { 44 | @Override 45 | public Result createFromParcel(Parcel in) { 46 | return new Result(in); 47 | } 48 | 49 | @Override 50 | public Result[] newArray(int size) { 51 | return new Result[size]; 52 | } 53 | }; 54 | 55 | public Result() { 56 | } 57 | 58 | @Override 59 | public int describeContents() { 60 | return 0; 61 | } 62 | 63 | @Override 64 | public void writeToParcel(Parcel dest, int flags) { 65 | dest.writeInt(voteCount); 66 | dest.writeInt(id); 67 | dest.writeByte((byte) (video ? 1 : 0)); 68 | dest.writeDouble(voteAverage); 69 | dest.writeString(title); 70 | dest.writeDouble(popularity); 71 | dest.writeString(posterPath); 72 | dest.writeString(originalLanguage); 73 | dest.writeString(originalTitle); 74 | dest.writeByte((byte) (adult ? 1 : 0)); 75 | dest.writeString(overview); 76 | dest.writeString(releaseDate); 77 | } 78 | } -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/Contracts.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import in.rrapps.mvpdaggertesting.models.response.Result; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author shishank 9 | */ 10 | 11 | public interface Contracts { 12 | 13 | interface View { 14 | void initView(); 15 | 16 | void populateData(List resultList); 17 | 18 | void onMovieItemSelected(Result result); 19 | 20 | void onError(Throwable throwable); 21 | 22 | void showLoading(); 23 | 24 | void hideLoading(); 25 | 26 | void sortingList(); 27 | } 28 | 29 | interface Presenter { 30 | void init(); 31 | 32 | void fetchMovies(int pageIndex); 33 | 34 | boolean shouldUpdate(); 35 | 36 | void sortByPopularity(int pageIndex); 37 | 38 | void sortByRating(int pageIndex); 39 | 40 | void showLoading(); 41 | 42 | void hideLoading(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/MovieComponent.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import dagger.Subcomponent; 4 | 5 | /** 6 | * Created by abhishek 7 | * on 14/12/17. 8 | * 9 | * Custom scope for movie screen, this is a child component of App Component 10 | * and needs to be smaller in size 11 | */ 12 | @MovieScope 13 | @Subcomponent(modules = {MovieModule.class}) 14 | public interface MovieComponent { 15 | void inject(MovieListFragment movieListFragment); 16 | } -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/MovieListActivity.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import android.os.Bundle; 4 | import android.view.Menu; 5 | 6 | import in.rrapps.mvpdaggertesting.BaseApplication; 7 | import in.rrapps.mvpdaggertesting.BaseToolBarActivity; 8 | 9 | 10 | public class MovieListActivity extends BaseToolBarActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(in.rrapps.mvpdaggertesting.R.layout.activity_movie_list); 16 | if (getSupportActionBar() != null) { 17 | getSupportActionBar().setDisplayHomeAsUpEnabled(false); 18 | } 19 | 20 | } 21 | 22 | @Override 23 | public boolean onCreateOptionsMenu(Menu menu) { 24 | getMenuInflater().inflate(in.rrapps.mvpdaggertesting.R.menu.sort_menu, menu); 25 | return super.onCreateOptionsMenu(menu); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/MovieListAdapter.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | 11 | import com.bumptech.glide.Glide; 12 | import com.bumptech.glide.request.RequestOptions; 13 | import in.rrapps.mvpdaggertesting.Constants; 14 | import in.rrapps.mvpdaggertesting.R; 15 | import in.rrapps.mvpdaggertesting.models.response.Result; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | import butterknife.BindView; 21 | import butterknife.ButterKnife; 22 | import lombok.Getter; 23 | 24 | /** 25 | * @author shishank 26 | */ 27 | 28 | public class MovieListAdapter extends RecyclerView.Adapter { 29 | 30 | private Context context; 31 | 32 | @Getter 33 | private List movieList; 34 | private LayoutInflater layoutInflater; 35 | private Contracts.View movieView; 36 | 37 | public MovieListAdapter(Context context, Contracts.View movieView) { 38 | this.context = context; 39 | movieList = new ArrayList<>(); 40 | layoutInflater = LayoutInflater.from(context); 41 | this.movieView = movieView; 42 | } 43 | 44 | public void addAll(List results) { 45 | movieList.addAll(results); 46 | notifyDataSetChanged(); 47 | } 48 | 49 | public List getList() { 50 | return movieList; 51 | } 52 | 53 | public void clear() { 54 | if (movieList != null) { 55 | movieList.clear(); 56 | } 57 | } 58 | 59 | @Override 60 | public MovieViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 61 | return new MovieViewHolder(layoutInflater.inflate(R.layout.view_movie_item, parent, 62 | false)); 63 | } 64 | 65 | 66 | @Override 67 | public void onBindViewHolder(MovieViewHolder holder, int position) { 68 | holder.bindViews(movieList.get(position)); 69 | } 70 | 71 | @Override 72 | public int getItemCount() { 73 | return movieList.size(); 74 | } 75 | 76 | class MovieViewHolder extends RecyclerView.ViewHolder { 77 | @BindView(R.id.iv_movie_poster) 78 | ImageView ivMoviePoster; 79 | 80 | MovieViewHolder(View itemView) { 81 | super(itemView); 82 | ButterKnife.bind(this, itemView); 83 | } 84 | 85 | @SuppressLint("CheckResult") 86 | void bindViews(Result result) { 87 | RequestOptions requestOptions = new RequestOptions(); 88 | requestOptions.placeholder(R.drawable.ic_placeholder); 89 | requestOptions.error(R.drawable.ic_placeholder); 90 | requestOptions.fitCenter(); 91 | Glide.with(context) 92 | .asDrawable() 93 | .apply(requestOptions) 94 | .load(Constants.IMAGE_URL_BASE + result.getPosterPath()) 95 | .into(ivMoviePoster); 96 | itemView.setOnClickListener(v -> movieView.onMovieItemSelected(result)); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/MovieListFragment.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.design.widget.Snackbar; 8 | import android.support.v7.widget.AppCompatTextView; 9 | import android.support.v7.widget.GridLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.view.LayoutInflater; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.ProgressBar; 16 | 17 | import com.jakewharton.rxbinding2.support.v7.widget.RxRecyclerView; 18 | 19 | import java.util.List; 20 | 21 | import javax.inject.Inject; 22 | 23 | import butterknife.BindView; 24 | import butterknife.ButterKnife; 25 | import butterknife.Unbinder; 26 | import in.rrapps.mvpdaggertesting.BaseApplication; 27 | import in.rrapps.mvpdaggertesting.BaseFragment; 28 | import in.rrapps.mvpdaggertesting.Constants; 29 | import in.rrapps.mvpdaggertesting.R; 30 | import in.rrapps.mvpdaggertesting.api.ApiService; 31 | import in.rrapps.mvpdaggertesting.movie.detail.MovieDetailActivity; 32 | import in.rrapps.mvpdaggertesting.models.response.Result; 33 | 34 | /** 35 | * @author shishank 36 | */ 37 | 38 | public class MovieListFragment extends BaseFragment implements Contracts.View { 39 | 40 | @BindView(R.id.rv_movie_list) 41 | RecyclerView rvMovieList; 42 | 43 | @BindView(R.id.progress_bar) 44 | ProgressBar progressBar; 45 | 46 | @BindView(R.id.tv_info) 47 | AppCompatTextView tvInfo; 48 | 49 | Unbinder unbinder; 50 | 51 | @Inject 52 | MovieListPresenter presenter; 53 | 54 | private GridLayoutManager gridLayoutManager; 55 | 56 | private static int pageIndex = 1; 57 | private MovieListAdapter movieListAdapter; 58 | 59 | @Inject 60 | ApiService apiService; 61 | 62 | @Override 63 | public void onCreate(Bundle savedInstanceState) { 64 | super.onCreate(savedInstanceState); 65 | ((BaseApplication)getActivity().getApplication()) 66 | .getAppComponent() 67 | .newMovieComponent(new MovieModule(this)) 68 | .inject(this); 69 | } 70 | 71 | @Nullable 72 | @Override 73 | public View onCreateView(@NonNull LayoutInflater inflater, 74 | @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 75 | View view = inflater.inflate(R.layout.fragment_movie_list, container, false); 76 | unbinder = ButterKnife.bind(this, view); 77 | 78 | return view; 79 | } 80 | 81 | @Override 82 | public void onActivityCreated(Bundle savedInstanceState) { 83 | super.onActivityCreated(savedInstanceState); 84 | presenter.init(); 85 | RxRecyclerView.scrollEvents(rvMovieList) 86 | .filter(event -> presenter.shouldUpdate()) 87 | .filter(event1 -> hasScrolledToLast()) 88 | .map(event -> pageIndex = pageIndex + 1) 89 | .subscribe(recyclerViewScrollEvent -> presenter.fetchMovies(pageIndex), 90 | this::onError); 91 | } 92 | 93 | @Override 94 | public void onDestroyView() { 95 | super.onDestroyView(); 96 | unbinder.unbind(); 97 | } 98 | 99 | private Boolean hasScrolledToLast() { 100 | int pastVisibleItems, visibleItemCount, totalItemCount; 101 | visibleItemCount = gridLayoutManager.getChildCount(); 102 | totalItemCount = gridLayoutManager.getItemCount(); 103 | pastVisibleItems = gridLayoutManager.findFirstVisibleItemPosition(); 104 | return (visibleItemCount + pastVisibleItems) >= totalItemCount; 105 | } 106 | 107 | private void resetPageIndex() { 108 | pageIndex = 1; 109 | } 110 | 111 | @Override 112 | public boolean onOptionsItemSelected(MenuItem item) { 113 | switch (item.getItemId()) { 114 | case R.id.action_high_rated: 115 | resetPageIndex(); 116 | presenter.sortByPopularity(pageIndex); 117 | break; 118 | case R.id.action_most_popular: 119 | resetPageIndex(); 120 | presenter.sortByRating(pageIndex); 121 | break; 122 | } 123 | return super.onOptionsItemSelected(item); 124 | } 125 | 126 | //View methods 127 | @Override 128 | public void initView() { 129 | gridLayoutManager = new GridLayoutManager(getActivity(), 3); 130 | rvMovieList.setLayoutManager(gridLayoutManager); 131 | movieListAdapter = new MovieListAdapter(getContext(), this); 132 | rvMovieList.setAdapter(movieListAdapter); 133 | presenter.fetchMovies(pageIndex); 134 | } 135 | 136 | @Override 137 | public void populateData(List resultList) { 138 | movieListAdapter.addAll(resultList); 139 | hideLoading(); 140 | } 141 | 142 | @Override 143 | public void onMovieItemSelected(Result result) { 144 | Intent intent = new Intent(getActivity(), MovieDetailActivity.class); 145 | intent.putExtra(Constants.MOVIE_DETAIL, result); 146 | startActivity(intent); 147 | } 148 | 149 | @Override 150 | public void onError(Throwable throwable) { 151 | hideLoading(); 152 | Snackbar.make(tvInfo, R.string.something_went_wrong, Snackbar.LENGTH_LONG).show(); 153 | } 154 | 155 | @Override 156 | public void showLoading() { 157 | rvMovieList.setVisibility(View.GONE); 158 | progressBar.setVisibility(View.VISIBLE); 159 | tvInfo.setVisibility(View.VISIBLE); 160 | } 161 | 162 | @Override 163 | public void hideLoading() { 164 | progressBar.setVisibility(View.GONE); 165 | tvInfo.setVisibility(View.GONE); 166 | rvMovieList.setVisibility(View.VISIBLE); 167 | } 168 | 169 | @Override 170 | public void sortingList() { 171 | showLoading(); 172 | movieListAdapter.clear(); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/MovieListPresenter.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import in.rrapps.mvpdaggertesting.api.ApiService; 4 | import in.rrapps.mvpdaggertesting.models.response.DiscoverResponse; 5 | import in.rrapps.mvpdaggertesting.Constants; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import javax.inject.Inject; 11 | 12 | import io.reactivex.android.schedulers.AndroidSchedulers; 13 | import lombok.Setter; 14 | 15 | /** 16 | * @author shishank 17 | */ 18 | 19 | public class MovieListPresenter implements Contracts.Presenter { 20 | 21 | private Contracts.View movieView; 22 | private boolean isUpdating; 23 | private Map queryMap; 24 | 25 | private ApiService apiService; 26 | 27 | public MovieListPresenter(Contracts.View movieView, ApiService apiService) { 28 | super(); 29 | this.movieView = movieView; 30 | this.apiService = apiService; 31 | queryMap = new HashMap<>(); 32 | queryMap.put("api_key", Constants.API_KEY); 33 | } 34 | 35 | @Override 36 | public void init() { 37 | movieView.initView(); 38 | } 39 | 40 | @Override 41 | public void fetchMovies(int pageIndex) { 42 | queryMap.put("page", pageIndex); 43 | fetchMovieList(queryMap); 44 | } 45 | 46 | private void fetchMovieList(Map map) { 47 | isUpdating = true; 48 | apiService.getMoviesList(map).observeOn(AndroidSchedulers.mainThread()) 49 | .doOnTerminate(() -> isUpdating = false) 50 | .map(DiscoverResponse::getResults) 51 | .subscribe(movieView::populateData, movieView::onError); 52 | } 53 | 54 | @Override 55 | public boolean shouldUpdate() { 56 | return !isUpdating; 57 | } 58 | 59 | @Override 60 | public void sortByPopularity(int pageIndex) { 61 | movieView.sortingList(); 62 | queryMap.put("sort_by", "popularity.desc"); 63 | queryMap.put("page", pageIndex); 64 | fetchMovieList(queryMap); 65 | } 66 | 67 | @Override 68 | public void sortByRating(int pageIndex) { 69 | movieView.sortingList(); 70 | queryMap.put("sort_by", "vote_average.desc"); 71 | queryMap.put("page", pageIndex); 72 | fetchMovieList(queryMap); 73 | } 74 | 75 | @Override 76 | public void showLoading() { 77 | movieView.showLoading(); 78 | } 79 | 80 | @Override 81 | public void hideLoading() { 82 | movieView.hideLoading(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/MovieModule.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import dagger.Module; 4 | import dagger.Provides; 5 | import in.rrapps.mvpdaggertesting.api.ApiService; 6 | 7 | /** 8 | * Created by abhishek 9 | * on 14/12/17. 10 | */ 11 | 12 | @Module 13 | public class MovieModule { 14 | 15 | private final Contracts.View movieView; 16 | 17 | public MovieModule(Contracts.View movieView) { 18 | this.movieView = movieView; 19 | } 20 | 21 | @Provides 22 | @MovieScope 23 | MovieListPresenter provideMovieListPresenter(ApiService apiService) { 24 | return new MovieListPresenter(movieView, apiService); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/MovieScope.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie; 2 | 3 | import javax.inject.Scope; 4 | 5 | /** 6 | * Created by abhishek 7 | * on 18/12/17. 8 | */ 9 | 10 | @Scope 11 | public @interface MovieScope { 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/detail/Contracts.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie.detail; 2 | 3 | import in.rrapps.mvpdaggertesting.models.MovieData; 4 | 5 | /** 6 | * @author shishank 7 | */ 8 | 9 | public interface Contracts { 10 | 11 | interface View { 12 | void initView(); 13 | 14 | void PopulateData(); 15 | 16 | void onCompleted(MovieData movieData); 17 | 18 | void showLoading(); 19 | 20 | void hideLoading(); 21 | } 22 | 23 | interface Presenter { 24 | void init(); 25 | 26 | void updateMovie(MovieData movieData); 27 | 28 | void findMovie(int id); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/detail/MovieDetailActivity.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie.detail; 2 | 3 | import android.os.Bundle; 4 | 5 | import in.rrapps.mvpdaggertesting.BaseToolBarActivity; 6 | import in.rrapps.mvpdaggertesting.R; 7 | 8 | /** 9 | * @author shishank 10 | */ 11 | 12 | public class MovieDetailActivity extends BaseToolBarActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_movie_detail); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/detail/MovieDetailComponent.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie.detail; 2 | 3 | import dagger.Subcomponent; 4 | import in.rrapps.mvpdaggertesting.movie.MovieListFragment; 5 | import in.rrapps.mvpdaggertesting.movie.MovieModule; 6 | import in.rrapps.mvpdaggertesting.movie.MovieScope; 7 | 8 | /** 9 | * Created by abhishek 10 | * on 14/12/17. 11 | * 12 | * Custom component for movie detail screen, this is a child component of App Component 13 | * and needs to be smaller in size 14 | */ 15 | @MovieScope 16 | @Subcomponent(modules = {MovieDetailModule.class}) 17 | public interface MovieDetailComponent { 18 | void inject(MovieDetailFragment movieDetailFragment); 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/detail/MovieDetailFragment.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie.detail; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v4.content.ContextCompat; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | import android.widget.ImageView; 12 | import android.widget.LinearLayout; 13 | import android.widget.RelativeLayout; 14 | import android.widget.ScrollView; 15 | import android.widget.TextView; 16 | 17 | import com.bumptech.glide.Glide; 18 | import com.hookedonplay.decoviewlib.DecoView; 19 | import com.hookedonplay.decoviewlib.charts.SeriesItem; 20 | import com.hookedonplay.decoviewlib.events.DecoEvent; 21 | 22 | import in.rrapps.mvpdaggertesting.BaseApplication; 23 | import in.rrapps.mvpdaggertesting.BaseFragment; 24 | import in.rrapps.mvpdaggertesting.Constants; 25 | import in.rrapps.mvpdaggertesting.R; 26 | import in.rrapps.mvpdaggertesting.models.MovieData; 27 | import in.rrapps.mvpdaggertesting.models.response.Result; 28 | 29 | import java.util.Locale; 30 | 31 | import javax.inject.Inject; 32 | 33 | import butterknife.BindView; 34 | import butterknife.ButterKnife; 35 | import butterknife.OnClick; 36 | import butterknife.Unbinder; 37 | 38 | /** 39 | * @author shishank 40 | */ 41 | 42 | public class MovieDetailFragment extends BaseFragment implements Contracts.View { 43 | 44 | @BindView(R.id.ll_parent) 45 | LinearLayout llParent; 46 | 47 | Unbinder unbinder; 48 | 49 | @BindView(R.id.iv_movie_poster) 50 | ImageView ivMoviePoster; 51 | 52 | @BindView(R.id.btn_like) 53 | Button btnLike; 54 | 55 | @BindView(R.id.btn_dislike) 56 | Button btnDislike; 57 | 58 | @BindView(R.id.tv_movie_title) 59 | TextView tvMovieTitle; 60 | 61 | @BindView(R.id.user_vote_progress) 62 | DecoView userVoteProgress; 63 | 64 | @BindView(R.id.tv_summary) 65 | TextView tvSummary; 66 | 67 | @BindView(R.id.rl_parent) 68 | RelativeLayout rlParent; 69 | 70 | @BindView(R.id.sv_parent) 71 | ScrollView svParent; 72 | 73 | @BindView(R.id.tv_score) 74 | TextView tvScore; 75 | 76 | private final float MAX_RANGE = 10f; 77 | 78 | @Inject 79 | MovieDetailPresenter presenter; 80 | 81 | private Result result; 82 | 83 | @Override 84 | public void onCreate(Bundle savedInstanceState) { 85 | super.onCreate(savedInstanceState); 86 | ((BaseApplication)getActivity().getApplication()) 87 | .getAppComponent() 88 | .newMovieDetailComponent(new MovieDetailModule(this)) 89 | .inject(this); 90 | } 91 | 92 | @Nullable 93 | @Override 94 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 95 | @Nullable Bundle savedInstanceState) { 96 | View view = inflater.inflate(R.layout.fragment_movie_detail, container, false); 97 | unbinder = ButterKnife.bind(this, view); 98 | return view; 99 | } 100 | 101 | @Override 102 | public void onActivityCreated(Bundle savedInstanceState) { 103 | super.onActivityCreated(savedInstanceState); 104 | SeriesItem seriesItem = new SeriesItem.Builder(ContextCompat.getColor(getActivity(), android.R.color.white)) 105 | .setRange(0, MAX_RANGE, MAX_RANGE).setInitialVisibility(true).build(); 106 | userVoteProgress.addSeries(seriesItem); 107 | presenter.init(); 108 | } 109 | 110 | @Override 111 | public void onDestroyView() { 112 | super.onDestroyView(); 113 | unbinder.unbind(); 114 | } 115 | 116 | //View Methods 117 | @Override 118 | public void initView() { 119 | 120 | } 121 | 122 | @Override 123 | public void PopulateData() { 124 | rlParent.setVisibility(View.VISIBLE); 125 | svParent.setVisibility(View.VISIBLE); 126 | if (getActivity().getIntent() != null) { 127 | result = getActivity().getIntent().getParcelableExtra(Constants.MOVIE_DETAIL); 128 | if (result != null) { 129 | presenter.findMovie(result.getId()); 130 | float userVote = (float) result.getVoteAverage(); 131 | tvScore.setText(String.format(Locale.getDefault(), "%s", result.getVoteAverage())); 132 | SeriesItem seriesItem1 = 133 | new SeriesItem.Builder(ContextCompat.getColor(getActivity(), 134 | android.R.color.holo_green_light)) 135 | .setRange(0, MAX_RANGE, 0) 136 | .setSpinDuration(1000) 137 | .setInitialVisibility(true) 138 | .build(); 139 | int series1Index = userVoteProgress.addSeries(seriesItem1); 140 | userVoteProgress.addEvent(new DecoEvent.Builder(userVote) 141 | .setIndex(series1Index).setDuration(1000).build()); 142 | 143 | Glide.with(getActivity()).asDrawable() 144 | .load(Constants.IMAGE_URL_BASE + result.getPosterPath()) 145 | .into(ivMoviePoster); 146 | tvMovieTitle.setText(String.format(Locale.getDefault(), "%s ( %s )", 147 | result.getOriginalTitle(), result.getReleaseDate())); 148 | tvSummary.setText(result.getOverview()); 149 | 150 | } 151 | } 152 | } 153 | 154 | @Override 155 | public void onCompleted(MovieData movieData) { 156 | cancelLoadingDialog(); 157 | String s; 158 | if (movieData.isLike()) { 159 | s = getString(R.string.like_this_movie); 160 | btnLike.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.holo_green_light)); 161 | btnDislike.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.white)); 162 | } else { 163 | s = getString(R.string.dislike_this_movie); 164 | btnDislike.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.holo_green_light)); 165 | btnLike.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.white)); 166 | } 167 | Snackbar.make(btnDislike, s, Snackbar.LENGTH_SHORT).show(); 168 | } 169 | 170 | @Override 171 | public void showLoading() { 172 | } 173 | 174 | @Override 175 | public void hideLoading() { 176 | 177 | } 178 | 179 | @OnClick({R.id.btn_like, R.id.btn_dislike}) 180 | public void onViewClicked(View view) { 181 | switch (view.getId()) { 182 | case R.id.btn_like: 183 | if (result != null) { 184 | MovieData movieData = new MovieData(); 185 | movieData.setId(result.getId()); 186 | movieData.setLike(true); 187 | movieData.setDisLike(false); 188 | movieData.setName(result.getOriginalTitle()); 189 | presenter.updateMovie(movieData); 190 | } 191 | break; 192 | case R.id.btn_dislike: 193 | if (result != null) { 194 | MovieData movieData = new MovieData(); 195 | movieData.setId(result.getId()); 196 | movieData.setDisLike(true); 197 | movieData.setLike(false); 198 | movieData.setName(result.getOriginalTitle()); 199 | presenter.updateMovie(movieData); 200 | } 201 | break; 202 | } 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/detail/MovieDetailModule.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie.detail; 2 | 3 | import dagger.Module; 4 | import dagger.Provides; 5 | import in.rrapps.mvpdaggertesting.dao.DatabaseInteractor; 6 | import in.rrapps.mvpdaggertesting.movie.MovieScope; 7 | import timber.log.Timber; 8 | 9 | /** 10 | * Created by abhishek 11 | * on 24/12/17. 12 | */ 13 | 14 | @Module 15 | public class MovieDetailModule { 16 | 17 | private final Contracts.View movieDetailView; 18 | 19 | public MovieDetailModule(Contracts.View movieDetailView) { 20 | this.movieDetailView = movieDetailView; 21 | } 22 | 23 | @Provides 24 | @MovieScope 25 | MovieDetailPresenter provideMovieDetailPresenter(DatabaseInteractor databaseInteractor) { 26 | Timber.d("Creating new presenter for movie detail"); 27 | return new MovieDetailPresenter(movieDetailView, databaseInteractor); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/in/rrapps/mvpdaggertesting/movie/detail/MovieDetailPresenter.java: -------------------------------------------------------------------------------- 1 | package in.rrapps.mvpdaggertesting.movie.detail; 2 | 3 | import in.rrapps.mvpdaggertesting.dao.DatabaseCallbacks; 4 | import in.rrapps.mvpdaggertesting.dao.DatabaseInteractor; 5 | import in.rrapps.mvpdaggertesting.models.MovieData; 6 | import io.reactivex.android.schedulers.AndroidSchedulers; 7 | import io.reactivex.schedulers.Schedulers; 8 | import timber.log.Timber; 9 | 10 | /** 11 | * @author shishank 12 | */ 13 | 14 | public class MovieDetailPresenter implements Contracts.Presenter, DatabaseCallbacks { 15 | 16 | private Contracts.View movieDetailView; 17 | private final DatabaseInteractor databaseInteractor; 18 | 19 | public MovieDetailPresenter(Contracts.View movieDetailView, 20 | DatabaseInteractor databaseInteractor) { 21 | this.movieDetailView = movieDetailView; 22 | this.databaseInteractor = databaseInteractor; 23 | databaseInteractor.setCallbacks(this); 24 | } 25 | 26 | @Override 27 | public void init() { 28 | movieDetailView.PopulateData(); 29 | } 30 | 31 | @Override 32 | public void updateMovie(MovieData movieData) { 33 | movieDetailView.showLoading(); 34 | databaseInteractor.setMovieData(movieData); 35 | } 36 | 37 | @Override 38 | public void findMovie(int id) { 39 | databaseInteractor.getMovieData(id).observeOn(AndroidSchedulers.mainThread()) 40 | .subscribeOn(Schedulers.computation()) 41 | .subscribe(movieDetailView::onCompleted, this::onFailed); 42 | } 43 | 44 | @Override 45 | public void onDataInserted(MovieData data) { 46 | findMovie(data.getId()); 47 | } 48 | 49 | 50 | @Override 51 | public void onFailed(Throwable throwable) { 52 | Timber.d("data inserted"+throwable.getCause()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_gallery.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_send.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_share.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_slideshow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhishekBansal/android-mvp-retrofit2-dagger2-rxjava2-testing/a30f3c876ae4e7662b51fb29bb4df6a064359fe3/app/src/main/res/drawable-xxxhdpi/ic_placeholder.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_base.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_base_drawer.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_base_toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 16 | 17 | 18 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_movie_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_movie_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_movie_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 |