A sample photo browsing app in Kotlin, Android using Picsum image API.

Overview

Picsum Photo App

Functionality

The app's functionality includes:

  1. Fetch a list of images from picsum photos api (https://picsum.photos/) and show them in RecyclerView using StaggeredGrid Layout Manager.
  2. User can view the list of images using smooth infinite scroll.
  3. When an image is selected from RecyclerView it will load the full-screen image with pinch zoom in/out feature.
  4. User can download the image from full-screen view.
  5. User can share the image from full-screen view.
  6. The image list is cached into local DB, so the list of images are available offline.
  7. The app supports SwipeRefreshLayout to refresh RecyclerView content from remote source.

Architecture

The app uses clean architecture with MVVM(Model View View Model) design pattern. MVVM provides better separation of concern, easier testing, Live data & lifecycle awareness, etc.

UI

The UI consists of two screen

  1. MainActivity.kt - Initial screen. Shows a list of images.
  2. FullScreenActivity.kt - Shows full-screen view of the image with additional options.

Model

Model is generated from JSON data into a Kotlin data class. In addition, entity class has been added for room database.

ViewModel

MainViewModel.kt

Used for fetching picsum images & update livedata. Also send out the status of the network call like Loading, Success, Error using sealed class.

FullScreenViewModel.kt

Used for downloading the image into a bitmap & save it into internal storage.

Dependency Injection

The app uses Dagger-hilt as a dependency injection library.

The ApplicationModule.kt class provides Singleton reference for Retrofit, OkHttpClient, Repository etc.

Network

The network layer is composed of Repository, ApiService. PicsumApi - Is an interface containing the suspend functions for retrofit API call.

ImageListRepository - Holds the definition of the remote/local repository call.

Building

You can open the project in Android studio and press run. Android Studio version used to build the project: Arctic fox 2020.3.1

Gradle plugin used in the project will require Java 11.0 to run.

you can set the gradle jdk in Preferences->Build Tools->Gradle->Gradle JDK

Libraries used

  1. Android appcompat, core, constraint layout, Material Support.
  2. Android View Binding
  3. Hilt for dependency injection
  4. Retrofit for REST API communication
  5. Coroutine for Network call
  6. Lifecycle, ViewModel
  7. LiveData
  8. Room for local database.
  9. Glide for image loading.
  10. Custom fileprovider for writing & reading files into internal storage.
  11. Swipe Refresh Layout for pull-to-refresh RecyclerView.
  12. Mockito & Junit for Unit testing.
  13. Robolectric for Instrumentation testing
  14. Truth for Assertion in testing.
  15. Photo View for zoom in/out image.

Testing

Unit and integration testing has been added for MainViewModel , FullScreenViewModel, ImageListRepository & ImageListItemSerializableTest.

MainViewModelTest.kt

Test the viewmodel of the app using CoroutineRule & LiveData Observer.

The test cases comprise of testing different states like Loading, Success, Error with fake data for testing image list response, cache response.

FullScreenViewModelTest.kt

Test Image donwload returns file uri & URL to bitmap conversion.

ListingRepository.kt

Test the Repository of the app using Robolectric.

The test comprises of testing the functionality of Image Room Database like Insertion, Remove, Get saved response etc.

Mock Webserver is used to test the Network api response in case of successful data, empty, failed case.

Screenshots

Infinite Scroll, Pinch Zoom Image Download Image share
You might also like...
 Booking - Android Architecture Sample
Booking - Android Architecture Sample

Booking - Android Architecture Sample A simple app that loads information from REST API to show one approach to using some of the best practices in An

A sample repo to play with modern Android technologies

MarvelCompose Marvel + Compose. Table of Contents Introduction Features Feedback Introduction This is a sample repo to play with modern Android techno

Sample projects for Android 13 (Developer Preview 1)
Sample projects for Android 13 (Developer Preview 1)

android-13-samples Sample projects for Android 13 (Developer Preview 1). Table of Content Themed App Icon (Github) (Tutorial) Quick Settings Placement

Sample Android Clean MVVM architecture
Sample Android Clean MVVM architecture

Sample Android Clean MVVM architecture ( Retrofit + Okhttp + Moshi + Coil + Room + Navigation Component + Coroutines + Flow + DataStore + ViewModel + Hilt + Compose )

Viper - Sample Viper (MVVMR) architecture pattern
Viper - Sample Viper (MVVMR) architecture pattern

Viper V I P E R = View + Interactor + Presenter + Entity + Router My versions Wi

Learn How to use Google Map API for Android from Basic to Advance with complete examples.

Complete-Google-Map-API-Tutorial Learn How to use Google Map API for Android from Basic to Advance. Satellite View 3D Building Map and StreetView Lear

Multiple samples demonstrating Search API usage in Android.

Search Samples Repository This repository contains a set of individual Android Studio projects to help you get started writing apps that take advantag

This example was built for lecturing proposes, it shows how to consume data from an API.

Android Kotlin NewsMobEDJDCM2122 Example - EDJD 2021/2022 This example was wirten during the Mobile Computing lectures in the course 'Lincentura em En

REST API with Retrofit, SQLite with Room, Hilt, MVVM, Jetpack Compose
REST API with Retrofit, SQLite with Room, Hilt, MVVM, Jetpack Compose

Simple REST API Learn how to make an Android App that will call a REST API using Retrofit to retrieve some data that will be stored in SQLite using Ro

Owner
Rafsan Ahmad
Software developer...enthusiastic about latest trend and opportunities in tech world.
Rafsan Ahmad
📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Android Components Architecture in a Modular Word Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 app

Madalin Valceleanu 2.3k Dec 30, 2022
MVVM(Model View ViewModel) sample in Kotlin using the components ViewModel, LiveData and Retrofit library

kotlin-mvvm Languages: English, Spanish MVVM(Model View ViewModel) sample in Kotlin using the components ViewModel, LiveData, the libraries Retrofit,

Eduardo José Medina Alfaro 466 Jan 5, 2023
FTUE sample using Jetpack Navigation's Navigation-Compose, ViewModel, SavedStateHandle, Hilt

Jetpack Navigation's Navigation-Compose + Jetpack Compose + NavGraphs + SavedStateHandle + Dagger-Hilt + EventEmitter (toasts / navigation commands) T

Gabor Varadi 15 Dec 8, 2022
A sample Album list app that shows how to use ViewModels and Room together with RxJava & Dagger2, in Kotlin by Clean Architecture.

Kotlin-MVVM-Hilt A sample Album list app that shows how to use ViewModels and Room together with RxJava & Dagger2, in Kotlin by Clean Architecture. Im

hpAndro 1 May 12, 2022
MVI Architecture Android Beginners: Sample App

MVI Architecture Android Beginners: Sample App This repository contains a sample app that implements MVI architecture using Kotlin, ViewModel, LiveDat

null 16 Dec 7, 2022
Quarkus Sample Application with extensions cache, kotlin, rest client, resteasy and smallrye

quarkus-sample Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its w

Erdem Aydın 1 Sep 25, 2022
A simple list-detail application using the Github API

GitHub Users Search Android application to search users via GitHub API Project demonstrates how to use Kotlin, Android Architecture Components, Dagger

Ndu Sunday 2 May 26, 2022
Saga of Star wars - An Android sample repo showcasing Clean Arch with MVVM and Epoxy models

Star Wars Universe This is a showcase android application written in Kotlin and follows Clean Code architecture to showcase Characters from the StarWa

Adit Lal 5 Dec 13, 2022
This is an example implementation of android accessibility services with 5 Sample Actions

Android Accessibility Services Example This is an example implementation of android accessibility services with 5 Sample Actions such as: Simulate Pow

Muhammad Fahriansyah 7 Jul 1, 2022
Android Modern Architecture Sample

AndroidModernArchitectureSample TODO: write readme Download (playstore release - under review) https://play.google.com/store/apps/details?id=io.github

Ji Sungbin 22 Sep 10, 2022