Skip to content

Marvel Cinematic Universe is an Android Application for practicing various Jetpack libraries.

Notifications You must be signed in to change notification settings

kym1924/marvel-cinematic-universe

Repository files navigation

Marvel Cinematic Universe

Marvel Cinematic Universe is an app for practicing various Jetpack libraries.

screenshots

Libraries

  • Kotlin
  • Android
    • AppStartup : A straightforward, performant way to initialize components at application startup.
    • DataBinding : Bind UI components in your layouts to data sources in your app using a declarative format.
    • Datastore : A data storage using Kotlin coroutines and Flow to store small and simple datasets.
    • Hilt : Jetpack's recommended DI solution for Android.
    • JankStats : Track and analyze jank performance problems in your app's UI.
    • Lifecycle : Defines an object that has an Android Lifecycle.
    • Navigation-component : Framework for navigating between destinations within an app.
    • Room : Database persistence layer designed for usability, safety, and testability.
    • Splash-screens : A new app launch animation for all apps when running on a device with Android 12 or higher.
    • ViewModel : A business logic or screen level state holder.
    • WorkManager : A library for managing deferrable and guaranteed background work.
  • Glide : An image loading and caching library for Android.
  • Gson : A Java serialization/deserialization library to convert Java Objects into JSON and back.
  • Material-Components : Modular and customizable Material Design UI components for Android.
  • Timber : A logger with a small, extensible API.

Architecture

architecture

  • This application consists of two layers.
  • Unidirectional Data Flow(UDF)
    • In UDF, data flows in only one direction.
    • The events that modify the data in the opposite direction.

UI Layer

UI Layer

  • UI Layer consists of two things.
    • View(UI elements) that renders data to the screen.
    • ViewModel that holds data, exposes data, handles logic.
  • ViewModel exposes the data, and the View observes the data.

Data Layer

Data Layer

  • Data layer contains Repositories where DAO is injected to access Database.
  • Repositories get immutable data stream from Database and expose it to the ViewModel.

Room Database

Room Database

  • To use the Room database efficiently, refer to the 7-pro-tips.

  • Pre-populate your database via RoomDatabase#Callback.

    • You can detect the moment the database is created with RoomDatabase.Callback().
    • Using WorkManager, add default data when a database is created.
    • You can build an offline-first app by adding default data.
    • That is, it can perform some or all of its business logic without access to the internet.
    Room.databaseBuilder(
        context,
        MarvelDatabase::class.java,
        "Marvel.db"
    ).addCallback(
        object : RoomDatabase.Callback() {
            override fun onCreate(db: SupportSQLiteDatabase) {
                super.onCreate(db)
                val request = OneTimeWorkRequestBuilder<MarvelDatabaseWorker>().build()
                WorkManager.getInstance(context).enqueue(request)
            }
        }
    ).build()
  • Read only what you need.

    • For example, Movie data class stored in the database has 7 fields.
    @Entity
    data class Movie(
        @PrimaryKey val id: Int,
        val title: String,
        val phase: Int,
        val content: String,
        val release: String,
        @ColumnInfo(name = "running_time") val runningTime: Int,
        val image: String
    )
    
    // In DAO
    @Query("SELECT * FROM Movie")
    fun getMovies(): Flow<List<Movie>>
    • Instead of getting all field values stored in the database, read only what you need.
    data class MovieBasicInfo(
        val id: Int,
        val title: String,
        val image: String
    )
    
    // In DAO
    @Query("SELECT id, title, image FROM Movie")
    fun getMovies(): Flow<List<MovieBasicInfo>>
    • This will also improve the speed of queries by reducing the IO cost.

Contents