feature/fetch_userinfo #85

Merged
Fujimatsu merged 35 commits from feature/fetch_userinfo into main 2024-06-24 01:36:45 +00:00
Showing only changes of commit 3423037837 - Show all commits

View File

@ -1,4 +1,58 @@
package one.nem.kidshift.data.retrofit; package one.nem.kidshift.data.retrofit;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import dagger.hilt.InstallIn;
import dagger.hilt.components.SingletonComponent;
import okhttp3.OkHttpClient;
import one.nem.kidshift.data.UserSettings;
import one.nem.kidshift.data.retrofit.interceptor.AuthorizationInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
@Module
@InstallIn(SingletonComponent.class)
public class KidShiftApiServiceModule { public class KidShiftApiServiceModule {
@Inject
UserSettings userSettings;
@Provides
@Singleton
public AuthorizationInterceptor provideAuthorizationInterceptor() {
return new AuthorizationInterceptor(userSettings);
}
// Gson
@Provides
@Singleton
public Gson provideGson() {
return new GsonBuilder()
.create();
}
@Provides
@Singleton
public OkHttpClient provideOkHttpClient() {
return new OkHttpClient.Builder()
.addInterceptor(provideAuthorizationInterceptor())
.build();
}
@Provides
@Singleton
public KidShiftApiService provideKidShiftApiService() {
return new Retrofit.Builder()
.baseUrl(userSettings.getApiSetting().getApiBaseUrl())
.addConverterFactory(GsonConverterFactory.create(provideGson()))
.client(provideOkHttpClient())
.build()
.create(KidShiftApiService.class);
}
} }