|
1 |
| -## Kotlin Sample App (work-in-progress 👷🔧️👷♀️⛏) |
| 1 | +## Kotlin Sample App |
2 | 2 | [](https://circleci.com/gh/VMadalin/kotlin-sample-app/tree/master)
|
3 | 3 | [](https://codecov.io/gh/VMadalin/kotlin-sample-app)
|
4 | 4 | [](https://www.codacy.com/manual/VMadalin/kotlin-sample-app?utm_source=github.com&utm_medium=referral&utm_content=VMadalin/kotlin-sample-app&utm_campaign=Badge_Grade)
|
@@ -107,20 +107,58 @@ Moreover, has been implemented support for [dark theme](https://developer.androi
|
107 | 107 |
|
108 | 108 | The architecture of the application is based, apply and strictly complies with each of the following 5 points:
|
109 | 109 |
|
| 110 | +<img src="screenshots/architecture/project_structure.png" width="300" align="right" hspace="20"> |
| 111 | + |
110 | 112 | - A single-activity architecture, using the [Navigation component](https://developer.android.com/guide/navigation/navigation-getting-started) to manage fragment operations.
|
111 | 113 | - [Android architecture components](https://developer.android.com/topic/libraries/architecture/), part of Android Jetpack for give to project a robust design, testable and maintainable.
|
112 |
| -- Pattern [Model-View-ViewModel](](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel)) (MVVM) facilitating a [separation](https://en.wikipedia.org/wiki/Separation_of_concerns) of development of the graphical user interface. |
| 114 | +- Pattern [Model-View-ViewModel](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel) (MVVM) facilitating a [separation](https://en.wikipedia.org/wiki/Separation_of_concerns) of development of the graphical user interface. |
113 | 115 | - [S.O.L.I.D](https://en.wikipedia.org/wiki/SOLID) design principles intended to make software designs more understandable, flexible and maintainable.
|
114 | 116 | - [Modular app architecture](https://proandroiddev.com/build-a-modular-android-app-architecture-25342d99de82) allows to be developed features in isolation, independently from other features.
|
115 | 117 |
|
116 | 118 | ### Modules
|
117 | 119 |
|
118 |
| -Modules are collection of source files and build settings that allow you to divide a project into discrete units of functionality. In this case apart from dividing by functionality/responsibility, existing dependence between them: |
| 120 | +Modules are collection of source files and build settings that allow you to divide a project into discrete units of functionality. In this case apart from dividing by functionality/responsibility, existing the following dependence between them: |
119 | 121 |
|
120 | 122 | <p align="center">
|
121 | 123 | <img src="screenshots/architecture/modules_diagram.png">
|
122 | 124 | </p>
|
123 | 125 |
|
| 126 | +The above graph shows the app modularisation: |
| 127 | +- `:app` depends on `:core` and indirectly depends on `:features` by dynamic-features. |
| 128 | +- `:features` modules depends on `:commons`, `:core`, `:libraries` and `:app`. |
| 129 | +- `:core` and `:commons` only depends for possible utils on `:libraries`. |
| 130 | +- `:libraries` don’t have any dependency. |
| 131 | + |
| 132 | +#### App module |
| 133 | + |
| 134 | +The `:app` module is an [com.android.application](https://developer.android.com/studio/build/), which is needed to create the app bundle. It is also responsible for initiating the [dependency graph](https://github.com/google/dagger), [play core](https://developer.android.com/reference/com/google/android/play/core/release-notes) and another project global libraries, differentiating especially between different app environments. |
| 135 | + |
| 136 | +#### Core module |
| 137 | + |
| 138 | +The `:core` module is an [com.android.library](https://developer.android.com/studio/projects/android-library) for serving network requests or accessing to the database. Providing the data source for the many features that require it. |
| 139 | + |
| 140 | +#### Features modules |
| 141 | + |
| 142 | +The `:features` module are an [com.android.dynamic-feature](https://developer.android.com/studio/projects/dynamic-delivery) is essentially a gradle module which can be downloaded independently from the base application module. It can hold code and resources and include dependencies, just like any other gradle module. |
| 143 | + |
| 144 | +#### Commons modules |
| 145 | + |
| 146 | +The `:commons` modules are an [com.android.library](https://developer.android.com/studio/projects/android-library) only contains code and resources which are shared between feature modules. Reusing this way resources, layouts, views, and components in the different features modules, without the need to duplicate code. |
| 147 | + |
| 148 | +#### Libraries modules |
| 149 | + |
| 150 | +The `:libraries` modules are an [com.android.library](https://developer.android.com/studio/projects/android-library), basically contains different utilities that can be used by the different modules. |
| 151 | + |
| 152 | +### Architecture components |
| 153 | + |
| 154 | +Ideally, ViewModels shouldn’t know anything about Android. This improves testability, leak safety and modularity. ViewModels have different scopes than activities or fragments. While a ViewModel is alive and running, an activity can be in any of its lifecycle states. Activities and fragments can be destroyed and created again while the ViewModel is unaware. |
| 155 | + |
| 156 | +Passing a reference of the View (activity or fragment) to the ViewModel is a serious risk. Lets assume the ViewModel requests data from the network and the data comes back some time later. At that moment, the View reference might be destroyed or might be an old activity that is no longer visible, generating a memory leak and, possibly, a crash. |
| 157 | + |
| 158 | +<img src="screenshots/architecture/communication_diagram.png"> |
| 159 | + |
| 160 | +The communication between the different layers follow the above diagram using the reactive paradigm, observing changes on components without need of callbacks avoiding leaks and edge cases related with them. |
| 161 | + |
124 | 162 | ### Build variants
|
125 | 163 |
|
126 | 164 | The application has different product flavours: `Dev`, `QA`, `Prod`. Each variant has a specific target environment and to make easier to distinguish them the app uses a specific icon colour for `debug` and `release` build variant with descriptive app name. In this case and given that it's a sample, all variants have the same Marvel API endpoint. But the idea is to have different environments target for Development and QA respectively, what doesn't affect the production environment. This is applicable to any tool, platform, service what is being used. For more information about build variant, check this [link](https://developer.android.com/studio/build/build-variants).
|
|
0 commit comments