During Google I/O 2017, Android Team announced guidelines for architecture of Android app. This is just sample app explaining the new Architecture Guidelines written in Kotlin, YAY!
It's an extremely simple app which uses NewsAPI to show the latest news from Google News. It uses Retrofit 2 to fetch the news from the API and save them into database using Room. The main aim of this sample app is show how to use the new Architecture Guidelines with Kotlin.
- Go to NewsAPI and generate an API key (It's only 2 steps!)
- Create new file ->
credentials.properties
- Add the API key as shown below:
NEWS_API_KEY = "YOUR_API_KEY"
- Run the app
- Enjoyyyyy 🎉
The app uses ViewModel
to abstract the data from UI and Repository
as single source of truth for data. Repository
fetch the data from database if it doesn't exist then it fetches from the webservice.
Trying to learn the new Architecture Components. I have wrote a series of articles to understand Android Architecture Components. Feel free to check it out to learn more.
- Android Architecture Components - A Deep Dive - Caster.io 📺
- Android Architecture Components Podcast on Fragmented 🎤
Write article explaining the complete flow of application- Create fork of repo showing integration with Dagger 2
- Write test cases; (DONE for Room - DAO and Retrofit - WebService)
The architecture components are highly testable. Following table shows how to test various parts of the app (cheatsheet for testing architecture component)
Component | Test | Mock |
---|---|---|
UI | Espresso | ViewModel |
ViewModel | JUnit | Repository |
Repository | JUnit | DAO and WebService |
DAO | Instrumented | - |
WebService | Instrumented | MockWebServer |
- Android Studio 3.0
- Android Device with USB Debugging Enabled
- Android Studio - The Official IDE for Android
- Kotlin - The Official Language for Android
- Gradle - Build tool for Android Studio
Please read CONTRIBUTING.md for contributions.
Proudly 💪 made in Kotlin
The MIT License (MIT)
Copyright (c) 2017 Akshay Chordiya
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.