Skip to content

Commit 013134e

Browse files
Waheed NazirWaheedNazir
authored andcommitted
1.0.5 Migrated to Kotlin DSL & upgraded dependencies
- Build script migrated to Kotlin DSL - Migrated Kapt to Ksp - Upgraded Android Gradle Plugin - Upgraded Kotlin version. - Upgraded Room implementation - Added Flow to handle Room data
1 parent fdde950 commit 013134e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+464
-527
lines changed

app/build.gradle

Lines changed: 0 additions & 107 deletions
This file was deleted.

app/build.gradle.kts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import java.util.Properties
2+
import java.io.FileInputStream
3+
import java.io.FileNotFoundException
4+
5+
plugins {
6+
id("com.android.application")
7+
id("org.jetbrains.kotlin.android")
8+
id("com.google.dagger.hilt.android")
9+
id("com.google.devtools.ksp")
10+
}
11+
12+
android {
13+
namespace = "com.kotlin.mvvm"
14+
compileSdk = 35
15+
16+
defaultConfig {
17+
applicationId = "com.kotlin.mvvm.architecture"
18+
minSdk = 21
19+
targetSdk = 34
20+
compileSdk = 34
21+
versionCode = 5
22+
versionName = "1.0.5"
23+
multiDexEnabled = true
24+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
25+
vectorDrawables.useSupportLibrary = true
26+
}
27+
28+
// Load properties from the credentials.properties file
29+
val credentialsFile = rootProject.file("credentials.properties")
30+
val properties = Properties()
31+
32+
if (credentialsFile.exists()) {
33+
properties.load(FileInputStream(credentialsFile))
34+
} else {
35+
throw FileNotFoundException("Missing credentials.properties file!")
36+
}
37+
38+
39+
buildTypes {
40+
getByName("debug") {
41+
buildConfigField("String", "NEWS_API_KEY", properties.getProperty("NEWS_API_KEY"))
42+
buildConfigField("String", "BASE_URL", properties.getProperty("BASE_URL"))
43+
isMinifyEnabled = false // Enable ProGuard for release builds if needed
44+
isDebuggable = true
45+
}
46+
getByName("release") {
47+
buildConfigField("String", "NEWS_API_KEY", properties.getProperty("NEWS_API_KEY"))
48+
buildConfigField("String", "BASE_URL", properties.getProperty("BASE_URL"))
49+
isMinifyEnabled = false // Enable ProGuard for release builds if needed
50+
isDebuggable = false
51+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
52+
}
53+
}
54+
55+
compileOptions {
56+
sourceCompatibility = JavaVersion.VERSION_1_8
57+
targetCompatibility = JavaVersion.VERSION_1_8
58+
}
59+
60+
kotlinOptions {
61+
jvmTarget = "1.8"
62+
}
63+
buildFeatures {
64+
viewBinding = true
65+
buildConfig = true
66+
}
67+
}
68+
69+
dependencies {
70+
implementation("androidx.multidex:multidex:2.0.1")
71+
implementation("androidx.appcompat:appcompat:1.7.0")
72+
implementation("androidx.multidex:multidex:2.0.1")
73+
implementation("com.google.android.material:material:1.12.0")
74+
implementation("com.google.code.gson:gson:2.11.0")
75+
implementation("androidx.recyclerview:recyclerview:1.3.2")
76+
77+
//KTX
78+
implementation("androidx.core:core-ktx:1.13.1")
79+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
80+
implementation("androidx.fragment:fragment-ktx:1.8.4")
81+
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.8.6")
82+
implementation("androidx.legacy:legacy-support-v4:1.0.0")
83+
84+
// Dagger, Hilt
85+
val hilt = "2.51.1"
86+
implementation("com.google.dagger:hilt-android:$hilt")
87+
ksp("com.google.dagger:hilt-compiler:$hilt")
88+
89+
// Retrofit
90+
implementation("com.squareup.retrofit2:retrofit:2.9.0")
91+
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
92+
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
93+
94+
// Room
95+
implementation("androidx.room:room-runtime:2.6.1")
96+
ksp("androidx.room:room-compiler:2.6.1")
97+
98+
//Kotlin Extensions and Coroutines support for Room
99+
implementation("androidx.room:room-ktx:2.6.1")
100+
// optional - Test helpers
101+
testImplementation("androidx.room:room-testing:2.6.1")
102+
103+
// Glide
104+
implementation("com.github.bumptech.glide:glide:4.16.0")
105+
106+
//RxJava
107+
implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
108+
implementation("io.reactivex.rxjava2:rxjava:2.2.11")
109+
implementation("com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0")
110+
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.kotlin.mvvm">
55

6-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
76
<uses-permission android:name="android.permission.INTERNET" />
8-
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
7+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
98

109
<application
1110
android:name="com.kotlin.mvvm.app.App"

app/src/main/java/com/kotlin/mvvm/app/App.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import android.app.Application
44
import dagger.hilt.android.HiltAndroidApp
55

66
/**
7-
* Created by Waheed on 04,November,2019
8-
* Migrated to Hilt 20, June, 2021
7+
* Hilt Android App
98
*/
109

1110
@HiltAndroidApp

app/src/main/java/com/kotlin/mvvm/app/AppExecutors.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import java.util.concurrent.Executors
77
import javax.inject.Inject
88
import javax.inject.Singleton
99

10-
/**
11-
* Created by Waheed on 04,November,2019
12-
*/
13-
1410
/**
1511
* Global executor pools for the whole application.
1612
*

app/src/main/java/com/kotlin/mvvm/di/modules/AppModule.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import retrofit2.converter.gson.GsonConverterFactory
1818
import javax.inject.Singleton
1919

2020
/**
21-
* Created by Waheed on 04,November,2019
22-
* Migrated to Hilt 20, June, 2021
21+
* App module listing all modules
2322
*/
2423

2524
@Module

app/src/main/java/com/kotlin/mvvm/di/modules/PreferencesModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dagger.hilt.components.SingletonComponent
1010
import javax.inject.Singleton
1111

1212
/**
13-
* Created by Waheed on 04,November,2019
13+
* Created by Waheed
1414
* Migrated to Hilt 20, June, 2021
1515
*/
1616

app/src/main/java/com/kotlin/mvvm/repository/api/ApiServices.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ import androidx.lifecycle.LiveData
44
import com.kotlin.mvvm.repository.api.network.Resource
55
import com.kotlin.mvvm.repository.model.news.NewsSource
66
import retrofit2.http.GET
7+
import retrofit2.http.Header
78
import retrofit2.http.QueryMap
89

910
/**
10-
* Created by Waheed on 04,November,2019
11+
* Created by Waheed
1112
* Api services to communicate with server
1213
*/
1314

1415
interface ApiServices {
1516
/**
1617
* Fetch news articles from Google news using GET API Call on given Url
1718
* Url would be something like this top-headlines?country=my&apiKey=XYZ
19+
* GET https://newsapi.org/v2/everything?q=Apple&from=2024-10-03&sortBy=popularity&apiKey=API_KEY
20+
* GET https://newsapi.org/v2/top-headlines?country=us&apiKey=API_KEY
21+
*
22+
* Response{protocol=h2, code=429, message=, url=https://newsapi.org/v2/top-headlines?country=ar&apiKey=28679d41d4454bffaf6a4f40d4b024cc}
1823
*/
1924
@GET("top-headlines")
20-
fun getNewsSource(@QueryMap options: Map<String, String>): LiveData<Resource<NewsSource>>
25+
fun getNewsSource(
26+
@QueryMap options: Map<String, String>
27+
): LiveData<Resource<NewsSource>>
2128

2229
}

app/src/main/java/com/kotlin/mvvm/repository/api/network/LiveDataCallAdapter.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import java.lang.reflect.Type
88
import java.util.concurrent.atomic.AtomicBoolean
99

1010

11-
/**
12-
* Created by Waheed on 04,November,2019
13-
*/
11+
1412

1513
/**
1614
* A Retrofit adapter that converts the Call into a LiveData of ApiResponse.

app/src/main/java/com/kotlin/mvvm/repository/api/network/LiveDataCallAdapterFactoryForRetrofit.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.kotlin.mvvm.repository.api.network;
22

3-
/**
4-
* Created by Waheed on 04,November,2019
5-
*/
3+
64

75
import androidx.annotation.NonNull;
86
import androidx.lifecycle.LiveData;

0 commit comments

Comments
 (0)