├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── gradle.xml ├── jarRepositories.xml ├── kotlinScripting.xml ├── navEditor.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── developersancho │ │ └── mvvm │ │ └── ExampleInstrumentedTest.kt │ ├── dev │ ├── AndroidManifest.xml │ └── res │ │ └── values │ │ └── strings.xml │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── developersancho │ │ │ └── mvvm │ │ │ ├── CoreApp.kt │ │ │ ├── base │ │ │ ├── BaseActivity.kt │ │ │ ├── BaseFragment.kt │ │ │ ├── BaseViewHolder.kt │ │ │ ├── BaseViewModel.kt │ │ │ └── IBasePresenter.kt │ │ │ ├── di │ │ │ ├── AppModule.kt │ │ │ └── ViewModelModule.kt │ │ │ └── ui │ │ │ ├── databindingtest │ │ │ ├── DViewModel.kt │ │ │ ├── DataBindingTestActivity.kt │ │ │ └── DataBindingTestFragment.kt │ │ │ ├── main │ │ │ ├── IMainPresenter.kt │ │ │ ├── MainActivity.kt │ │ │ └── MainViewModel.kt │ │ │ └── viewbindingtest │ │ │ ├── VViewModel.kt │ │ │ ├── ViewBindingTestActivity.kt │ │ │ └── ViewBindingTestFragment.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── ripple_light_with_border.xml │ │ ├── layout │ │ ├── activity_data_binding_test.xml │ │ ├── activity_main.xml │ │ ├── activity_view_binding_test.xml │ │ ├── fragment_data_binding_test.xml │ │ └── fragment_view_binding_test.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 │ │ ├── navigation │ │ ├── nav_graph_data_binding.xml │ │ └── nav_graph_view_binding.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── network_security_config.xml │ └── test │ └── java │ └── developersancho │ └── mvvm │ └── ExampleUnitTest.kt ├── build.gradle ├── buildSrc ├── build.gradle.kts └── src │ └── main │ └── java │ └── Dependencies.kt ├── common ├── util │ ├── .gitignore │ ├── build.gradle │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── developersancho │ │ │ └── util │ │ │ └── ExampleInstrumentedTest.kt │ │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── developersancho │ │ │ └── util │ │ │ ├── NetworkUtils.kt │ │ │ └── extensions │ │ │ └── ActivityExtensions.kt │ │ └── test │ │ └── java │ │ └── com │ │ └── developersancho │ │ └── util │ │ └── ExampleUnitTest.kt └── widget │ ├── .gitignore │ ├── build.gradle │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── developersancho │ │ └── widget │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── developersancho │ │ │ └── widget │ │ │ └── ProgressLoadingDialog.kt │ └── res │ │ └── layout │ │ └── dialog_progress_loading.xml │ └── test │ └── java │ └── com │ └── developersancho │ └── widget │ └── ExampleUnitTest.kt ├── core ├── local │ ├── .gitignore │ ├── build.gradle │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── developersancho │ │ │ └── local │ │ │ ├── dao │ │ │ ├── BaseDao.kt │ │ │ └── FavDao.kt │ │ │ ├── db │ │ │ └── CoreDatabase.kt │ │ │ ├── di │ │ │ └── LocalModule.kt │ │ │ └── entity │ │ │ └── FavEntity.kt │ │ └── test │ │ └── java │ │ └── com │ │ └── developersancho │ │ └── local │ │ ├── BaseLocalTest.kt │ │ └── FavDaoTest.kt ├── manager │ ├── .gitignore │ ├── build.gradle │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── developersancho │ │ │ └── manager │ │ │ └── ExampleInstrumentedTest.kt │ │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── developersancho │ │ │ └── manager │ │ │ ├── DataManager.kt │ │ │ ├── IDataManager.kt │ │ │ ├── base │ │ │ └── BaseDataManager.kt │ │ │ └── di │ │ │ └── ManagerModule.kt │ │ └── test │ │ └── java │ │ └── com │ │ └── developersancho │ │ └── manager │ │ ├── BaseManagerTest.kt │ │ └── ManagerTest.kt └── remote │ ├── .gitignore │ ├── build.gradle │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── developersancho │ │ └── remote │ │ ├── di │ │ └── RemoteModule.kt │ │ ├── model │ │ ├── License.kt │ │ ├── Owner.kt │ │ ├── RepoResponse.kt │ │ └── Repos.kt │ │ ├── network │ │ ├── AuthInterceptor.kt │ │ ├── NetworkState.kt │ │ └── RemoteDataException.kt │ │ └── service │ │ └── IRepoService.kt │ └── test │ └── java │ └── com │ └── developersancho │ └── remote │ ├── BaseRemoteTest.kt │ └── RepoServiceTest.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── module-1.png └── module-2.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/androidstudio 2 | # Edit at https://www.gitignore.io/?templates=androidstudio 3 | 4 | ### AndroidStudio ### 5 | # Covers files to be ignored for android development using Android Studio. 6 | 7 | # Built application files 8 | *.apk 9 | *.ap_ 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle 24 | .gradle/ 25 | build/ 26 | 27 | # Signing files 28 | .signing/ 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | # Log Files 37 | *.log 38 | 39 | # Android Studio 40 | /*/build/ 41 | /*/local.properties 42 | /*/out 43 | /*/*/build 44 | /*/*/production 45 | captures/ 46 | .navigation/ 47 | *.ipr 48 | *~ 49 | *.swp 50 | 51 | # Android Patch 52 | gen-external-apklibs 53 | 54 | # External native build folder generated in Android Studio 2.2 and later 55 | .externalNativeBuild 56 | 57 | # NDK 58 | obj/ 59 | 60 | # IntelliJ IDEA 61 | *.iml 62 | *.iws 63 | /out/ 64 | 65 | # User-specific configurations 66 | .idea/caches/ 67 | .idea/libraries/ 68 | .idea/shelf/ 69 | .idea/workspace.xml 70 | .idea/tasks.xml 71 | .idea/.name 72 | .idea/compiler.xml 73 | .idea/copyright/profiles_settings.xml 74 | .idea/encodings.xml 75 | .idea/misc.xml 76 | .idea/modules.xml 77 | .idea/scopes/scope_settings.xml 78 | .idea/dictionaries 79 | .idea/vcs.xml 80 | .idea/jsLibraryMappings.xml 81 | .idea/datasources.xml 82 | .idea/dataSources.ids 83 | .idea/sqlDataSources.xml 84 | .idea/dynamic.xml 85 | .idea/uiDesigner.xml 86 | .idea/assetWizardSettings.xml 87 | 88 | # OS-specific files 89 | .DS_Store 90 | .DS_Store? 91 | ._* 92 | .Spotlight-V100 93 | .Trashes 94 | ehthumbs.db 95 | Thumbs.db 96 | 97 | # Legacy Eclipse project files 98 | .classpath 99 | .project 100 | .cproject 101 | .settings/ 102 | 103 | # Mobile Tools for Java (J2ME) 104 | .mtj.tmp/ 105 | 106 | # Package Files # 107 | *.war 108 | *.ear 109 | 110 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 111 | hs_err_pid* 112 | 113 | ## Plugin-specific files: 114 | 115 | # mpeltonen/sbt-idea plugin 116 | .idea_modules/ 117 | 118 | # JIRA plugin 119 | atlassian-ide-plugin.xml 120 | 121 | # Mongo Explorer plugin 122 | .idea/mongoSettings.xml 123 | 124 | # Crashlytics plugin (for Android Studio and IntelliJ) 125 | com_crashlytics_export_strings.xml 126 | crashlytics.properties 127 | crashlytics-build.properties 128 | fabric.properties 129 | 130 | ### AndroidStudio Patch ### 131 | 132 | !/gradle/wrapper/gradle-wrapper.jar 133 | 134 | # End of https://www.gitignore.io/api/androidstudio 135 | 136 | # Variant 137 | debug 138 | release 139 | staging 140 | 141 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | -------------------------------------------------------------------------------- /.idea/kotlinScripting.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/navEditor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 52 | 53 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # New Version Of Clean Architecture MVVM 2 | 3 | [Rorty Native Android Project](https://github.com/developersancho/Rorty.Android) - you can reach here. 4 | 5 | [Rorty Native Android Medium Post](https://developersancho.medium.com/android-modular-clean-architecture-with-rorty-app-5b4b08398492) - you can reach here. 6 | 7 | 8 | ## CleanArchitectureMVVM 9 | [![Kotlin Version](https://img.shields.io/badge/kotlin-1.3.61-blue.svg)](http://kotlinlang.org/) 10 | [![Gradle](https://img.shields.io/badge/gradle-5.6.4-blue.svg)](https://lv.binarybabel.org/catalog/gradle/latest) 11 | [![API](https://img.shields.io/badge/API-19%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=21) 12 | [![License](https://img.shields.io/badge/License-Apache%202.0-lightgrey.svg)](http://www.apache.org/licenses/LICENSE-2.0) 13 | 14 | Example of Clean Architecture of Android app using MVVM, Koin, Coroutines, Retrofit, Room, Solid Principle, DRY, KISS, OOP, Unit Test 15 | 16 | This Base Architecture project that presents modern, 2019 approach to [Android](https://www.android.com/) application development 17 | using [Kotlin](https://kotlinlang.org/) 18 | 19 | The trick of the project is to demonstrate best practices, provide a set of guidelines, and present modern Android Application Architecture 20 | that is modular, scalable, maintainable and testable, suitable for bigger teams and long application lifecycle management. 21 | 22 | ## Environment setup 23 | You require the latest Android Studio 3.6 RC1 (or newer) to be able to build the app. 24 | 25 | ## Multi-Module -1 26 | ![Module Structure](screenshots/module-1.png "Multi-Module 1") 27 | 28 | ## Multi-Module -2 29 | ![Module Structure](screenshots/module-2.png "Multi-Module 2") 30 | 31 | ### Dependencies 32 | 33 | - [Jetpack](https://developer.android.com/jetpack): 34 | - [Android KTX](https://developer.android.com/kotlin/ktx.html) - provide concise, idiomatic Kotlin to Jetpack and Android platform APIs. 35 | - [AndroidX](https://developer.android.com/jetpack/androidx) - major improvement to the original Android [Support Library](https://developer.android.com/topic/libraries/support-library/index), which is no longer maintained. 36 | - [Benchmark](https://developer.android.com/studio/profile/benchmark.html) - handles warmup, measures your code performance, and outputs benchmarking results to the Android Studio console. 37 | - [Data Binding](https://developer.android.com/topic/libraries/data-binding/) - allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically. 38 | - [View Binding](https://developer.android.com/topic/libraries/view-binding/) - allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically. 39 | - [Lifecycle](https://developer.android.com/topic/libraries/architecture/lifecycle) - perform actions in response to a change in the lifecycle status of another component, such as activities and fragments. 40 | - [LiveData](https://developer.android.com/topic/libraries/architecture/livedata) - lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services. 41 | - [Navigation](https://developer.android.com/guide/navigation/) - helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer. 42 | - [Room](https://developer.android.com/topic/libraries/architecture/room) - persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite. 43 | - [ViewModel](https://developer.android.com/topic/libraries/architecture/viewmodel) - designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations. 44 | - [Coroutines](https://kotlinlang.org/docs/reference/coroutines-overview.html) - managing background threads with simplified code and reducing needs for callbacks. 45 | - [Coroutines-Flow](https://kotlinlang.org/docs/reference/coroutines/flow.html) - suspending functions asynchronously returns a single value, but how can we return multiple asynchronously computed values? This is where Kotlin Flows come in. 46 | - [Koin](https://insert-koin.io/) - dependency injector for replacement all FactoryFactory classes. 47 | - [Retrofit](https://square.github.io/retrofit/) - type-safe HTTP client. 48 | - [Glide](https://github.com/bumptech/glide) - image loading and caching library for Android focused on smooth scrolling. 49 | - [Gson](https://github.com/google/gson) - makes it easy to parse JSON into Kotlin objects. 50 | - [Timber](https://github.com/JakeWharton/timber) - a logger with a small, extensible API which provides utility on top of Android's normal Log class. 51 | - [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl-samples) - makes it easy to manage dependency all module that we have 52 | - [and more...](https://github.com/developersancho/CleanArchitectureMVVM/blob/development/buildSrc/src/main/java/Dependencies.kt) 53 | 54 | ### Test Dependencies 55 | 56 | - [Robolectric](https://github.com/robolectric/robolectric) - industry-standard unit testing framework for Android. 57 | - [JUnit](https://github.com/junit-team/junit4) - a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks. 58 | - [Koin Test](https://start.insert-koin.io/#/getting-started/testing) - project brings you small but powerfull tools to test your Koin application. 59 | - [Coroutine Test](https://github.com/Kotlin/kotlinx.coroutines/tree/master/kotlinx-coroutines-test) - provides testing utilities for effectively testing coroutines. 60 | - [and more...](https://github.com/developersancho/CleanArchitectureMVVM/blob/development/buildSrc/src/main/java/Dependencies.kt) 61 | 62 | ### Plugins 63 | - [Versions](https://github.com/ben-manes/gradle-versions-plugin) - make easy to determine which dependencies have updates. 64 | - [SafeArgs](https://developer.android.com/guide/navigation/navigation-pass-data#Safe-args) - generates simple object and builder classes for type-safe navigation and access to any associated arguments. 65 | 66 | ## Contributions 67 | 68 | All contributions are welcome! 69 | Please feel free to post questions, recommendations, ideas, bugs by create [new issue](https://github.com/developersancho/CleanArchitectureMVVM/issues/new) following the template or if you want create directly [new pull request](https://github.com/developersancho/CleanArchitectureMVVM/compare). 70 | 71 | ## Special Thanks 72 | - [Mehmet Taş](https://github.com/mehmettas) 73 | - [Pelin Gül Çınar](https://github.com/pelingcinar) 74 | - [Mücahit Kambur](https://github.com/mucahitkambur) 75 | 76 | ## License 77 | Copyright 2019 developersancho. 78 | 79 | Licensed under the Apache License, Version 2.0 (the "License"); 80 | you may not use this file except in compliance with the License. 81 | You may obtain a copy of the License at 82 | 83 | http://www.apache.org/licenses/LICENSE-2.0 84 | 85 | Unless required by applicable law or agreed to in writing, software 86 | distributed under the License is distributed on an "AS IS" BASIS, 87 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 88 | See the License for the specific language governing permissions and 89 | limitations under the License. 90 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/androidstudio 2 | # Edit at https://www.gitignore.io/?templates=androidstudio 3 | 4 | ### AndroidStudio ### 5 | # Covers files to be ignored for android development using Android Studio. 6 | 7 | # Built application files 8 | *.apk 9 | *.ap_ 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle 24 | .gradle/ 25 | build/ 26 | 27 | # Signing files 28 | .signing/ 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | # Log Files 37 | *.log 38 | 39 | # Android Studio 40 | /*/build/ 41 | /*/local.properties 42 | /*/out 43 | /*/*/build 44 | /*/*/production 45 | captures/ 46 | .navigation/ 47 | *.ipr 48 | *~ 49 | *.swp 50 | 51 | # Android Patch 52 | gen-external-apklibs 53 | 54 | # External native build folder generated in Android Studio 2.2 and later 55 | .externalNativeBuild 56 | 57 | # NDK 58 | obj/ 59 | 60 | # IntelliJ IDEA 61 | *.iml 62 | *.iws 63 | /out/ 64 | 65 | # User-specific configurations 66 | .idea/caches/ 67 | .idea/libraries/ 68 | .idea/shelf/ 69 | .idea/workspace.xml 70 | .idea/tasks.xml 71 | .idea/.name 72 | .idea/compiler.xml 73 | .idea/copyright/profiles_settings.xml 74 | .idea/encodings.xml 75 | .idea/misc.xml 76 | .idea/modules.xml 77 | .idea/scopes/scope_settings.xml 78 | .idea/dictionaries 79 | .idea/vcs.xml 80 | .idea/jsLibraryMappings.xml 81 | .idea/datasources.xml 82 | .idea/dataSources.ids 83 | .idea/sqlDataSources.xml 84 | .idea/dynamic.xml 85 | .idea/uiDesigner.xml 86 | .idea/assetWizardSettings.xml 87 | 88 | # OS-specific files 89 | .DS_Store 90 | .DS_Store? 91 | ._* 92 | .Spotlight-V100 93 | .Trashes 94 | ehthumbs.db 95 | Thumbs.db 96 | 97 | # Legacy Eclipse project files 98 | .classpath 99 | .project 100 | .cproject 101 | .settings/ 102 | 103 | # Mobile Tools for Java (J2ME) 104 | .mtj.tmp/ 105 | 106 | # Package Files # 107 | *.war 108 | *.ear 109 | 110 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 111 | hs_err_pid* 112 | 113 | ## Plugin-specific files: 114 | 115 | # mpeltonen/sbt-idea plugin 116 | .idea_modules/ 117 | 118 | # JIRA plugin 119 | atlassian-ide-plugin.xml 120 | 121 | # Mongo Explorer plugin 122 | .idea/mongoSettings.xml 123 | 124 | # Crashlytics plugin (for Android Studio and IntelliJ) 125 | com_crashlytics_export_strings.xml 126 | crashlytics.properties 127 | crashlytics-build.properties 128 | fabric.properties 129 | 130 | ### AndroidStudio Patch ### 131 | 132 | !/gradle/wrapper/gradle-wrapper.jar 133 | 134 | # End of https://www.gitignore.io/api/androidstudio 135 | 136 | # Variant 137 | debug 138 | release 139 | staging 140 | 141 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("kotlin-android") 4 | id("kotlin-android-extensions") 5 | id("kotlin-kapt") 6 | id("androidx.navigation.safeargs.kotlin") 7 | } 8 | 9 | def buildVersionCode = new Date().format("yyMMddHHmm", TimeZone.getTimeZone("Europe/Istanbul")).toInteger() 10 | 11 | android { 12 | compileSdkVersion(Versions.compileSdk) 13 | buildToolsVersion(Versions.buildTools) 14 | 15 | defaultConfig { 16 | applicationId = ApplicationId.id 17 | minSdkVersion(Versions.minSdk) 18 | targetSdkVersion(Versions.targetSdk) 19 | testInstrumentationRunner(BuildPlugins.testInstrumentationRunner) 20 | vectorDrawables.useSupportLibrary(BuildPlugins.supportLibraryVectorDrawables) 21 | multiDexEnabled(BuildPlugins.multidexEnable) 22 | } 23 | 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 28 | } 29 | 30 | debug { 31 | debuggable true 32 | minifyEnabled false 33 | } 34 | } 35 | 36 | configurations.all { 37 | resolutionStrategy.eachDependency { DependencyResolveDetails details -> 38 | def requested = details.requested 39 | if (requested.group == "androidx.appcompat") { 40 | if (!requested.name.startsWith("multidex")) { 41 | details.useVersion "1.+" 42 | } 43 | } 44 | } 45 | } 46 | 47 | compileOptions { 48 | sourceCompatibility = JavaVersion.VERSION_1_8 49 | targetCompatibility = JavaVersion.VERSION_1_8 50 | } 51 | 52 | kotlinOptions { 53 | jvmTarget = JavaVersion.VERSION_1_8.toString() 54 | } 55 | 56 | dataBinding.enabled = true 57 | 58 | viewBinding.enabled = true 59 | 60 | androidExtensions { 61 | experimental = true 62 | } 63 | 64 | kapt { 65 | useBuildCache = true 66 | } 67 | 68 | 69 | flavorDimensions 'default' 70 | 71 | productFlavors { 72 | 73 | dev { 74 | dimension = 'default' 75 | applicationIdSuffix = '.dev' 76 | versionCode = buildVersionCode 77 | versionName = '1.0.0' 78 | versionNameSuffix = '-dev' 79 | buildConfigField("String", "BASE_URL", "\"https://api.github.com/\"") 80 | buildConfigField("String", "ROOT_URL", "\"https://api.github.com/\"") 81 | buildConfigField("String", "API_HOST", "\"api.github.com/\"") 82 | buildConfigField("String", 'DB_NAME', '"github.db"') 83 | resValue "string", "app_name", "Test - App" 84 | } 85 | 86 | prod { 87 | dimension = 'default' 88 | applicationIdSuffix = '' 89 | versionCode = buildVersionCode 90 | versionName = '1.0.0' 91 | versionNameSuffix = '' 92 | buildConfigField("String", "BASE_URL", "\"https://api.github.com/\"") 93 | buildConfigField("String", "ROOT_URL", "\"https://api.github.com/\"") 94 | buildConfigField("String", "API_HOST", "\"api.github.com/\"") 95 | buildConfigField("String", 'DB_NAME', '"github.db"') 96 | resValue "string", "app_name", "Prod - App" 97 | } 98 | } 99 | } 100 | 101 | android.applicationVariants.all { variant -> 102 | def appName = "base-app" 103 | variant.outputs.all { output -> 104 | def newApkName = "${appName}-${variant.versionName}.apk" 105 | output.outputFileName = new File(newApkName) 106 | } 107 | } 108 | 109 | dependencies { 110 | implementation fileTree(dir: 'libs', include: ['*.jar']) 111 | implementation project(Modules.manager) 112 | implementation project(Modules.local) 113 | implementation project(Modules.remote) 114 | implementation project(Modules.widget) 115 | implementation project(Modules.util) 116 | 117 | implementation(Libraries.kotlinStdLib) 118 | implementation(Libraries.appCompat) 119 | implementation(Libraries.coreKtx) 120 | implementation(Libraries.constraintLayout) 121 | implementation(Libraries.material) 122 | implementation(Libraries.legacy) 123 | // firebase 124 | implementation(Libraries.firebaseCore) 125 | 126 | // Bindings 127 | kapt(Libraries.databinding) 128 | 129 | // navigation 130 | implementation(Libraries.navFragmentKtx) 131 | implementation(Libraries.navUiKtx) 132 | // Coroutines 133 | implementation(Libraries.kotlinCoroutineCore) 134 | implementation(Libraries.kotlinCoroutineAndroid) 135 | // retrofit - gson 136 | implementation(Libraries.gson) 137 | implementation(Libraries.retrofit) 138 | implementation(Libraries.retrofitConvertorGson) 139 | // okhttp 140 | implementation(Libraries.okhttp) 141 | implementation(Libraries.okhttpLogging) 142 | // lifecycle 143 | implementation(Libraries.lifeCycleViewModelKtx) 144 | implementation(Libraries.lifeCycleLiveDataKtx) 145 | implementation(Libraries.lifeCycleRunTimeKtx) 146 | kapt(Libraries.lifeCycleCommon) 147 | // koin for di 148 | implementation(Libraries.koinCore) 149 | implementation(Libraries.koinAndroid) 150 | implementation(Libraries.koinScope) 151 | implementation(Libraries.koinViewModel) 152 | // room 153 | implementation(Libraries.room) 154 | kapt(Libraries.roomCompiler) 155 | // glide 156 | implementation(Libraries.glide) 157 | kapt(Libraries.glideCompiler) 158 | // timber 159 | implementation(Libraries.timber) 160 | 161 | // test implementation 162 | testImplementation(Libraries.koinTest) 163 | testImplementation(Libraries.lifeCycleTest) 164 | testImplementation(Libraries.junit) 165 | // android test implementation 166 | androidTestImplementation(Libraries.junitExt) 167 | androidTestImplementation(Libraries.espressoCore) 168 | } 169 | -------------------------------------------------------------------------------- /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/developersancho/mvvm/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext 22 | assertEquals("developersancho.mvvm.dev", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/dev/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/dev/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/CoreApp.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm 2 | 3 | import android.content.Context 4 | import androidx.multidex.MultiDexApplication 5 | import developersancho.mvvm.di.appModule 6 | import org.koin.android.ext.koin.androidContext 7 | import org.koin.android.ext.koin.androidFileProperties 8 | import org.koin.android.ext.koin.androidLogger 9 | import org.koin.core.context.startKoin 10 | import timber.log.Timber 11 | 12 | class CoreApp : MultiDexApplication() { 13 | 14 | companion object { 15 | lateinit var context: Context 16 | } 17 | 18 | override fun onCreate() { 19 | super.onCreate() 20 | context = applicationContext 21 | configureDi() 22 | configureTimber() 23 | } 24 | 25 | private fun configureTimber() { 26 | Timber.plant(Timber.DebugTree()) 27 | } 28 | 29 | private fun configureDi() = startKoin { 30 | // use AndroidLogger as Koin Logger - default Level.INFO 31 | if (BuildConfig.DEBUG) 32 | androidLogger() 33 | // use the Android context given there 34 | androidContext(this@CoreApp) 35 | // load properties from assets/koin.properties file 36 | androidFileProperties() 37 | // module list 38 | modules(appModule) 39 | } 40 | } -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/base/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.base 2 | 3 | import android.R 4 | import android.os.Bundle 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import androidx.annotation.LayoutRes 8 | import androidx.appcompat.app.AppCompatActivity 9 | import androidx.databinding.DataBindingUtil 10 | import androidx.databinding.ViewDataBinding 11 | import androidx.fragment.app.FragmentActivity 12 | import androidx.viewbinding.ViewBinding 13 | import com.developersancho.widget.ProgressLoadingDialog 14 | 15 | abstract class BaseActivity : AppCompatActivity(), IBasePresenter { 16 | 17 | private val progress: ProgressLoadingDialog by lazy { 18 | ProgressLoadingDialog(context = this) 19 | } 20 | 21 | @get:LayoutRes 22 | protected abstract val layoutId: Int? 23 | 24 | protected abstract fun initPresenter() 25 | 26 | protected abstract fun initUI() 27 | 28 | protected abstract fun initListener() 29 | 30 | private fun initBinding() {} 31 | 32 | override fun onCreate(savedInstanceState: Bundle?) { 33 | super.onCreate(savedInstanceState) 34 | 35 | layoutId?.let { 36 | setContentView(it) 37 | } ?: run { 38 | initBinding() 39 | } 40 | 41 | initPresenter() 42 | initUI() 43 | initListener() 44 | } 45 | 46 | 47 | override fun showLoading() { 48 | progress.toggle(status = true) 49 | } 50 | 51 | override fun hideLoading() { 52 | progress.release() 53 | } 54 | 55 | override fun showError(code: Int, message: String) { 56 | 57 | } 58 | 59 | override fun showSuccess(title: String, message: String) { 60 | 61 | } 62 | } 63 | 64 | // Extension for data-binding and view-binding START 65 | 66 | fun FragmentActivity.dataBinding(): Lazy = object : Lazy { 67 | private var binding: T? = null 68 | 69 | override fun isInitialized(): Boolean = binding != null 70 | 71 | override val value: T 72 | get() = binding ?: bind(getContentView()).also { 73 | it.lifecycleOwner = this@dataBinding 74 | binding = it 75 | } 76 | 77 | private fun FragmentActivity.getContentView(): View { 78 | return checkNotNull(findViewById(R.id.content).getChildAt(0)) { 79 | "Call setContentView or Use Activity's secondary constructor passing layout res id." 80 | } 81 | } 82 | 83 | private fun bind(view: View): T = DataBindingUtil.bind(view)!! 84 | } 85 | 86 | 87 | fun FragmentActivity.viewBinding(bind: (View) -> T): Lazy = object : Lazy { 88 | private var binding: T? = null 89 | 90 | override fun isInitialized(): Boolean = binding != null 91 | 92 | override val value: T 93 | get() = binding ?: bind(getContentView()).also { 94 | binding = it 95 | } 96 | 97 | private fun FragmentActivity.getContentView(): View { 98 | return checkNotNull(findViewById(R.id.content).getChildAt(0)) { 99 | "Call setContentView or Use Activity's secondary constructor passing layout res id." 100 | } 101 | } 102 | } 103 | 104 | // Extension for data-binding and view-binding END -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/base/BaseFragment.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.base 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import androidx.annotation.LayoutRes 8 | import androidx.databinding.DataBindingUtil 9 | import androidx.databinding.ViewDataBinding 10 | import androidx.fragment.app.Fragment 11 | import androidx.viewbinding.ViewBinding 12 | import com.developersancho.widget.ProgressLoadingDialog 13 | import kotlin.properties.ReadOnlyProperty 14 | import kotlin.reflect.KProperty 15 | 16 | abstract class BaseFragment : Fragment(), IBasePresenter { 17 | 18 | private val progress: ProgressLoadingDialog by lazy { 19 | ProgressLoadingDialog(context = requireContext()) 20 | } 21 | 22 | @get:LayoutRes 23 | protected abstract val layoutId: Int? 24 | 25 | protected abstract fun initPresenter() 26 | 27 | protected abstract fun initUI(view: View) 28 | 29 | protected abstract fun initListener() 30 | 31 | open fun initBinding(inflater: LayoutInflater, container: ViewGroup?): View? = null 32 | 33 | override fun onCreateView( 34 | inflater: LayoutInflater, 35 | container: ViewGroup?, 36 | savedInstanceState: Bundle? 37 | ): View? { 38 | initPresenter() 39 | 40 | return layoutId?.let { 41 | inflater.inflate(it, container, false) 42 | } ?: run { 43 | initBinding(inflater, container) 44 | } 45 | 46 | } 47 | 48 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 49 | super.onViewCreated(view, savedInstanceState) 50 | initUI(view) 51 | initListener() 52 | } 53 | 54 | override fun showLoading() { 55 | progress.toggle(status = true) 56 | } 57 | 58 | override fun hideLoading() { 59 | progress.release() 60 | } 61 | 62 | override fun showError(code: Int, message: String) { 63 | 64 | } 65 | 66 | override fun showSuccess(title: String, message: String) { 67 | 68 | } 69 | 70 | } 71 | 72 | // Extension for data-binding and view-binding START 73 | 74 | fun Fragment.viewBinding(bind: (View) -> T): ReadOnlyProperty = 75 | object : ReadOnlyProperty { 76 | @Suppress("UNCHECKED_CAST") 77 | override fun getValue(thisRef: Fragment, property: KProperty<*>): T { 78 | (requireView().getTag(property.name.hashCode()) as? T)?.let { return it } 79 | return bind(requireView()).also { 80 | requireView().setTag(property.name.hashCode(), it) 81 | } 82 | } 83 | } 84 | 85 | fun Fragment.dataBinding(): ReadOnlyProperty { 86 | return object : ReadOnlyProperty { 87 | @Suppress("UNCHECKED_CAST") 88 | override fun getValue(thisRef: Fragment, property: KProperty<*>): T { 89 | (requireView().getTag(property.name.hashCode()) as? T)?.let { return it } 90 | return bind(requireView()).also { 91 | it.lifecycleOwner = thisRef.viewLifecycleOwner 92 | it.root.setTag(property.name.hashCode(), it) 93 | } 94 | } 95 | 96 | private fun bind(view: View): T = DataBindingUtil.bind(view)!! 97 | } 98 | } 99 | 100 | // Extension for data-binding and view-binding END -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/base/BaseViewHolder.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.base 2 | 3 | import android.view.View 4 | import androidx.databinding.DataBindingUtil 5 | import androidx.databinding.ViewDataBinding 6 | import androidx.recyclerview.widget.RecyclerView 7 | import androidx.viewbinding.ViewBinding 8 | 9 | fun RecyclerView.ViewHolder.dataBinding(): Lazy = object : Lazy { 10 | private var binding: T? = null 11 | 12 | override val value: T 13 | get() = binding ?: bind(getContentView()).also { 14 | binding = it 15 | } 16 | 17 | override fun isInitialized(): Boolean = binding != null 18 | 19 | private fun RecyclerView.ViewHolder.getContentView(): View { 20 | return checkNotNull(itemView.rootView) { 21 | "Call binding view holder" 22 | } 23 | } 24 | 25 | private fun bind(view: View): T = DataBindingUtil.bind(view)!! 26 | 27 | } 28 | 29 | fun RecyclerView.ViewHolder.viewBinding(bind: (View) -> T): Lazy = 30 | object : Lazy { 31 | private var binding: T? = null 32 | 33 | override val value: T 34 | get() = binding ?: bind(getContentView()).also { 35 | binding = it 36 | } 37 | 38 | override fun isInitialized(): Boolean = binding != null 39 | 40 | private fun RecyclerView.ViewHolder.getContentView(): View { 41 | return checkNotNull(itemView.rootView) { 42 | "Call binding view holder" 43 | } 44 | } 45 | 46 | private fun bind(view: View): T = DataBindingUtil.bind(view)!! 47 | 48 | } -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/base/BaseViewModel.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.base 2 | 3 | import androidx.lifecycle.ViewModel 4 | import com.developersancho.manager.IDataManager 5 | import java.lang.ref.WeakReference 6 | 7 | abstract class BaseViewModel

(val dataManager: IDataManager) : ViewModel() { 8 | 9 | private lateinit var presenter: WeakReference

10 | 11 | fun getPresenter(): P? { 12 | return presenter.get() 13 | } 14 | 15 | fun setPresenter(presenter: P) { 16 | this.presenter = WeakReference(presenter) 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/base/IBasePresenter.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.base 2 | 3 | interface IBasePresenter { 4 | 5 | fun showLoading() 6 | fun hideLoading() 7 | fun showError(code: Int, message: String) 8 | fun showSuccess(title: String, message: String) 9 | } -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/di/AppModule.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.di 2 | 3 | import com.developersancho.local.di.localModule 4 | import com.developersancho.manager.di.managerModule 5 | import com.developersancho.remote.di.remoteModule 6 | import developersancho.mvvm.BuildConfig 7 | 8 | val appModule = listOf( 9 | remoteModule(BuildConfig.BASE_URL, isDebug = BuildConfig.DEBUG), 10 | localModule(BuildConfig.DB_NAME), 11 | managerModule, 12 | viewModelModule 13 | ) -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/di/ViewModelModule.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.di 2 | 3 | import developersancho.mvvm.ui.databindingtest.DViewModel 4 | import developersancho.mvvm.ui.main.MainViewModel 5 | import developersancho.mvvm.ui.viewbindingtest.VViewModel 6 | import org.koin.androidx.viewmodel.dsl.viewModel 7 | import org.koin.dsl.module 8 | 9 | val viewModelModule = module { 10 | viewModel { MainViewModel(get()) } 11 | viewModel { DViewModel(get()) } 12 | viewModel { VViewModel(get()) } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/databindingtest/DViewModel.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.databindingtest 2 | 3 | import com.developersancho.manager.IDataManager 4 | import developersancho.mvvm.base.BaseViewModel 5 | import developersancho.mvvm.base.IBasePresenter 6 | 7 | class DViewModel(dataManager: IDataManager) : BaseViewModel(dataManager) -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/databindingtest/DataBindingTestActivity.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.databindingtest 2 | 3 | import androidx.navigation.findNavController 4 | import developersancho.mvvm.R 5 | import developersancho.mvvm.base.BaseActivity 6 | import developersancho.mvvm.base.dataBinding 7 | import developersancho.mvvm.databinding.ActivityDataBindingTestBinding 8 | 9 | class DataBindingTestActivity : BaseActivity() { 10 | 11 | private val binding by dataBinding() 12 | 13 | override val layoutId: Int? 14 | get() = R.layout.activity_data_binding_test 15 | 16 | override fun initPresenter() { 17 | 18 | } 19 | 20 | override fun initUI() { 21 | binding.textDataBindingDsc.text = "DataBindingTestActivity" 22 | } 23 | 24 | override fun initListener() { 25 | 26 | } 27 | 28 | override fun onSupportNavigateUp(): Boolean = 29 | findNavController(R.id.data_nav_host_fragment).navigateUp() 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/databindingtest/DataBindingTestFragment.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.databindingtest 2 | 3 | import android.view.View 4 | import developersancho.mvvm.R 5 | import developersancho.mvvm.base.BaseFragment 6 | import developersancho.mvvm.base.dataBinding 7 | import developersancho.mvvm.databinding.FragmentDataBindingTestBinding 8 | import org.koin.androidx.viewmodel.ext.android.sharedViewModel 9 | 10 | 11 | class DataBindingTestFragment : BaseFragment() { 12 | 13 | private val viewModel by sharedViewModel() 14 | 15 | private val binding by dataBinding() 16 | 17 | override val layoutId: Int? 18 | get() = R.layout.fragment_data_binding_test 19 | 20 | override fun initPresenter() { 21 | viewModel.setPresenter(this) 22 | } 23 | 24 | override fun initUI(view: View) { 25 | binding.textFragDataBinding.text = "DataBindingFragment" 26 | } 27 | 28 | override fun initListener() { 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/main/IMainPresenter.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.main 2 | 3 | import developersancho.mvvm.base.IBasePresenter 4 | 5 | interface IMainPresenter : IBasePresenter { 6 | 7 | fun showRepoSize(size: Int) 8 | 9 | } -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/main/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.main 2 | 3 | import android.content.Intent 4 | import androidx.lifecycle.Observer 5 | import com.developersancho.util.extensions.longToast 6 | import developersancho.mvvm.R 7 | import developersancho.mvvm.base.BaseActivity 8 | import developersancho.mvvm.base.viewBinding 9 | import developersancho.mvvm.databinding.ActivityMainBinding 10 | import developersancho.mvvm.ui.databindingtest.DataBindingTestActivity 11 | import developersancho.mvvm.ui.viewbindingtest.ViewBindingTestActivity 12 | import org.koin.androidx.viewmodel.ext.android.viewModel 13 | 14 | class MainActivity : BaseActivity(), IMainPresenter { 15 | 16 | private val binding by viewBinding { ActivityMainBinding.bind(it) } 17 | 18 | private val viewModel by viewModel() 19 | 20 | override val layoutId: Int? 21 | get() = R.layout.activity_main 22 | 23 | override fun initPresenter() { 24 | viewModel.setPresenter(this) 25 | } 26 | 27 | override fun initUI() { 28 | observeViewModel() 29 | initData() 30 | } 31 | 32 | private fun initData() { 33 | viewModel.getRepos(user = "developersancho") 34 | } 35 | 36 | private fun observeViewModel() { 37 | viewModel.repos.observe(this, Observer { 38 | longToast("repo adı: --> ${it.first().fullName}") 39 | }) 40 | } 41 | 42 | override fun initListener() { 43 | binding.btnD.setOnClickListener { 44 | startActivity(Intent(this, DataBindingTestActivity::class.java)) 45 | } 46 | 47 | binding.btnV.setOnClickListener { 48 | startActivity(Intent(this, ViewBindingTestActivity::class.java)) 49 | } 50 | } 51 | 52 | 53 | override fun showRepoSize(size: Int) { 54 | binding.textCenter.text = "Toplam repo $size tanedir." 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/main/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.main 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.viewModelScope 6 | import com.developersancho.local.entity.FavEntity 7 | import com.developersancho.manager.IDataManager 8 | import com.developersancho.remote.model.Repos 9 | import com.developersancho.remote.network.NetworkState 10 | import developersancho.mvvm.base.BaseViewModel 11 | import kotlinx.coroutines.Dispatchers 12 | import kotlinx.coroutines.flow.collect 13 | import kotlinx.coroutines.launch 14 | 15 | class MainViewModel(dataManager: IDataManager) : BaseViewModel(dataManager) { 16 | 17 | private val _repos: MutableLiveData> = MutableLiveData() 18 | 19 | var repos: LiveData> = _repos 20 | 21 | fun getRepos(user: String) = viewModelScope.launch { 22 | getPresenter()?.showLoading() 23 | dataManager.getRepos(userName = user).collect { state -> 24 | when (state) { 25 | is NetworkState.Success -> { 26 | getPresenter()?.hideLoading() 27 | getPresenter()?.showRepoSize(state.response.size) 28 | _repos.value = state.response 29 | } 30 | is NetworkState.Error -> { 31 | getPresenter()?.hideLoading() 32 | getPresenter()?.showError(state.exception.code, state.exception.message) 33 | } 34 | } 35 | 36 | } 37 | } 38 | 39 | fun insertFavData(favEntity: FavEntity) = viewModelScope.launch(Dispatchers.IO) { 40 | dataManager.insertFav(favEntity = favEntity) 41 | } 42 | 43 | fun getFavList() = viewModelScope.launch(Dispatchers.IO) { 44 | dataManager.favList() 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/viewbindingtest/VViewModel.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.viewbindingtest 2 | 3 | import com.developersancho.manager.IDataManager 4 | import developersancho.mvvm.base.BaseViewModel 5 | import developersancho.mvvm.base.IBasePresenter 6 | 7 | class VViewModel(dataManager: IDataManager) : BaseViewModel(dataManager) -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/viewbindingtest/ViewBindingTestActivity.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.viewbindingtest 2 | 3 | import androidx.navigation.findNavController 4 | import developersancho.mvvm.R 5 | import developersancho.mvvm.base.BaseActivity 6 | import developersancho.mvvm.base.viewBinding 7 | import developersancho.mvvm.databinding.ActivityViewBindingTestBinding 8 | 9 | class ViewBindingTestActivity : BaseActivity() { 10 | 11 | 12 | private val binding by viewBinding { ActivityViewBindingTestBinding.bind(it) } 13 | 14 | override val layoutId: Int? 15 | get() = R.layout.activity_view_binding_test 16 | 17 | override fun initPresenter() { 18 | 19 | } 20 | 21 | override fun initUI() { 22 | binding.textViewBindingDsc.text = "ViewBindingTestActivity" 23 | } 24 | 25 | override fun initListener() { 26 | 27 | } 28 | 29 | override fun onSupportNavigateUp(): Boolean = 30 | findNavController(R.id.view_nav_host_fragment).navigateUp() 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/developersancho/mvvm/ui/viewbindingtest/ViewBindingTestFragment.kt: -------------------------------------------------------------------------------- 1 | package developersancho.mvvm.ui.viewbindingtest 2 | 3 | import android.view.View 4 | import developersancho.mvvm.R 5 | import developersancho.mvvm.base.BaseFragment 6 | import developersancho.mvvm.base.viewBinding 7 | import developersancho.mvvm.databinding.FragmentViewBindingTestBinding 8 | import org.koin.androidx.viewmodel.ext.android.sharedViewModel 9 | 10 | 11 | class ViewBindingTestFragment : BaseFragment() { 12 | 13 | private val viewModel by sharedViewModel() 14 | 15 | private val binding by viewBinding { FragmentViewBindingTestBinding.bind(it) } 16 | 17 | override val layoutId: Int? 18 | get() = R.layout.fragment_view_binding_test 19 | 20 | override fun initPresenter() { 21 | viewModel.setPresenter(this) 22 | } 23 | 24 | override fun initUI(view: View) { 25 | binding.textFragViewBinding.text = "ViewBindingFragment" 26 | } 27 | 28 | override fun initListener() { 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /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_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/ripple_light_with_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_data_binding_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 22 | 23 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 |