Make Your Own E-Book Reader App

Mahesh Jadkar
Globant
Published in
5 min readSep 20, 2022

Co-author: Sumedha Kulkarni, working as an Android application developer

What we will be building

We’ll build an e-book reader application in Android using Kotlin MVVM architecture. We will impart some unique features to it (listed below).

Key features which will make this app different from others:

  • Get Summary: As per the user's request, provide a short or descriptive summary. The summary is fetched via a Python script from the backend. Read more about the Python Script here
  • Navigate to the page where you left
  • Zoom Functionality

Here is the high-level architecture diagram to get a clear idea about the application we are building.

A frontend is written in Android, an interactive application is developed in which the user can read any book in pdf format.

  • Whenever the user wants to get a summary of a book till the last read page, the application extracts the text from the pdf and with extracted text it sends the request getSummary() to the server. Read more
  • Backend server is written in Kotlin, using the Ktor framework.
  • At the backend, Python script helps to get a meaningful summary of the extracted text from the frontend. Backend responds with this summary.
  • And this summary is displayed to the user through Kotlin UI.

For this article we will be focusing on the frontend of the Ebook Reader, so let’s dive more into the application architecture which we used.

We have used the latest architecture in Android Development i.e. MVVM Clean explained in the below diagram,

Reference: https://www.raywenderlich.com/3595916-clean-architecture-tutorial-for-android-getting-started

From the above diagram we get a basic idea of what MVVM architecture is,

MVVM architecture mainly separates views from business logic, ViewModel contains all the business logic, but in large and more complex applications ViewModel becomes overloaded with all the business logic, so it’s better to use clean architecture.

Reference: https://androidexample365.com/clean-architectureclean-architecture-kotlin-mvvm-use-cases/

Clean architecture has three main layers:

Presentation layer,

Domain Layer,

and Data Layer.

To simplify, the Presentation layer contains all the views i.e Activity/Fragments, and view models.

The domain layer contains all the business logic i.e. UseCases, Entities.

The data layer contains all the repositories, and data sources (remote or local).

Below is how we used clean architecture. We have created three separate modules for each layer.

The simplest and most popular KOIN dependency injection framework is used for dependency injection. In this architecture fragments and activity contain all the UI components which are getting displayed to the user i.e. PDF reader, CTA/buttons to get a summary. Activities/fragments communicate with view models, to get data i.e summary to display on UI. ViewModel contains function calls which are written in the domain layer’s interface. ViewModel communicates with the domain layer to get the required data. Remote API calls are present in the data layer. Local and remote repositories are also present in this layer.

Ability to do HTTP calls

To support communication between client and server, it is necessary to include a library which helps us to make calls to the API. For example, in our application, we need to make a call to get a summary of the book till the last read page. Now to accommodate this we are using a popular and easy-to-use Retrofit library. The Retrofit library provides a powerful framework for interacting and authenticating with API’s.

Below is how we use retrofit for a network call to get a summary

First of all, we need to create an API service interface with the help of annotations i.e. provided in the Retrofit library. We make a call in the repository using this ApiService, And once this call is successful, we store the response in the entity. Then later through ViewModel, we display this summary response on UI.

Ability to display pdf

To read books effectively, we need to display PDFs selected by the user in a user-friendly manner. Also to get a summary we need to extract the text from the pdf to the current page. To achieve the above points there is one library present in Android i.e ‘com.github.barteksc:android-pdf-viewer:2.8.2’. We just need to pass a context and document URI. Then free to use any function in this library as below.

And similarly for extraction of text we used library com.itextpdf:itextg:5.5.10

Coroutines

Coroutines are used to fetch the summary in the background.

Unit testing

Testing is an integral part of the app development process. By running tests against your app consistently, you can verify your app’s correctness, functional behaviour, and usability before you release it publicly.

Credits

Used third-party library for extraction of PDF data used below repository

https://mvnrepository.com/artifact/com.itextpdf/itextpdf/5.5.10
https://github.com/itext/itextpdf/releases

https://github.com/InsertKoinIO/koin
https://developer.android.com/topic/libraries/architecture/datastore?gclid=Cj0KCQjwyMiTBhDKARIsAAJ-9VvqNBw8hyJOxWlqDDlvsWtyvxOumRfW2vaB74hpPiMk3_-AgOTeOFwaAjFuEALw_wcB&gclsrc=aw.ds

https://androidexample365.com/clean-architectureclean-architecture-kotlin-mvvm-use-cases/

Summary

We end up with an interactive android application which lets users read a book in pdf format and gives a summary which is a short explanation about the book and contains key points until the present page number.

The concept is required to keep the user engaged while reading the book and keep the user updated about the points in the book which he has read so far. For. e.g: Automatically takes the user to the page number that they were reading. Also whenever a user requests he will get a summary of the current page.

Special thanks to Mukund Sharma, Shivhar Jalkote and Mitesh Dewda for conceiving and editing this article.

--

--