This repository contains a sample app that implements MVVM architecture using Kotlin, Hilt, Retrofit, Coroutines, Flow, Stateflow, Room, etc.
- MVVM Architecture
- Kotlin
- Hilt
- Retrofit
- Coroutines
- Flows
- Stateflow
- View binding
- Unit Test
- Offline Support
- It is a fully-featured, compile-time dependency injection framework.
- Configuration: Requires a lot of boilerplate code and manual configuration.
- Learning Curve: Steeper learning curve due to its comprehensive feature set.
- Flexibility: Offers a high level of flexibility and customization.
- Use Cases: Suitable for complex.
- There are annotations defined in Dagger 2 to specify which operation to take. We will now briefly touch on these.
- Dagger Project Link
The classes to be used are specified here. Dagger finds and retrieves the desired injection by looking at the @Provide methods.
It is used to tell Dagger what all dependencies are that need to be passed. We can use @Inject in 3 different places. Constructors Objects Methods
Classes in which @Provide annotations are used are told to Dagger with the @Module annotation.
It’s something like a bridge between @Module and @Inject. It is used to create interfaces that connect everything. Here we define from which modules we get our dependencies.
It determines the life processes.
- Type:Hilt is a library built on top of Dagger 2, designed to simplify dependency injection in Android applications.
- Configuration: Offers simplified annotations and reduced boilerplate code compared to Dagger 2.
- Learning Curve: Easier to learn and use, especially for developers new to Dagger.
- Flexibility: Sacrifices some flexibility for ease of use and reduced setup.
- Use Cases: Aimed at Android app developers for more straightforward dependency injection.
- Annotations such as module, inject and provides are also used in Hilt. We will now briefly touch on these.
Generates the Hilt code. It should be added to the Application class.
Thanks to this annotation, many components such as Activity, Fragment, View become ready to be @Inject.
Used for classes that derive from ViewModel. For Retrofit client or database operations, when we create and @Inject objects as modules, Hilt finds those objects from within the modules and presents them to us.
This indicates that Hilt-created DI containers must be present in module bindings. We specify the scope we will use.
- data: It contains all the data accessing and manipulating components.
- di: Dependency providing classes using Dagger2.
- ui: View classes along with their corresponding ViewModel.
- utils: Utility classes.
The main advantage of using MVVM, there is no two-way dependency between ViewModel and Model, unlike MVP. Here the view can observe the data changes in the ViewModel as we are using LiveData which is lifecycle aware. The viewmodel-to-view communication is achieved through observer pattern (basically observing the state changes of the data in the viewmodel).
- Fetching News
- Top Headlines News
- News Based on Source
- News Based on Selection
- News Based on Language Selection
- Instant Search using Flows Operator
- Debounce
- Filter
- DistinctUntilChanged
- FlatMapLatest
- Map
- Unit Test
- Mockito
- JUnit
- Turbine
Copyright (C) 2024 Pavan Mankar
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