Every new project that I start is an opportunity to do better – to implement best practices that are up-to-date and consistent with Google's recommendations. This image search example app is an attempt to implement these best practices as of January 2021:
- Google's recommended app architecture*: single activity w/fragments, ViewModel underneath, repository underneath that
- Dependency injection (using Dagger Hilt)
- Jetpack libraries, including: paging, navigation, lifecycle, ViewBinding, among others
- REST API interaction using Retrofit, paired with Moshi for JSON parsing
- 100% Kotlin 😎
* Data persistence is not included in this example app. For an example on how to persist data using Room, check out AppNotifier.
- Search for images using Imgur's API
- View images fullscreen with pinch-to-zoom
The app can be used out-of-the-box with some minimal configuration.
This is required for the Imgur API to work. You can obtain this by registering your application with Imgur here.
- Location: ImageSearchModule.kt line 56
Prerequisites:
- Windows / MacOS / Linux
- JDK 8
- Android SDK
- Internet connection (to download dependencies)
First, ensure that you have added an Imgur Client ID to the app, as described in the Configuration section above. Once all the prerequisites are met, make sure that the ANDROID_HOME environment variable is set to your Android SDK directory, then run ./gradlew assembleDebug at the base directory of the project to start the build. After the build completes, navigate to app/build/outputs/apk/debug where you will end up with an APK file ready to install on your Android device.