
이전 네트워크 관련 설정은 똑같이 설정해주자!
build.gradle에 필요한 라이브러리를 추가하자.
// Retrofit 라이브러리
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
// Gson 변환기 라이브러리
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
// Scalars 변환기 라이브러리
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
api/NetworkClient.Class를 생성하자.

public class NetworkClient {
public static Retrofit retrofit;
public static Retrofit getRetrofitClient(Context context){
if(retrofit == null){
// 네트워크 통신한, 로그를 확인하는 코드
// http 로깅 셋팅
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// 네트워크 연결시키는 코드
OkHttpClient httpClient = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES) //네트워크 연결 하는 시간을 최대 1분으로 설정
.readTimeout(1, TimeUnit.MINUTES) // 네트워크를 읽는데 시간을 최대 1분으로 설정
.writeTimeout(1, TimeUnit.MINUTES) //
.addInterceptor(loggingInterceptor)
.build();
retrofit = new Retrofit.Builder()
.baseUrl(Config.BASE_URL) //Config에 작성된 url을 가져온다.
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
아주 유익한 내용이네요!