News App : Clean Code Architecture + Paging + Room DB in Android Studio

Mohit Damke
3 min readJul 4, 2024

--

Here is the implementation of the News app with news api in kotlin and jetpack.

Summery : Here is the full app which we have to build with the help of news api in clean code architecture which include dagger hilt for dependency injection, pagination library for paging, roomdb for storing some data in it, retrofit for api calling.

Project Implementation In Simple Steps

  • First we need to add some dependency
plugins {
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
id("kotlin-parcelize")
}
dependencies {

//Splash Api
implementation "androidx.core:core-splashscreen:1.0.1"
//Compose Navigation
def nav_version = "2.6.0"
implementation "androidx.navigation:navigation-compose:$nav_version"
//Dagger Hilt
implementation "com.google.dagger:hilt-android:2.45"
kapt "com.google.dagger:hilt-compiler:2.45"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
//Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
//Coil
implementation("io.coil-kt:coil-compose:2.4.0")
//Datastore
implementation "androidx.datastore:datastore-preferences:1.0.0"
//Compose Foundation
implementation "androidx.compose.foundation:foundation:1.4.3"
//Accompanist
implementation "com.google.accompanist:accompanist-systemuicontroller:0.31.4-beta"
//Paging 3
def paging_version = "3.1.1"
implementation "androidx.paging:paging-runtime:$paging_version"
implementation "androidx.paging:paging-compose:3.2.0-rc01"
//Room
def room_version = "2.5.2"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:2.5.2"
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
id("com.google.dagger.hilt.android") version "2.44" apply false
}



buildscript {

dependencies {
classpath("com.google.dagger:hilt-android-gradle-plugin:2.51.1")
}

}
  • Here we have implemented plugin, dependency, classpath
  • Later we will do some changes in manifest file.

Add Come Custom Colors in it

package com.example.newsapp.ui.theme

import androidx.compose.ui.graphics.Color

val Black = Color(0xFF1C1E21) //Dark Background
val Blue = Color(0xFF1877F2) //Primary

val DarkRed = Color(0xFFC30052) //Dark Error
val LightRed = Color(0xFFFF84B7)

val LightBlack = Color(0xFF3A3B3C) //Dark Surface


val BlueGray = Color(0xFFA0A3BD)
val WhiteGray = Color(0xFFB0B3B8)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="display_small">#000000</color>
<color name="text_medium">#FF4E4B66</color>
<color name="text_title">#000000</color>
<color name="body">#4E4B66</color>
<color name="input_background">#fff</color>
<color name="placeholder">#9B9FC5</color>
<color name="shimmer">#C3C3C3</color>
</resources>

Lets Set Up Dagger Hilt First

  • Make sure to add annotations.
  • For MainActivity
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
  • For ViewModel
@HiltViewModel
class DetailViewModel @Inject constructor(
private val newsUseCases: NewsUseCases
) : ViewModel() {
  • Create one class file as NewApplication and extend it as Application Class
@HiltAndroidApp
class NewApplication : Application() {
}
  • Add name to Manifest File
<application
android:allowBackup="true"
android:name=".NewApplication"
  • Add Internet Permission
<uses-permission android:name="android.permission.INTERNET"/>
  • Add Query for share and visit link in the app
</intent-filter>
</activity>
</application>

<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.SEND"/>
</intent>
</queries>

Here we will make app in parts so with lets start with splash screen and onboarding screen

Part 1 : Implementing Splash & OnBoarding Screen Integration in App

Part 2 : Implementing Preferences Datastore and Dependency Injection

Part 3 : Implementing NavGraph in app

Part 4 : Implementing News Api with Retrofit in App

Part 5 : Implementing Search Screen in app

Part 6: Implementing News Detail Screen in app

Part 7: Implementing RoomDB for the saving Bookmark in local storage

Part 8: Final part of making an App

Here we are able to implement full app with Clean Code Architecture, Dagger Hilt, Retrofit, RoomDB, Paging.

You can add 50 clap by just pressing on clap icon

Visit my GitHub Repository : https://github.com/mohitdamke/NewsApp

Make sure to follow me on
Link-tree :
https://linktr.ee/MohitDamke01
LinkedIn :
https://www.linkedin.com/in/mohitdamke01:

--

--

Mohit Damke

Junior Android Developer | Kotlin | Jetpack | Firebase | Android Studio | MVVM & Clean Code Architecture