-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathRestClient.java
More file actions
44 lines (36 loc) · 1.39 KB
/
RestClient.java
File metadata and controls
44 lines (36 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package ua.naiksoftware.stompclientexample;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by Naik on 24.02.17.
*/
public class RestClient {
public static final String ANDROID_EMULATOR_LOCALHOST = "10.0.2.2";
public static final String SERVER_PORT = "8080";
private static RestClient instance;
private static final Object lock = new Object();
public static RestClient getInstance() {
RestClient instance = RestClient.instance;
if (instance == null) {
synchronized (lock) {
instance = RestClient.instance;
if (instance == null) {
RestClient.instance = instance = new RestClient();
}
}
}
return instance;
}
private final ExampleRepository mExampleRepository;
private RestClient() {
Retrofit retrofit = new Retrofit.Builder().baseUrl("http://" + ANDROID_EMULATOR_LOCALHOST + ":" + SERVER_PORT + "/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.build();
mExampleRepository = retrofit.create(ExampleRepository.class);
}
public ExampleRepository getExampleRepository() {
return mExampleRepository;
}
}