├── .gitignore ├── .idea ├── assetWizardSettings.xml ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── maiconhellmann │ │ └── architecture │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── maiconhellmann │ │ │ └── architecture │ │ │ ├── ArchitectureApplication.kt │ │ │ ├── data │ │ │ ├── MovieRepository.kt │ │ │ ├── local │ │ │ │ ├── MovieDao.kt │ │ │ │ ├── MovieDataBase.kt │ │ │ │ └── MovieLocalDataSource.kt │ │ │ ├── model │ │ │ │ ├── Movie.kt │ │ │ │ └── Type.kt │ │ │ └── remote │ │ │ │ ├── dto │ │ │ │ ├── Dto.kt │ │ │ │ └── SearchMovieDto.kt │ │ │ │ └── endpoint │ │ │ │ └── MovieWebService.kt │ │ │ ├── injection │ │ │ └── module │ │ │ │ ├── LocalDataSourceModule.kt │ │ │ │ ├── RemoteDataSourceModule.kt │ │ │ │ ├── RepositoryModule.kt │ │ │ │ └── ViewModelModule.kt │ │ │ ├── misc │ │ │ ├── RequestInterceptor.kt │ │ │ ├── UnsafeOkHttpClient.kt │ │ │ ├── ViewLifeCycleFragment.kt │ │ │ └── ext │ │ │ │ ├── ActivityExtension.kt │ │ │ │ ├── ButtomSheetBehaviorExtension.kt │ │ │ │ ├── ContextExtension.kt │ │ │ │ ├── CoroutinesExtension.kt │ │ │ │ ├── CursorExtension.kt │ │ │ │ ├── DateExtension.kt │ │ │ │ ├── DrawableExtension.kt │ │ │ │ ├── EditTextExtension.kt │ │ │ │ ├── MaskExtension.kt │ │ │ │ ├── SharedPreferencesExtension.kt │ │ │ │ ├── StringExtension.kt │ │ │ │ ├── TextViewExtension.kt │ │ │ │ ├── ViewExtension.kt │ │ │ │ └── ViewModelExtension.kt │ │ │ └── view │ │ │ ├── AbstractViewModel.kt │ │ │ ├── BaseActivity.kt │ │ │ ├── BaseFragment.kt │ │ │ ├── ViewConstants.kt │ │ │ └── main │ │ │ ├── EpisodeFragment.kt │ │ │ ├── MainActivity.kt │ │ │ ├── MainViewModel.kt │ │ │ ├── MovieAdapter.kt │ │ │ ├── MovieFragment.kt │ │ │ └── SeriesFragment.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_error_black_24dp.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_local_movies_black_24dp.xml │ │ ├── ic_movie_black_24dp.xml │ │ ├── ic_movie_filter_black_24dp.xml │ │ └── ic_search_black_24dp.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_movie.xml │ │ └── row_movie.xml │ │ ├── menu │ │ └── navigation.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── maiconhellmann │ └── architecture │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/assetWizardSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 46 | 47 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 [yyyy] [name of copyright owner] 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 | # kotlin-mvvm-coroutines-koin 2 | Android architecture using Kotlin, MVVM, Coroutines and Koin. 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | 6 | 7 | android { 8 | compileSdkVersion 27 9 | defaultConfig { 10 | applicationId "com.maiconhellmann.architecture" 11 | minSdkVersion 15 12 | targetSdkVersion 27 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | buildConfigField 'String', 'API_KEY', '"i=tt3896198&apikey=a39c66fa"' 22 | buildConfigField 'String', 'URL_API', '"http://www.omdbapi.com/"' 23 | } 24 | debug { 25 | versionNameSuffix " Debug" 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | buildConfigField 'String', 'API_KEY', '"i=tt3896198&apikey=a39c66fa"' 29 | buildConfigField 'String', 'URL_API', '"http://www.omdbapi.com/"' 30 | } 31 | } 32 | } 33 | 34 | dependencies { 35 | final supportLibraryVersion = '27.1.1' 36 | final RETROFIT_VERSION = '2.1.0' 37 | final mockito_version = '2.6.2' 38 | final expresseVersion = '3.0.1' 39 | final jUnitVersion = '4.12' 40 | final runnerVersion = '1.0.1' 41 | final koin_version = '0.9.0' 42 | final anko_version = '0.10.4' 43 | final androidArchitectureVersion = '1.1.1' 44 | final coroutines_version = '0.22.5' 45 | final roomVersion = '1.0.0' 46 | final glideVersion = '4.6.1' 47 | 48 | implementation fileTree(dir: 'libs', include: ['*.jar']) 49 | 50 | //Test 51 | testImplementation "junit:junit:$jUnitVersion" 52 | androidTestImplementation "com.android.support.test:runner:$runnerVersion" 53 | androidTestImplementation "com.android.support.test.espresso:espresso-core:$expresseVersion" 54 | 55 | //Kotlin 56 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 57 | 58 | //SupportLibrary 59 | implementation "com.android.support:appcompat-v7:$supportLibraryVersion" 60 | implementation "com.android.support:design:$supportLibraryVersion" 61 | implementation "com.android.support:support-vector-drawable:$supportLibraryVersion" 62 | implementation "com.android.support:recyclerview-v7:$supportLibraryVersion" 63 | implementation "com.android.support:cardview-v7:$supportLibraryVersion" 64 | implementation "com.android.support:support-annotations:$supportLibraryVersion" 65 | implementation "com.android.support:design:$supportLibraryVersion" 66 | 67 | //Compomennts 68 | implementation "com.android.support.constraint:constraint-layout:1.1.0" 69 | 70 | //GSON 71 | implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION" 72 | 73 | //Retrofit 74 | implementation "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION" 75 | 76 | //Request logs 77 | implementation "com.squareup.okhttp3:logging-interceptor:3.6.0" 78 | 79 | //Timber 80 | implementation "com.jakewharton.timber:timber:4.4.0" 81 | 82 | // Koin 83 | implementation "org.koin:koin-android-architecture:$koin_version" 84 | testImplementation "org.koin:koin-test:$koin_version" 85 | testImplementation "org.mockito:mockito-core:$mockito_version" 86 | 87 | // Anko 88 | implementation "org.jetbrains.anko:anko:$anko_version" 89 | 90 | // ViewModel and LiveData 91 | implementation "android.arch.lifecycle:extensions:$androidArchitectureVersion" 92 | annotationProcessor "android.arch.lifecycle:compiler:$androidArchitectureVersion" 93 | testImplementation "android.arch.core:core-testing:$androidArchitectureVersion" 94 | 95 | //Kotlin Coroutines 96 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" 97 | implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:1.0.0" 98 | 99 | //Room 100 | implementation "android.arch.persistence.room:runtime:$roomVersion" 101 | kapt "android.arch.persistence.room:compiler:$roomVersion" 102 | 103 | //Glide 104 | implementation "com.github.bumptech.glide:glide:$glideVersion" 105 | kapt "com.github.bumptech.glide:compiler:$glideVersion" 106 | } 107 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/maiconhellmann/architecture/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.maiconhellmann.architecture", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/ArchitectureApplication.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture 2 | 3 | import android.app.Application 4 | import com.maiconhellmann.architecture.injection.module.localDataSourceModule 5 | import com.maiconhellmann.architecture.injection.module.remoteDatasourceModule 6 | import com.maiconhellmann.architecture.injection.module.repositoryModule 7 | import com.maiconhellmann.architecture.injection.module.viewModelModule 8 | import org.koin.android.ext.android.startKoin 9 | import timber.log.Timber 10 | import timber.log.Timber.DebugTree 11 | 12 | 13 | class ArchitectureApplication : Application() { 14 | override fun onCreate() { 15 | super.onCreate() 16 | 17 | if (BuildConfig.DEBUG) { 18 | Timber.plant(DebugTree()) 19 | } 20 | 21 | startKoin(this, listOf( 22 | remoteDatasourceModule, 23 | localDataSourceModule, 24 | repositoryModule, 25 | viewModelModule)) 26 | } 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/MovieRepository.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data 2 | 3 | import com.maiconhellmann.architecture.data.local.MovieDatabase 4 | import com.maiconhellmann.architecture.data.model.Type 5 | import com.maiconhellmann.architecture.data.remote.dto.SearchMovieDto 6 | import com.maiconhellmann.architecture.data.remote.endpoint.MovieWebService 7 | 8 | class MovieRepository(private val remoteDataSource: MovieWebService, 9 | private val localDataSource: MovieDatabase) { 10 | 11 | suspend fun searchMovies(query: String): SearchMovieDto { 12 | //remote data source Request 13 | return remoteDataSource.getMovies(query, Type.MOVIE.value).await() 14 | } 15 | 16 | suspend fun searchEpisodes(query: String): SearchMovieDto { 17 | //remote data source Request 18 | return remoteDataSource.getMovies(query, Type.EPISODE.value).await() 19 | } 20 | 21 | suspend fun searchSeries(query: String): SearchMovieDto { 22 | //remote data source Request 23 | return remoteDataSource.getMovies(query, Type.SERIES.value).await() 24 | } 25 | 26 | suspend fun queryDatabase() { 27 | //Database query example 28 | // val sizeDeffered = async { 29 | // localDataSource.rateDao().getRates().size 30 | // } 31 | // Timber.e("erro: ${sizeDeffered.await()}") 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/local/MovieDao.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.local 2 | 3 | import android.arch.persistence.room.* 4 | import com.maiconhellmann.architecture.data.model.Movie 5 | 6 | @Dao 7 | interface MovieDao { 8 | 9 | @Query("SELECT * from movie") 10 | fun getMovieList(): List 11 | 12 | @Insert(onConflict = OnConflictStrategy.REPLACE) 13 | fun insert(movie: Movie) 14 | 15 | @Update 16 | fun update(movie: Movie): Int 17 | 18 | 19 | @Query("DELETE FROM movie") 20 | fun deleteAll() 21 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/local/MovieDataBase.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.local 2 | 3 | import android.arch.persistence.room.Database 4 | import android.arch.persistence.room.Room 5 | import android.arch.persistence.room.RoomDatabase 6 | import android.content.Context 7 | import com.maiconhellmann.architecture.data.model.Movie 8 | 9 | @Database(entities = arrayOf(Movie::class), version = 2, exportSchema = false) 10 | abstract class MovieDatabase : RoomDatabase() { 11 | 12 | abstract fun movieDao(): MovieDao 13 | 14 | companion object { 15 | 16 | private var INSTANCE: MovieDatabase? = null 17 | 18 | private val lock = Any() 19 | 20 | fun getInstance(context: Context): MovieDatabase { 21 | synchronized(lock) { 22 | if (INSTANCE == null) { 23 | INSTANCE = Room.databaseBuilder(context.applicationContext, 24 | MovieDatabase::class.java, "movie.db") 25 | .build() 26 | } 27 | return INSTANCE!! 28 | } 29 | } 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/local/MovieLocalDataSource.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.local 2 | 3 | class MovieLocalDataSource(val database: MovieDatabase) { 4 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/model/Movie.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.model 2 | 3 | import android.arch.persistence.room.Entity 4 | import android.arch.persistence.room.PrimaryKey 5 | import com.google.gson.annotations.SerializedName 6 | 7 | @Entity(tableName = "movie") 8 | class Movie { 9 | @PrimaryKey(autoGenerate = true) 10 | var id: Long? = null 11 | 12 | @SerializedName("Title") 13 | var title: String? = null 14 | 15 | @SerializedName("Year") 16 | var year: String? = null 17 | 18 | @SerializedName("Rated") 19 | var rated: String? = null 20 | 21 | @SerializedName("Runtime") 22 | var runTime: String? = null 23 | 24 | @SerializedName("Genre") 25 | var genre: String? = null 26 | 27 | @SerializedName("Director") 28 | var director: String? = null 29 | 30 | @SerializedName("Writer") 31 | var writer: String? = null 32 | 33 | @SerializedName("Plot") 34 | var plot: String? = null 35 | 36 | @SerializedName("Awards") 37 | var awards: String? = null 38 | 39 | @SerializedName("Poster") 40 | var poster: String? = null 41 | 42 | // var ratings: List 43 | 44 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/model/Type.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.model 2 | 3 | enum class Type(val value: String) { 4 | MOVIE("movie"), 5 | SERIES("series"), 6 | EPISODE("episode") 7 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/remote/dto/Dto.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.remote.dto 2 | 3 | import com.google.gson.annotations.SerializedName 4 | 5 | open class Dto( 6 | var totalResults: Long? = null, 7 | 8 | @SerializedName("Response") 9 | var response: Boolean? = null, 10 | 11 | @SerializedName("Error") 12 | var error: String? = null 13 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/remote/dto/SearchMovieDto.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.remote.dto 2 | 3 | import com.google.gson.annotations.SerializedName 4 | import com.maiconhellmann.architecture.data.model.Movie 5 | 6 | class SearchMovieDto : Dto() { 7 | @SerializedName("Search") 8 | var search: List? = null 9 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/data/remote/endpoint/MovieWebService.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.data.remote.endpoint 2 | 3 | import com.maiconhellmann.architecture.BuildConfig 4 | import com.maiconhellmann.architecture.data.remote.dto.SearchMovieDto 5 | import kotlinx.coroutines.experimental.Deferred 6 | import retrofit2.http.GET 7 | import retrofit2.http.Query 8 | 9 | interface MovieWebService { 10 | 11 | @GET("?${BuildConfig.API_KEY}") 12 | fun getMovies(@Query("s") query: String, @Query("type") type: String): Deferred 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/injection/module/LocalDataSourceModule.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.injection.module 2 | 3 | import com.maiconhellmann.architecture.data.local.MovieDatabase 4 | import com.maiconhellmann.architecture.data.local.MovieLocalDataSource 5 | import org.koin.dsl.module.applicationContext 6 | 7 | val localDataSourceModule = applicationContext { 8 | 9 | factory { MovieLocalDataSource(get()) } 10 | factory { MovieDatabase.getInstance(get()) } 11 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/injection/module/RemoteDataSourceModule.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.injection.module 2 | 3 | import com.google.gson.* 4 | import com.jakewharton.retrofit2.adapter.kotlin.coroutines.experimental.CoroutineCallAdapterFactory 5 | import com.maiconhellmann.architecture.BuildConfig 6 | import com.maiconhellmann.architecture.data.remote.endpoint.MovieWebService 7 | import com.maiconhellmann.architecture.misc.RequestInterceptor 8 | import com.maiconhellmann.architecture.misc.UnsafeOkHttpClient 9 | import okhttp3.OkHttpClient 10 | import okhttp3.logging.HttpLoggingInterceptor 11 | import org.koin.dsl.module.applicationContext 12 | import retrofit2.Retrofit 13 | import retrofit2.converter.gson.GsonConverterFactory 14 | import java.util.* 15 | import java.util.concurrent.TimeUnit 16 | 17 | val remoteDatasourceModule = applicationContext { 18 | 19 | //RequestInterceptor 20 | bean { provideRequestInterceptor() } 21 | 22 | //LoggingInterceptop 23 | bean { provideLoggingInterceptor() } 24 | 25 | // provided web components 26 | bean { provideOkHttpClient(get(), get()) } 27 | 28 | bean { provideGson() } 29 | 30 | bean { provideRemoteDataSource(get(), get()) } 31 | } 32 | 33 | /** 34 | * Prove o parser de Json para a aplicação 35 | */ 36 | fun provideGson(): Gson { 37 | val builder = GsonBuilder() 38 | 39 | builder.registerTypeAdapter(Date::class.java, JsonDeserializer { json, _, _ -> 40 | json?.asJsonPrimitive?.asLong?.let { 41 | return@JsonDeserializer Date(it) 42 | } 43 | }) 44 | 45 | builder.registerTypeAdapter(Date::class.java, JsonSerializer { date, _, _ -> 46 | JsonPrimitive(date.time) 47 | }) 48 | 49 | return builder.create() 50 | } 51 | 52 | 53 | /** 54 | * Prove o interceptor das requisições. Utilizado para adicionar header de token, por exemplo. 55 | */ 56 | fun provideRequestInterceptor(): RequestInterceptor { 57 | return RequestInterceptor() 58 | } 59 | 60 | /** 61 | * Provê o interceptor de logging das requisições 62 | */ 63 | fun provideLoggingInterceptor(): HttpLoggingInterceptor { 64 | //Adiciona log às requisições 65 | val logInterceptor = HttpLoggingInterceptor() 66 | logInterceptor.level = HttpLoggingInterceptor.Level.BODY 67 | 68 | return logInterceptor 69 | } 70 | 71 | /** 72 | * Provê o httpClient padrão para o App 73 | */ 74 | fun provideOkHttpClient(requestInterceptor: RequestInterceptor, 75 | logInterceptor: HttpLoggingInterceptor): OkHttpClient { 76 | 77 | val builder = UnsafeOkHttpClient.getUnsafeOkHttpClient() 78 | 79 | //Adiciona os interceptors 80 | builder.addInterceptor(logInterceptor) 81 | builder.addInterceptor(requestInterceptor) 82 | 83 | builder.connectTimeout(2, TimeUnit.MINUTES) 84 | builder.readTimeout(1, TimeUnit.MINUTES) 85 | builder.readTimeout(1, TimeUnit.MINUTES) 86 | 87 | return builder.build() 88 | } 89 | 90 | /** 91 | * Provê o endpoint service para a aplicação 92 | */ 93 | fun provideRemoteDataSource(okHttpClient: OkHttpClient, gson: Gson): MovieWebService { 94 | return Retrofit.Builder() 95 | .client(okHttpClient) 96 | .baseUrl(BuildConfig.URL_API) 97 | .addConverterFactory(GsonConverterFactory.create(gson)) 98 | .addCallAdapterFactory(CoroutineCallAdapterFactory()) 99 | .build() 100 | .create(MovieWebService::class.java) 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/injection/module/RepositoryModule.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.injection.module 2 | 3 | import com.maiconhellmann.architecture.data.MovieRepository 4 | import org.koin.dsl.module.applicationContext 5 | 6 | val repositoryModule = applicationContext { 7 | factory { MovieRepository(get(), get()) } 8 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/injection/module/ViewModelModule.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.injection.module 2 | 3 | import com.maiconhellmann.architecture.view.main.MainViewModel 4 | import org.koin.android.architecture.ext.viewModel 5 | import org.koin.dsl.module.applicationContext 6 | 7 | val viewModelModule = applicationContext { 8 | viewModel { MainViewModel(get()) } 9 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/RequestInterceptor.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc 2 | 3 | import okhttp3.Interceptor 4 | import okhttp3.Response 5 | import timber.log.Timber 6 | 7 | class RequestInterceptor : Interceptor { 8 | override fun intercept(chain: Interceptor.Chain?): Response { 9 | val request = chain?.request() 10 | val newRequest = request?.newBuilder() 11 | 12 | //get the token 13 | try { 14 | newRequest?.addHeader("Accept", "application/json") 15 | 16 | // val token = dataBase.getToken().toBlocking().first() 17 | // val token = AutoVistoriaApplication.token 18 | 19 | //if token is not null try to add to header 20 | // token?.let { 21 | // newRequest?.addHeader(RemoteConstants.AUTHORIZATION, it.token) 22 | // } 23 | } catch (ex: Throwable) { 24 | Timber.w(ex, "Erro ao consultar token para o interceptop") 25 | } 26 | 27 | return chain?.proceed(newRequest!!.build())!! 28 | } 29 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/UnsafeOkHttpClient.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc 2 | 3 | import okhttp3.OkHttpClient 4 | import java.security.cert.CertificateException 5 | import javax.net.ssl.SSLContext 6 | import javax.net.ssl.TrustManager 7 | import javax.net.ssl.X509TrustManager 8 | 9 | class UnsafeOkHttpClient { 10 | companion object { 11 | fun getUnsafeOkHttpClient(): OkHttpClient.Builder { 12 | try { 13 | // Create a trust manager that does not validate certificate chains 14 | val trustAllCerts = arrayOf(object : X509TrustManager { 15 | @Throws(CertificateException::class) 16 | override fun checkClientTrusted(chain: Array, authType: String) { 17 | } 18 | 19 | @Throws(CertificateException::class) 20 | override fun checkServerTrusted(chain: Array, authType: String) { 21 | } 22 | 23 | override fun getAcceptedIssuers(): Array { 24 | return arrayOf() 25 | } 26 | }) 27 | 28 | // Install the all-trusting trust manager 29 | val sslContext = SSLContext.getInstance("SSL") 30 | sslContext.init(null, trustAllCerts, java.security.SecureRandom()) 31 | // Create an ssl socket factory with our all-trusting manager 32 | val sslSocketFactory = sslContext.socketFactory 33 | 34 | val builder = OkHttpClient.Builder() 35 | builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) 36 | builder.hostnameVerifier { _, _ -> true } 37 | 38 | return builder 39 | } catch (e: Exception) { 40 | throw RuntimeException(e) 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ViewLifeCycleFragment.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc 2 | 3 | import android.arch.lifecycle.Lifecycle.Event 4 | import android.arch.lifecycle.LifecycleOwner 5 | import android.arch.lifecycle.LifecycleRegistry 6 | import android.os.Bundle 7 | import android.support.v4.app.Fragment 8 | import android.view.View 9 | 10 | /** 11 | * Fragment providing separate lifecycle owners for each created view hierarchy. 12 | * 13 | * 14 | * This is one possible way to solve issue https://github.com/googlesamples/android-architecture-components/issues/47 15 | * 16 | * @author Christophe Beyls 17 | */ 18 | open class ViewLifecycleFragment : Fragment() { 19 | 20 | private var viewLifecycleOwner: ViewLifecycleOwner? = null 21 | 22 | internal class ViewLifecycleOwner : LifecycleOwner { 23 | private val lifecycleRegistry = LifecycleRegistry(this) 24 | 25 | override fun getLifecycle(): LifecycleRegistry { 26 | return lifecycleRegistry 27 | } 28 | } 29 | 30 | /** 31 | * @return the Lifecycle owner of the current view hierarchy, 32 | * or null if there is no current view hierarchy. 33 | */ 34 | fun getViewLifecycleOwner(): LifecycleOwner? { 35 | return viewLifecycleOwner 36 | } 37 | 38 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 39 | super.onViewCreated(view, savedInstanceState) 40 | viewLifecycleOwner = ViewLifecycleOwner() 41 | viewLifecycleOwner!!.lifecycle.handleLifecycleEvent(Event.ON_CREATE) 42 | } 43 | 44 | override fun onStart() { 45 | super.onStart() 46 | if (viewLifecycleOwner != null) { 47 | viewLifecycleOwner!!.lifecycle.handleLifecycleEvent(Event.ON_START) 48 | } 49 | } 50 | 51 | override fun onResume() { 52 | super.onResume() 53 | if (viewLifecycleOwner != null) { 54 | viewLifecycleOwner!!.lifecycle.handleLifecycleEvent(Event.ON_RESUME) 55 | } 56 | } 57 | 58 | override fun onPause() { 59 | if (viewLifecycleOwner != null) { 60 | viewLifecycleOwner!!.lifecycle.handleLifecycleEvent(Event.ON_PAUSE) 61 | } 62 | super.onPause() 63 | } 64 | 65 | override fun onStop() { 66 | if (viewLifecycleOwner != null) { 67 | viewLifecycleOwner!!.lifecycle.handleLifecycleEvent(Event.ON_STOP) 68 | } 69 | super.onStop() 70 | } 71 | 72 | override fun onDestroyView() { 73 | if (viewLifecycleOwner != null) { 74 | viewLifecycleOwner!!.lifecycle.handleLifecycleEvent(Event.ON_DESTROY) 75 | viewLifecycleOwner = null 76 | } 77 | super.onDestroyView() 78 | } 79 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/ActivityExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.Manifest 4 | import android.app.Activity 5 | import android.content.ClipData 6 | import android.content.ClipboardManager 7 | import android.content.Context 8 | import android.content.pm.PackageManager 9 | import android.os.Build 10 | import android.support.v4.app.ActivityCompat 11 | import android.support.v4.app.Fragment 12 | import com.maiconhellmann.architecture.view.ViewConstants 13 | 14 | 15 | fun Activity.copytoClipBoard(label: String, value: String) { 16 | val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager 17 | val clip = ClipData.newPlainText(label, value) 18 | clipboard.primaryClip = clip 19 | } 20 | 21 | fun Fragment.copytoClipBoard(label: String, value: String) { 22 | activity?.copytoClipBoard(label, value) 23 | } 24 | 25 | fun Activity.hasPermissions(): Boolean { 26 | val permissions = arrayOf(Manifest.permission.CAMERA, 27 | Manifest.permission.WRITE_EXTERNAL_STORAGE, 28 | Manifest.permission.ACCESS_FINE_LOCATION) 29 | 30 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 31 | permissions 32 | .filter { ActivityCompat.checkSelfPermission(this, it) != PackageManager.PERMISSION_GRANTED } 33 | .forEach { return false } 34 | } 35 | return true 36 | } 37 | 38 | fun Activity.requestPermissions() { 39 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 40 | var permissions = emptyArray() 41 | 42 | //Camera 43 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) 44 | != PackageManager.PERMISSION_GRANTED) { 45 | permissions += Manifest.permission.CAMERA 46 | } 47 | //Write storage 48 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) 49 | != PackageManager.PERMISSION_GRANTED) { 50 | permissions += Manifest.permission.WRITE_EXTERNAL_STORAGE 51 | } 52 | 53 | //Location 54 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) 55 | != PackageManager.PERMISSION_GRANTED) { 56 | permissions += Manifest.permission.ACCESS_FINE_LOCATION 57 | } 58 | 59 | if (permissions.isNotEmpty()) { 60 | ActivityCompat.requestPermissions(this, 61 | permissions, ViewConstants.REQUEST_APP_PERMISSIONS) 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/ButtomSheetBehaviorExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.support.design.widget.BottomSheetBehavior 4 | 5 | fun BottomSheetBehavior<*>.isExpanded(): Boolean{ 6 | return state == android.support.design.widget.BottomSheetBehavior.STATE_EXPANDED 7 | } 8 | fun BottomSheetBehavior<*>.isHidden(): Boolean{ 9 | return isExpanded().not() 10 | } 11 | fun BottomSheetBehavior<*>.expand(){ 12 | state = android.support.design.widget.BottomSheetBehavior.STATE_EXPANDED 13 | } 14 | fun BottomSheetBehavior<*>.hide(){ 15 | state = android.support.design.widget.BottomSheetBehavior.STATE_HIDDEN 16 | } 17 | fun BottomSheetBehavior<*>.toggle(){ 18 | if(isHidden()){ 19 | expand() 20 | }else if(isExpanded()){ 21 | hide() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/ContextExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.content.ComponentName 4 | import android.content.Context 5 | import android.content.CursorLoader 6 | import android.content.pm.PackageManager 7 | import android.net.ConnectivityManager 8 | import android.net.Uri 9 | import android.os.Looper 10 | import android.provider.MediaStore 11 | import android.support.annotation.ColorRes 12 | import android.support.annotation.StringRes 13 | import android.support.v4.app.Fragment 14 | import android.support.v4.content.ContextCompat 15 | import android.widget.Toast 16 | 17 | 18 | fun Context.isNetworkConnected(): Boolean { 19 | val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager 20 | return cm.activeNetworkInfo?.isConnectedOrConnecting ?: false 21 | } 22 | 23 | fun Context.toggleAndroidComponent(componentClass: Class<*>, enable: Boolean) { 24 | val componentName = ComponentName(this, componentClass) 25 | 26 | val newState = if (enable) 27 | PackageManager.COMPONENT_ENABLED_STATE_ENABLED 28 | else 29 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED 30 | 31 | packageManager.setComponentEnabledSetting(componentName, newState, PackageManager.DONT_KILL_APP) 32 | } 33 | 34 | /** 35 | * Default short toast 36 | */ 37 | fun Context.toast(any: Any, duration: Int = Toast.LENGTH_SHORT) { 38 | Toast.makeText(this, any.toString(), duration).show() 39 | } 40 | 41 | /** 42 | * Default short toast 43 | */ 44 | fun Context.toast(@StringRes resString: Int, duration: Int = Toast.LENGTH_SHORT) { 45 | toast(getString(resString), duration) 46 | } 47 | 48 | /** 49 | * Long duration toast 50 | */ 51 | fun Context.longToast(any: Any) { 52 | toast(any.toString(), Toast.LENGTH_LONG) 53 | } 54 | 55 | /** 56 | * Long duration toast 57 | */ 58 | fun Context.longToast(@StringRes stringRes: Int) { 59 | toast(getString(stringRes), Toast.LENGTH_LONG) 60 | } 61 | 62 | fun Fragment.toast(message: String, duration: Int = Toast.LENGTH_SHORT) { 63 | context?.toast(message, duration) 64 | } 65 | 66 | fun Fragment.toast(@StringRes resString: Int, duration: Int = Toast.LENGTH_SHORT) { 67 | context?.toast(getString(resString), duration) 68 | } 69 | 70 | fun Fragment.longToast(@StringRes stringRes: Int) { 71 | context?.toast(getString(stringRes), Toast.LENGTH_LONG) 72 | } 73 | 74 | 75 | fun Context.getPath(contentUri: Uri): String { 76 | val proj = arrayOf(MediaStore.Images.Media.DATA) 77 | val result: String 78 | 79 | if (Looper.myLooper() == null) { 80 | Looper.prepare() 81 | } 82 | val cursorLoader = CursorLoader( 83 | this, 84 | contentUri, proj, null, null, null) 85 | val cursor = cursorLoader.loadInBackground() 86 | 87 | result = if (cursor != null) { 88 | val column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) 89 | cursor.moveToFirst() 90 | cursor.getString(column_index) 91 | } else { 92 | contentUri.path 93 | } 94 | 95 | return result 96 | } 97 | 98 | fun Context.getColorCompat(@ColorRes resId: Int): Int { 99 | return ContextCompat.getColor(this, resId) 100 | } 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/CoroutinesExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import kotlinx.coroutines.experimental.* 4 | import kotlinx.coroutines.experimental.android.UI 5 | 6 | fun launchAsync(block: suspend CoroutineScope.() -> Unit): Job { 7 | return launch(UI) { block() } 8 | } 9 | 10 | suspend fun async(block: suspend CoroutineScope.() -> T): Deferred { 11 | return async(CommonPool) { block() } 12 | } 13 | 14 | suspend fun asyncAwait(block: suspend CoroutineScope.() -> T): T { 15 | return async(block).await() 16 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/CursorExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.database.Cursor 4 | 5 | fun Cursor.getString(columnName: String, defaultValue: String = ""): String { 6 | val index = getColumnIndex(columnName) 7 | return getString(index) ?: defaultValue 8 | } 9 | 10 | fun Cursor.getInt(columnName: String, defaultValue: Int = 0): Int { 11 | val index = getColumnIndex(columnName) 12 | return if (index >= 0) getInt(index) else defaultValue 13 | } 14 | 15 | fun Cursor.getLong(columnName: String, defaultValue: Long = 0): Long { 16 | val index = getColumnIndex(columnName) 17 | return if (index >= 0) getLong(index) else defaultValue 18 | } 19 | 20 | fun Cursor.getBoolean(columnName: String, defaultValue: Boolean = false): Boolean { 21 | val index = getColumnIndex(columnName) 22 | return if (index >= 0) getInt(index) == 1 else defaultValue 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/DateExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import java.text.SimpleDateFormat 4 | import java.util.* 5 | 6 | 7 | /** 8 | * Pattern: yyyy-MM-dd HH:mm:ss 9 | */ 10 | fun Date.formatToServerDateTimeDefaults(): String{ 11 | val sdf= SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()) 12 | return sdf.format(this) 13 | } 14 | 15 | fun Date.formatToTruncatedDateTime(): String{ 16 | val sdf= SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()) 17 | return sdf.format(this) 18 | } 19 | 20 | /** 21 | * Pattern: yyyy-MM-dd 22 | */ 23 | fun Date.formatToServerDateDefaults(): String{ 24 | val sdf= SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) 25 | return sdf.format(this) 26 | } 27 | 28 | /** 29 | * Pattern: HH:mm:ss 30 | */ 31 | fun Date.formatToServerTimeDefaults(): String{ 32 | val sdf= SimpleDateFormat("HH:mm:ss", Locale.getDefault()) 33 | return sdf.format(this) 34 | } 35 | 36 | /** 37 | * Pattern: dd/MM/yyyy HH:mm:ss 38 | */ 39 | fun Date.formatToViewDateTimeDefaults(): String{ 40 | val sdf= SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault()) 41 | return sdf.format(this) 42 | } 43 | 44 | /** 45 | * Pattern: dd/MM/yyyy 46 | */ 47 | fun Date.formatToViewDateDefaults(): String{ 48 | val sdf= SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()) 49 | return sdf.format(this) 50 | } 51 | 52 | /** 53 | * Pattern: HH:mm:ss 54 | */ 55 | fun Date.formatToViewTimeDefaults(): String{ 56 | val sdf= SimpleDateFormat("HH:mm:ss", Locale.getDefault()) 57 | return sdf.format(this) 58 | } 59 | 60 | /** 61 | * Add field date to current date 62 | */ 63 | fun Date.add(field: Int, amount: Int): Date{ 64 | val cal = Calendar.getInstance() 65 | cal.time=this 66 | cal.add(field, amount) 67 | 68 | this.time = cal.time.time 69 | 70 | cal.clear() 71 | 72 | return this 73 | } 74 | 75 | fun Date.addYears(years: Int): Date{ 76 | return add(Calendar.YEAR, years) 77 | } 78 | fun Date.addMonths(months: Int): Date { 79 | return add(Calendar.MONTH, months) 80 | } 81 | fun Date.addDays(days: Int): Date{ 82 | return add(Calendar.DAY_OF_MONTH, days) 83 | } 84 | fun Date.addHours(hours: Int): Date{ 85 | return add(Calendar.HOUR_OF_DAY, hours) 86 | } 87 | fun Date.addMinutes(minutes: Int): Date{ 88 | return add(Calendar.MINUTE, minutes) 89 | } 90 | fun Date.addSeconds(seconds: Int): Date{ 91 | return add(Calendar.SECOND, seconds) 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/DrawableExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.graphics.Bitmap 4 | import android.graphics.Canvas 5 | import android.graphics.drawable.BitmapDrawable 6 | import android.widget.ImageView 7 | 8 | fun ImageView.drawableToBitmap(): Bitmap? { 9 | val bitmap: Bitmap 10 | 11 | val drawable = drawable 12 | 13 | if (drawable is BitmapDrawable) { 14 | if (drawable.bitmap != null) { 15 | return drawable.bitmap 16 | } 17 | } 18 | 19 | bitmap = if (drawable.intrinsicWidth <= 0 || drawable.intrinsicHeight <= 0) { 20 | Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) 21 | } else { 22 | Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888) 23 | } 24 | 25 | val canvas = Canvas(bitmap) 26 | drawable.setBounds(0, 0, canvas.width, canvas.height) 27 | drawable.draw(canvas) 28 | return bitmap 29 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/EditTextExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.content.Context 4 | import android.view.inputmethod.InputMethodManager 5 | import android.widget.EditText 6 | import android.text.InputType 7 | 8 | 9 | fun EditText.hideKeyboard() { 10 | val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 11 | val focusedView = rootView.findFocus() ?: rootView 12 | val token = focusedView.applicationWindowToken 13 | 14 | imm.hideSoftInputFromWindow(token, 0) 15 | imm.hideSoftInputFromWindow(token, InputMethodManager.HIDE_IMPLICIT_ONLY) 16 | } 17 | 18 | fun EditText.showKeyboard() { 19 | requestFocus() 20 | 21 | post { 22 | val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 23 | 24 | imm.showSoftInput(this, 0) 25 | imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) 26 | } 27 | } 28 | 29 | fun EditText.disableSoftInputFromAppearing() { 30 | setRawInputType(InputType.TYPE_NULL) 31 | setTextIsSelectable(true) 32 | isFocusable = true 33 | 34 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/MaskExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.support.annotation.StringDef 4 | import android.text.Editable 5 | import android.text.TextWatcher 6 | import android.widget.EditText 7 | 8 | /** 9 | * Source: https://andremrezende.wordpress.com/tag/android-mask-mascara-edittext-java-layout-cpf-cnpj/ 10 | */ 11 | @StringDef(PHONE_9_MASK, PHONE_8_MASK, CPF_MASK, ZIP_CODE_PT_BR, MONTH_YEAR, CREDIT_CARD) 12 | @Retention(AnnotationRetention.SOURCE) 13 | annotation class MaskType 14 | 15 | const val PHONE_9_MASK = "(##) #####-####" 16 | const val PHONE_8_MASK = "(##) ####-####" 17 | const val CPF_MASK = "###.###.###-##" 18 | const val ZIP_CODE_PT_BR = "#####-###" 19 | 20 | const val MONTH_YEAR = "##/##" 21 | 22 | const val CREDIT_CARD = "#### #### #### ####" 23 | 24 | fun String.unmask(): String { 25 | return replace("[\\./\\(\\) \\-\\+]".toRegex(), "") 26 | } 27 | 28 | @Suppress("UNUSED") 29 | fun EditText.insert(@MaskType mask: String): TextWatcher { 30 | val textWatcher = MaskTextWatcher(mask) 31 | 32 | addTextChangedListener(textWatcher) 33 | 34 | return textWatcher 35 | } 36 | 37 | fun EditText.insertPhoneMask(): TextWatcher { 38 | val textWatcher = object : MaskTextWatcher() { 39 | override fun getMask(unmaskedValue: String): String { 40 | if (unmaskedValue.length < 11) { 41 | return PHONE_8_MASK 42 | } 43 | 44 | return PHONE_9_MASK 45 | } 46 | } 47 | 48 | addTextChangedListener(textWatcher) 49 | 50 | return textWatcher 51 | } 52 | 53 | fun String.formatPhone(): String { 54 | var _phone = this 55 | 56 | if (length == 8) 57 | _phone = String.format("%s-%s", substring(0, 4), substring(4, length)) 58 | else if (length == 9) 59 | _phone = String.format("%s-%s", substring(0, 5), substring(5, length)) 60 | else if (length == 10) 61 | _phone = String.format("%s %s-%s", substring(0, 2), substring(2, 6), substring(6, length)) 62 | else if (length == 11) 63 | _phone = String.format("%s %s-%s", substring(0, 2), substring(2, 7), substring(7, length)) 64 | 65 | return _phone 66 | } 67 | 68 | open class MaskTextWatcher(val mask: String = ""): SimpleTextWatcher() { 69 | 70 | internal var oldValue = "" 71 | 72 | internal var isUpdating: Boolean = false 73 | 74 | open fun getMask(unmaskedValue: String): String { 75 | return mask 76 | } 77 | 78 | override fun afterTextChanged(edit: Editable) { 79 | val unmaskedString = edit.toString().unmask() 80 | val maskedString = StringBuilder("") 81 | val mask = getMask(unmaskedString) 82 | 83 | // EditText was GC'ed 84 | 85 | if (isUpdating) { 86 | oldValue = unmaskedString 87 | isUpdating = false 88 | 89 | return 90 | } 91 | 92 | var i = 0 93 | 94 | for (m in mask.toCharArray()) { 95 | if (m != '#' && i < unmaskedString.length) { 96 | maskedString.append(m) 97 | continue 98 | } 99 | 100 | try { 101 | maskedString.append(unmaskedString[i]) 102 | } catch (e: Exception) { 103 | break 104 | } 105 | 106 | i++ 107 | } 108 | 109 | isUpdating = true 110 | 111 | edit.replace(0, edit.length, maskedString) 112 | } 113 | } 114 | 115 | open class SimpleTextWatcher : TextWatcher { 116 | override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { } 117 | 118 | override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { } 119 | 120 | override fun afterTextChanged(edit: Editable) { } 121 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/SharedPreferencesExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.content.SharedPreferences 4 | 5 | /** 6 | * puts a key value pair in shared prefs if doesn't exists, otherwise updates value on given [key] 7 | */ 8 | operator fun SharedPreferences.set(key: String, value: Any?) { 9 | when (value) { 10 | is String? -> edit({ it.putString(key, value) }) 11 | is Int -> edit({ it.putInt(key, value) }) 12 | is Boolean -> edit({ it.putBoolean(key, value) }) 13 | is Float -> edit({ it.putFloat(key, value) }) 14 | is Long -> edit({ it.putLong(key, value) }) 15 | else -> throw UnsupportedOperationException("Not yet implemented") 16 | } 17 | } 18 | 19 | /** 20 | * finds value on given key. 21 | * [T] is the type of value 22 | * @param defaultValue optional default value - will take null for strings, false for bool and -1 for numeric values if [defaultValue] is not specified 23 | */ 24 | inline operator fun SharedPreferences.get(key: String, defaultValue: T? = null): T? { 25 | return when (T::class) { 26 | String::class -> getString(key, defaultValue as? String) as T? 27 | Int::class -> getInt(key, defaultValue as? Int ?: -1) as T? 28 | Boolean::class -> getBoolean(key, defaultValue as? Boolean ?: false) as T? 29 | Float::class -> getFloat(key, defaultValue as? Float ?: -1f) as T? 30 | Long::class -> getLong(key, defaultValue as? Long ?: -1) as T? 31 | else -> throw UnsupportedOperationException("Not yet implemented") 32 | } 33 | } 34 | 35 | inline fun SharedPreferences.edit(operation: (SharedPreferences.Editor) -> Unit) { 36 | val editor = this.edit() 37 | operation(editor) 38 | editor.apply() 39 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/StringExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | fun String.Companion.empty(): String{ 4 | return "" 5 | } 6 | 7 | fun String.Companion.isEmpty(text: Any?): Boolean { 8 | return text==null || text.toString().trim() == String.empty() 9 | } 10 | 11 | fun String.Companion.isNotEmpty(text: Any?): Boolean { 12 | return text!=null && text.toString().trim() != String.empty() 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/TextViewExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | //fun TextView.setText(text: String){ 4 | // this.text = text 5 | //} -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/ViewExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.content.res.ColorStateList 4 | import android.support.annotation.ColorInt 5 | import android.support.design.widget.Snackbar 6 | import android.support.design.widget.TextInputEditText 7 | import android.support.design.widget.TextInputLayout 8 | import android.view.View 9 | import android.widget.FrameLayout 10 | import timber.log.Timber 11 | 12 | fun View.visible(){ 13 | this.visibility = View.VISIBLE 14 | } 15 | fun View.visible(visible : Boolean){ 16 | if(visible){ 17 | visible() 18 | }else{ 19 | gone() 20 | } 21 | } 22 | fun View.gone(){ 23 | this.visibility = View.GONE 24 | } 25 | fun View.invisible(){ 26 | this.visibility = View.INVISIBLE 27 | } 28 | 29 | fun View.isVisible(): Boolean{ 30 | return visibility == View.VISIBLE 31 | } 32 | fun View.isGone(): Boolean{ 33 | return visibility == View.GONE 34 | } 35 | fun View.isInvisible(): Boolean{ 36 | return visibility == View.INVISIBLE 37 | } 38 | 39 | fun View.snackbar(resId: Int, duration: Int = Snackbar.LENGTH_SHORT) { 40 | snackbar(this.resources.getString(resId), duration) 41 | } 42 | 43 | fun View.snackbar(msg: String, duration: Int = Snackbar.LENGTH_SHORT) { 44 | Snackbar.make(this, msg, duration).show() 45 | } 46 | fun View.longSnackbar(resId: Int) { 47 | snackbar(resId, Snackbar.LENGTH_LONG) 48 | } 49 | 50 | 51 | fun TextInputEditText.setTextEx(text: CharSequence?){ 52 | this.setText(text) 53 | /* 54 | if(text?.toString()?.isEmpty() == true){ 55 | setInputTextLayoutColor(Color.RED) 56 | }else{ 57 | setInputTextLayoutColor(Color.LTGRAY) 58 | } 59 | */ 60 | } 61 | fun TextInputEditText.setInputTextLayoutColor(@ColorInt color: Int) { 62 | try { 63 | 64 | val layout = if(parent is FrameLayout){ 65 | parent.parent as TextInputLayout 66 | }else{ 67 | parent as TextInputLayout 68 | } 69 | 70 | layout.editText?.highlightColor = color 71 | layout.editText?.setHintTextColor(color) 72 | layout.editText?.setTextColor(color) 73 | 74 | val fDefaultTextColor = TextInputLayout::class.java.getDeclaredField("mDefaultTextColor") 75 | fDefaultTextColor.isAccessible = true 76 | fDefaultTextColor.set(layout, ColorStateList(arrayOf(intArrayOf(0)), intArrayOf(color))) 77 | 78 | val fFocusedTextColor = TextInputLayout::class.java.getDeclaredField("mFocusedTextColor") 79 | fFocusedTextColor.isAccessible = true 80 | fFocusedTextColor.set(layout, ColorStateList(arrayOf(intArrayOf(0)), intArrayOf(color))) 81 | } catch (e: Exception) { 82 | Timber.e(e) 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/misc/ext/ViewModelExtension.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.misc.ext 2 | 3 | import android.arch.lifecycle.LifecycleOwner 4 | import android.arch.lifecycle.MutableLiveData 5 | import android.support.v7.app.AppCompatActivity 6 | import com.maiconhellmann.architecture.misc.ViewLifecycleFragment 7 | 8 | fun Any.observe(owner: LifecycleOwner, data: MutableLiveData, function: (data: T?) -> Unit) { 9 | data.observe(owner, android.arch.lifecycle.Observer { 10 | function(it) 11 | }) 12 | } 13 | 14 | fun AppCompatActivity.observe(data: MutableLiveData, function: (data: T?) -> Unit) { 15 | data.observe(this@observe, android.arch.lifecycle.Observer { 16 | function(it) 17 | }) 18 | } 19 | // 20 | //fun Fragment.observeFromFragment(data: MutableLiveData, function: (data: T?) -> Unit) { 21 | // data.observe(this@observeFromFragment, android.arch.lifecycle.Observer { 22 | // function(it) 23 | // }) 24 | //} 25 | // 26 | //fun Fragment.observeFromActivity(data: MutableLiveData, function: (data: T?) -> Unit) { 27 | // data.observe(this@observeFromActivity.activity as AppCompatActivity, android.arch.lifecycle.Observer { 28 | // function(it) 29 | // }) 30 | //} 31 | fun ViewLifecycleFragment.observe(data: MutableLiveData, function: (data: T?) -> Unit) { 32 | getViewLifecycleOwner()?.let{ 33 | data.observe(it, android.arch.lifecycle.Observer { 34 | function(it) 35 | }) 36 | } 37 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/AbstractViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view 2 | 3 | import android.arch.lifecycle.MutableLiveData 4 | import android.arch.lifecycle.ViewModel 5 | import android.support.annotation.CallSuper 6 | 7 | /** 8 | */ 9 | abstract class AbstractViewModel : ViewModel() { 10 | 11 | /** 12 | * Handle data loading 13 | */ 14 | val isDataLoading = MutableLiveData() 15 | 16 | /** 17 | * Handle errors 18 | */ 19 | val exception = MutableLiveData() 20 | 21 | 22 | @CallSuper 23 | override fun onCleared() { 24 | super.onCleared() 25 | } 26 | 27 | open fun setLoading(isLoading: Boolean? = true) { 28 | isDataLoading.value = isLoading 29 | 30 | if (isLoading == true) { 31 | exception.value = null 32 | } 33 | } 34 | 35 | open fun setError(t: Throwable) { 36 | exception.value = t 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view 2 | 3 | import android.annotation.SuppressLint 4 | import android.support.v7.app.AppCompatActivity 5 | 6 | @SuppressLint("Registered") 7 | open class BaseActivity : AppCompatActivity() -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/BaseFragment.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view 2 | 3 | import com.maiconhellmann.architecture.misc.ViewLifecycleFragment 4 | 5 | open class BaseFragment : ViewLifecycleFragment() -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/ViewConstants.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view 2 | 3 | /** 4 | * Created by Maicon Hellmann on 28/07/2017. 5 | */ 6 | class ViewConstants { 7 | companion object { 8 | const val REQUEST_APP_PERMISSIONS = 1001 9 | 10 | const val BOTTOM_NAVIGATION_MENU_INDEX = "bottomNavigationMenuIndex" 11 | } 12 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/main/EpisodeFragment.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view.main 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import com.maiconhellmann.architecture.R 8 | import com.maiconhellmann.architecture.misc.ext.gone 9 | import com.maiconhellmann.architecture.misc.ext.observe 10 | import com.maiconhellmann.architecture.misc.ext.visible 11 | import com.maiconhellmann.architecture.view.BaseFragment 12 | import kotlinx.android.synthetic.main.fragment_movie.* 13 | import org.jetbrains.anko.support.v4.alert 14 | import org.jetbrains.anko.yesButton 15 | import org.koin.android.architecture.ext.viewModel 16 | 17 | class EpisodeFragment : BaseFragment() { 18 | 19 | val viewModel: MainViewModel by viewModel() 20 | 21 | private var adapter: MovieAdapter = MovieAdapter() 22 | 23 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 24 | return inflater.inflate(R.layout.fragment_movie, container, false) 25 | } 26 | 27 | override fun onActivityCreated(savedInstanceState: Bundle?) { 28 | super.onActivityCreated(savedInstanceState) 29 | 30 | setupRecyclerView() 31 | setupObservers() 32 | } 33 | 34 | private fun setupObservers() { 35 | //Current currency 36 | observe(viewModel.episode, { 37 | it?.let { 38 | adapter.dataList = it 39 | } 40 | showNoDataFound(adapter.dataList.isEmpty()) 41 | }) 42 | 43 | //ProgressBar 44 | observe(viewModel.isDataLoading, { 45 | if (it == true) { 46 | viewProgressBar.visible() 47 | } else { 48 | viewProgressBar.gone() 49 | } 50 | }) 51 | 52 | observe(viewModel.exception, { 53 | showErrorMessage(it?.message) 54 | }) 55 | } 56 | 57 | private fun showErrorMessage(message: String?) { 58 | message?.let { 59 | alert(message, getString(R.string.error)) { 60 | yesButton { } 61 | }.show() 62 | viewModel.exception.value = null 63 | } 64 | } 65 | 66 | private fun showNoDataFound(show: Boolean) { 67 | if (show) { 68 | viewError.visible() 69 | textViewError.text = getString(R.string.no_episode_found) 70 | } else { 71 | viewError.gone() 72 | } 73 | } 74 | 75 | private fun setupRecyclerView() { 76 | recyclerView.adapter = adapter 77 | } 78 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/main/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view.main 2 | 3 | import android.os.Bundle 4 | import android.view.inputmethod.EditorInfo 5 | import com.maiconhellmann.architecture.R 6 | import com.maiconhellmann.architecture.misc.ext.hideKeyboard 7 | import com.maiconhellmann.architecture.view.BaseActivity 8 | import com.maiconhellmann.architecture.view.ViewConstants 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | import org.koin.android.architecture.ext.viewModel 11 | 12 | 13 | class MainActivity : BaseActivity() { 14 | 15 | val viewModel: MainViewModel by viewModel() 16 | 17 | /** 18 | * Selected menu id. Used to maintain state during the configuration changing 19 | */ 20 | var menuItemId = R.id.navigation_movie 21 | 22 | override fun onCreate(savedInstanceState: Bundle?) { 23 | super.onCreate(savedInstanceState) 24 | setContentView(R.layout.activity_main) 25 | 26 | setupEditTextSearchMovie() 27 | setupBottomNavigationMenun() 28 | 29 | viewModel.start() 30 | } 31 | 32 | private fun setupEditTextSearchMovie() { 33 | editTextSearchMovie.setOnEditorActionListener { _, actionId, _ -> 34 | if (actionId == EditorInfo.IME_ACTION_SEARCH) { 35 | val query = editTextSearchMovie.text.toString() 36 | viewModel.getMovieList(query) 37 | editTextSearchMovie.hideKeyboard() 38 | true 39 | } else { 40 | false 41 | } 42 | } 43 | } 44 | 45 | private fun setupBottomNavigationMenun() { 46 | bottomMenu.setOnNavigationItemSelectedListener { 47 | when { 48 | it.itemId == R.id.navigation_episode -> { 49 | showEpisodeFragment() 50 | } 51 | it.itemId == R.id.navigation_movie -> { 52 | showMovieFragment() 53 | } 54 | it.itemId == R.id.navigation_series -> { 55 | showSeriesFragment() 56 | } 57 | } 58 | true 59 | } 60 | bottomMenu.selectedItemId = menuItemId 61 | } 62 | 63 | override fun onSaveInstanceState(outState: Bundle) { 64 | super.onSaveInstanceState(outState) 65 | outState.putInt(ViewConstants.BOTTOM_NAVIGATION_MENU_INDEX, bottomMenu.selectedItemId) 66 | } 67 | 68 | override fun onRestoreInstanceState(savedInstanceState: Bundle?) { 69 | super.onRestoreInstanceState(savedInstanceState) 70 | 71 | savedInstanceState?.let { 72 | menuItemId = it.get(ViewConstants.BOTTOM_NAVIGATION_MENU_INDEX) as Int 73 | bottomMenu.selectedItemId = menuItemId 74 | } 75 | } 76 | 77 | private fun showSeriesFragment() { 78 | supportFragmentManager.beginTransaction() 79 | .replace(R.id.container, SeriesFragment()) 80 | .commit() 81 | } 82 | 83 | private fun showMovieFragment() { 84 | supportFragmentManager.beginTransaction() 85 | .replace(R.id.container, MovieFragment()) 86 | .commit() 87 | } 88 | 89 | private fun showEpisodeFragment() { 90 | supportFragmentManager.beginTransaction() 91 | .replace(R.id.container, EpisodeFragment()) 92 | .commit() 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/main/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view.main 2 | 3 | import android.arch.lifecycle.MutableLiveData 4 | import com.maiconhellmann.architecture.data.MovieRepository 5 | import com.maiconhellmann.architecture.data.model.Movie 6 | import com.maiconhellmann.architecture.misc.ext.launchAsync 7 | import com.maiconhellmann.architecture.view.AbstractViewModel 8 | 9 | class MainViewModel(private val repository: MovieRepository) : AbstractViewModel() { 10 | 11 | val movie = MutableLiveData>() 12 | val series = MutableLiveData>() 13 | val episode = MutableLiveData>() 14 | 15 | fun getMovieList(query: String) { 16 | if (query.isEmpty().not()) { 17 | 18 | //Fun isn't suspended, so it's necessary to run in mainthread 19 | launchAsync { 20 | try { 21 | //The data is loading 22 | setLoading() 23 | 24 | //Request with a suspended repository funcion 25 | val dtoMovies = repository.searchMovies(query) 26 | val dtoEpisodes = repository.searchEpisodes(query) 27 | val dtoSeries = repository.searchSeries(query) 28 | 29 | movie.value = dtoMovies.search 30 | episode.value = dtoEpisodes.search 31 | series.value = dtoSeries.search 32 | 33 | } catch (t: Throwable) { 34 | //An error was throw 35 | setError(t) 36 | movie.value = emptyList() 37 | } finally { 38 | //Isn't loading anymore 39 | setLoading(false) 40 | } 41 | } 42 | 43 | } else { 44 | movie.value = emptyList() 45 | } 46 | } 47 | 48 | fun start() { 49 | movie.value = emptyList() 50 | episode.value = emptyList() 51 | series.value = emptyList() 52 | } 53 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/main/MovieAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view.main 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import com.maiconhellmann.architecture.R 8 | import com.maiconhellmann.architecture.data.model.Movie 9 | import kotlinx.android.synthetic.main.row_movie.view.* 10 | 11 | class MovieAdapter : RecyclerView.Adapter() { 12 | 13 | var dataList: List = emptyList().toMutableList() 14 | set(value) { 15 | field = value 16 | notifyDataSetChanged() 17 | } 18 | 19 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewAdapterViewHolder { 20 | val itemView = LayoutInflater.from(parent.context) 21 | .inflate(R.layout.row_movie, parent, false) 22 | return RecyclerViewAdapterViewHolder(itemView) 23 | } 24 | 25 | override fun onBindViewHolder(holder: RecyclerViewAdapterViewHolder, position: Int) { 26 | val data = dataList[position] 27 | 28 | holder.textViewTitle.text = data.title 29 | } 30 | 31 | override fun getItemCount(): Int = dataList.size 32 | 33 | inner class RecyclerViewAdapterViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 34 | 35 | val textViewTitle = itemView.textViewTitle 36 | } 37 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/main/MovieFragment.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view.main 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import com.maiconhellmann.architecture.R 8 | import com.maiconhellmann.architecture.misc.ext.gone 9 | import com.maiconhellmann.architecture.misc.ext.observe 10 | import com.maiconhellmann.architecture.misc.ext.visible 11 | import com.maiconhellmann.architecture.view.BaseFragment 12 | import kotlinx.android.synthetic.main.fragment_movie.* 13 | import org.jetbrains.anko.support.v4.alert 14 | import org.jetbrains.anko.yesButton 15 | import org.koin.android.architecture.ext.viewModel 16 | 17 | class MovieFragment : BaseFragment() { 18 | 19 | val viewModel: MainViewModel by viewModel() 20 | 21 | private var adapter: MovieAdapter = MovieAdapter() 22 | 23 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 24 | return inflater.inflate(R.layout.fragment_movie, container, false) 25 | } 26 | 27 | override fun onActivityCreated(savedInstanceState: Bundle?) { 28 | super.onActivityCreated(savedInstanceState) 29 | 30 | setupRecyclerView() 31 | setupObservers() 32 | } 33 | 34 | private fun setupObservers() { 35 | //Current currency 36 | observe(viewModel.movie, { 37 | it?.let { 38 | adapter.dataList = it 39 | } 40 | showNoDataFound(adapter.dataList.isEmpty()) 41 | }) 42 | 43 | //ProgressBar 44 | observe(viewModel.isDataLoading, { 45 | if (it == true) { 46 | viewProgressBar.visible() 47 | } else { 48 | viewProgressBar.gone() 49 | } 50 | }) 51 | 52 | observe(viewModel.exception, { 53 | showErrorMessage(it?.message) 54 | }) 55 | } 56 | 57 | private fun showErrorMessage(message: String?) { 58 | message?.let { 59 | alert(message, getString(R.string.error)) { 60 | yesButton { } 61 | }.show() 62 | viewModel.exception.value = null 63 | } 64 | } 65 | 66 | private fun showNoDataFound(show: Boolean) { 67 | if (show) { 68 | viewError.visible() 69 | textViewError.text = getString(R.string.no_movie_found) 70 | } else { 71 | viewError.gone() 72 | } 73 | } 74 | 75 | private fun setupRecyclerView() { 76 | recyclerView.adapter = adapter 77 | } 78 | } -------------------------------------------------------------------------------- /app/src/main/java/com/maiconhellmann/architecture/view/main/SeriesFragment.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture.view.main 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import com.maiconhellmann.architecture.R 8 | import com.maiconhellmann.architecture.misc.ext.gone 9 | import com.maiconhellmann.architecture.misc.ext.observe 10 | import com.maiconhellmann.architecture.misc.ext.visible 11 | import com.maiconhellmann.architecture.view.BaseFragment 12 | import kotlinx.android.synthetic.main.fragment_movie.* 13 | import org.jetbrains.anko.support.v4.alert 14 | import org.jetbrains.anko.yesButton 15 | import org.koin.android.architecture.ext.viewModel 16 | 17 | class SeriesFragment : BaseFragment() { 18 | 19 | val viewModel: MainViewModel by viewModel() 20 | 21 | private var adapter: MovieAdapter = MovieAdapter() 22 | 23 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 24 | return inflater.inflate(R.layout.fragment_movie, container, false) 25 | } 26 | 27 | override fun onActivityCreated(savedInstanceState: Bundle?) { 28 | super.onActivityCreated(savedInstanceState) 29 | 30 | setupRecyclerView() 31 | setupObservers() 32 | } 33 | 34 | private fun setupObservers() { 35 | //Current currency 36 | observe(viewModel.series, { 37 | it?.let { 38 | adapter.dataList = it 39 | } 40 | showNoDataFound(adapter.dataList.isEmpty()) 41 | }) 42 | 43 | //ProgressBar 44 | observe(viewModel.isDataLoading, { 45 | if (it == true) { 46 | viewProgressBar.visible() 47 | } else { 48 | viewProgressBar.gone() 49 | } 50 | }) 51 | 52 | observe(viewModel.exception, { 53 | showErrorMessage(it?.message) 54 | }) 55 | } 56 | 57 | private fun showErrorMessage(message: String?) { 58 | message?.let { 59 | alert(message, getString(R.string.error)) { 60 | yesButton { } 61 | }.show() 62 | viewModel.exception.value = null 63 | } 64 | } 65 | 66 | private fun showNoDataFound(show: Boolean) { 67 | if (show) { 68 | viewError.visible() 69 | textViewError.text = getString(R.string.no_series_found) 70 | } else { 71 | viewError.gone() 72 | } 73 | } 74 | 75 | private fun setupRecyclerView() { 76 | recyclerView.adapter = adapter 77 | } 78 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_error_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_local_movies_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_movie_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_movie_filter_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 22 | 23 | 31 | 32 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_movie.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 29 | 30 | 38 | 39 | 40 | 41 | 51 | 52 | 66 | 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/row_movie.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/menu/navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8dp 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Architecture 3 | Search movie 4 | Movie 5 | Series 6 | Episode 7 | Error 8 | No series found 9 | No episode found 10 | No movie found 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/maiconhellmann/architecture/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.maiconhellmann.architecture 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.2.31' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.1' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | kotlin.coroutines=enable 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maiconhellmann/kotlin-mvvm-coroutines-koin/3348868cae1ca58d98af111bdc1050e8ea220abb/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Apr 15 17:59:53 WEST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------