Moly is a sample Android project using The Movie DB API based on MVVM architecture. It showcases the latest Android tech stacks with well-designed architecture and best practices.
- 100% Kotlin
- MVVM architecture
- Android Architecture Components and Jetpack.
- Kotlin Coroutines + Flow
- Single activity pattern
- Version Catalog TOML
- Retrofit + OkHttp - RESTful API and networking client.
- Hilt - Dependency injection.
- Android Architecture Components - A collections of libraries that help you design rebust, testable and maintainable apps.
- ViewModel - UI related data holder, lifecycle aware.
- LiveData - Observable data holder that notify views when underlying data changes.
- Lifecycle - Handling lifecycles with lifecycle-aware component
- ViewBinding - Instance of a binding class contains direct references to all views that have an ID in the corresponding layout.
- Navigation component - Fragment routing handler.
- Material Components for Android - Modular and customizable Material Design UI components for Android.
- Coroutine Concurrency design pattern for asynchronous programming.
- Flow Stream of value that returns from suspend function.
- Coil - Image loading.
- Timber - Extensible API for logging.
- Logger - Simple, pretty and powerful logger for android.
- Gson - Converting JSON to Kotlin data class.
- Glide - Loading and caching images.
- Glide Transformations - Providing image transformations for Glide.
- YouTube Android Player - Playing YouTube video in app.
- ExpandableTextView - TextView library that performs multiline ellipsize.
- Klock - Date & Time library for Multiplatform Kotlin 1.3.
- Desugar - Simplified for use on older runtimes.
- TOML - Version catalog is a list of dependencies, represented as dependency coordinates, that a user can pick from when declaring dependencies in a build script.
We follow Google recommended Guide to app architecture to structure our architecture based on MVVM, reactive UI using LiveData / Hilt observables and view binding.
- View: Activity/Fragment with UI-specific logics only.
- ViewModel: It keeps the logic away from View layer, provides data streams for UI and handle user interactions.
- Model: Repository pattern, data layers that provide interface to manipulate data from both the local and remote data sources. The local data sources will serve as single source of truth.
dev.byto.moly # Root Package
├── data # For data modeling layer
│ ├── mapper # Contains mapping functions to map DTOs(Data Transfer Objects)
│ ├── remote # contains *Retrofit* components to fetch data from the network source
| │ ├── api # API Service
| │ └── dto # DTOs(Data Transfer Objects)
│ └── repository # contains **implementations** of repository interfaces that are defined in the domain layera
|
├── di # Dependency injection modules
|
├── domain # Domain layer is the central layer of the project
│ ├── model # contains data classes that hold the data retrieved from the data layer to be used later
│ │ on in the presentation layer to expose it to UI
│ ├── repository # contains repository **interfaces** to abstract the domain layer from the data layer
│ └── usecase # contains use cases(interactors) that handle the business logic, which are reused by multiple ViewModels
│
├── ui # contains Activities & Fragments with their corresponding ViewModel classes
│ ├── adapter # contains RecyclerView adapter classes
│ ├── base # Base ViewModel
│ └── screen # Location screen Fragment and ViewModel
| | └── detail # Detail screen Fragment and ViewModel
| | | └── dialog # Dialog open Youtube
| | ├── home # Home screen Fragment and ViewModel
| | ├── list # List screen Fragment and ViewModel
| | └── MainActivity# Single activity
| └── UiState # UI State response
|
├── utils # Utility Classes / Kotlin extensions
└── MainApp # Application
The project separated into three main layers:
- Data
- UI
- Domain
You will need to provide developer key to fetch the data from TMDB API.
- Generate a new key (v3 auth) from here. Copy the key and go back to Android project.
- Define a constant
API_KEY
with the double quotes, it looks like
private const val API_KEY = "\"5423as******************655\""
- Add the key to build config in
./app/src/main/java/dev/byto/moly/di/NetworkModule.kt
: - Perform gradle sync.
Copyright 2023 Toby Zulkarnain
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.