11package com.vimalvijay.mymodule.di.modules
22
3+ import android.app.Application
34import android.content.Context
5+ import android.content.SharedPreferences
46import com.google.gson.FieldNamingPolicy
57import com.google.gson.GsonBuilder
68import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
79import com.vimalvijay.mymodule.BuildConfig
10+ import com.vimalvijay.mymodule.R
811import com.vimalvijay.mymodule.commonutils.CustomProgressbar
12+ import com.vimalvijay.mymodule.commonutils.SessionDataManager
913import com.vimalvijay.mymodule.network.api.ApiConstants
1014import com.vimalvijay.mymodule.network.api.ApiService
15+ import com.vimalvijay.mymodule.network.interceptors.AuthInterceptor
1116import com.vimalvijay.mymodule.network.interceptors.LoggingInterceptor
1217import dagger.Module
1318import dagger.Provides
1419import dagger.hilt.InstallIn
15- import dagger.hilt.android.components.ApplicationComponent
1620import dagger.hilt.android.qualifiers.ApplicationContext
21+ import dagger.hilt.components.SingletonComponent
1722import okhttp3.OkHttpClient
1823import okhttp3.logging.HttpLoggingInterceptor
1924import retrofit2.Retrofit
@@ -22,7 +27,7 @@ import javax.inject.Singleton
2227
2328
2429@Module
25- @InstallIn(ApplicationComponent ::class )
30+ @InstallIn(SingletonComponent ::class )
2631class AppModule {
2732 /* *
2833 * Application's Base URL
@@ -35,15 +40,16 @@ class AppModule {
3540 */
3641 @Provides
3742 @Singleton
38- fun provideOkHttpClient (@ApplicationContext context : Context ): OkHttpClient {
43+ fun provideOkHttpClient (@ApplicationContext context : Context , sessionDataManager : SessionDataManager ): OkHttpClient {
3944 val loggingInterceptor = HttpLoggingInterceptor ()
45+ loggingInterceptor.level = HttpLoggingInterceptor .Level .HEADERS
4046 loggingInterceptor.level = HttpLoggingInterceptor .Level .BODY
4147 val okHttpClient = OkHttpClient .Builder ()
48+ okHttpClient.addInterceptor(AuthInterceptor (sessionDataManager))
49+ okHttpClient.addInterceptor(LoggingInterceptor (context))
4250 if (BuildConfig .DEBUG ) {
4351 okHttpClient.addInterceptor(loggingInterceptor)
4452 }
45- // okHttpClient.addInterceptor(ErrorInterceptor(context))
46- okHttpClient.addInterceptor(LoggingInterceptor (context))
4753 return okHttpClient.build()
4854 }
4955
@@ -81,7 +87,18 @@ class AppModule {
8187 * Custom Progress Bar
8288 */
8389 @Provides
90+ @Singleton
8491 fun provideCustomProgressBar (): CustomProgressbar {
8592 return CustomProgressbar ()
8693 }
94+
95+ /* *
96+ * SessionDataManager
97+ */
98+ @Provides
99+ @Singleton
100+ fun provideSessionManager (application : Application ): SessionDataManager {
101+ return SessionDataManager (application.getSharedPreferences(application.resources.getString(R .string.app_name), Context .MODE_PRIVATE ))
102+ }
103+
87104}
0 commit comments