Android app written in Kotlin that displays news articles - powered by News API
In order to make it work, make sure to get your free API key from https://newsapi.org and add it to a new file config/secrets.properties
like this:
API_KEY=%your-api-key%
Do a gradle sync and everything should be ready.
It's designed based in the classic 3-layer clean architecture.
Every layer is represented as module, thus achieving separation of concerns. Also, it is important to note that domain layer is defined as a pure-kotlin non-android module, in order to avoid dependencies with the android framework.
This is where all of our domain entities and business logic is.
This layer does not need to know anything about the other 2, being totally independent in this sense. Other layers are responsible for mapping models to be naturally understood by the domain
layer.
Use cases contain business logic that can be used by the presentation
layer, and make use of repositories that are implemented in the data
layer.
I'm using coroutines flow to be able to execute asynchronous code.
This is where our repository implementations and data sources are.
Repositories are responsible for deciding whether to retrieve data from local or remote datasources. I'm using Room as database for the local datasource and Retrofit for the remote datasource.
In this layer I'm using the MVVM pattern, using Jetpack ViewModels and exposing a LiveData object that the view (activities or fragments) is observing and can react updating the UI accordingly.
I'm using koin for dependency injection and, even if the learning curve is super smooth making it really easy to setup, you better watch out for any potential runtime crash while trying to resolve dependencies.
It's worth mentioning that I'm using the Either
class from Λrrow library, since it allows a very natural way of handling errors.