Skip to content

This is a sample demo android application that I have created to apply MVVM and new android architecture components

Notifications You must be signed in to change notification settings

ercanduman/KotlinMVVMDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

KotlinMVVMDemo

This is a sample demo android application that I have created to apply MVVM and new android architecture components.

I have followed below diagram as reference which shows basic form of MVVM architecture.

mvvm-architecture

You can find all MVVM architecture codes for Activity, Fragment, ViewModel, ViewModelFactory, LiveData, Repository, Dao, Entity, Room database, Retrofit and Glide library, etc.

And also the following features (code samples) will be presented:

  • Applying Retrofit library to get data from WebService
  • Creating MainActivity as a host activity and using fragments for all other views
  • Using GSON library to convert JSON data into Kotlin data classes
  • Creating Api interface for retrofit requests
  • Applying Data Binding to layout xml files
  • Repository objects to make network calls and/or retrieving data from local database
  • Room Database, Entity and Dao objects creation
  • Writing SQL queries to retrieve data from Room database based on different conditions
  • Creating AppDatabase and applying Singleton design pattern
  • Using Coroutines and suspend functions for long running background operations
  • Creating Coroutines extension functions for different operations (IO, Main, etc.)
  • Creating ViewModelFactory objects to provide ViewModels
  • Using Groupie library to list items on RecyclerView
  • Using Glide library to download photo from url and display images in Adapter
  • Creating interface named ProcessListener to listen process steps
  • Handling Api and Network Exceptions (NoNetworkException in Exceptions.kt) in a separate object (SafeApiRequest.kt)
  • Using SharedPreferences to store simple data locally (PreferenceProvider.kt)
  • Creating ViewAdapter to adapt every single item of photo to RecyclerView
  • Creating Kotlin Extension functions (ViewUtils.kt) i.e.: Context.toast(message: String), Context.logd(debugMessage: String), etc.
  • Showing network responses on Snackbar (with extension function)
  • Applying Android Navigation Architecture and store all fragments in navigation component.
  • Passing bundle data between Navigation Architecture fragments
  • Adding Item click listener to Navigation Architecture fragments
  • Passing safeArgs data between Navigation Architecture fragments
  • Applying Kotlin Dependency Injection design pattern with KodeIn library

Application, Api and APK file

MVVM demo application uses data from JsonPlaceHolder Api. Application contains three different fragments called Album Fragment, Photo Fragment and Gallery Fragments.

Data for all albums are retrieved from JsonPlaceHolder api with this url: https://jsonplaceholder.typicode.com/albums and all albums are listed in Albums Fragment as shown in below image.

Every album contains multiple photos so if any album is clicked then Photos Fragment started and all photos that available in current album retrieved from this url: https://jsonplaceholder.typicode.com/photos?albumId=1 Photos are inserted and saved to Room database and then listed as shown below.

As displayed in above image Album id: 3 has 50 images.

MVVM demo application does not make any network call for Gallery Fragment. Because in Gallery fragment already downloaded photos will be displayed. As shown in below diagram's Snackbar there are already 700 images downloaded.

If you would like to try the application, you can download APK file from this link: Mapp_debug_apk.zip

Helpful links:

Happy coding! 👍 🥇

About

This is a sample demo android application that I have created to apply MVVM and new android architecture components

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages