@@ -1,4 +1,4 @@ |
||
1 |
-package ai.pai.lensman.box; |
|
1 |
+package ai.pai.lensman.bean; |
|
2 | 2 |
|
3 | 3 |
import android.support.annotation.NonNull; |
4 | 4 |
|
@@ -10,6 +10,7 @@ import java.net.ConnectException; |
||
10 | 10 |
import java.net.SocketTimeoutException; |
11 | 11 |
import java.net.UnknownHostException; |
12 | 12 |
|
13 |
+import ai.pai.lensman.box.BoxClient; |
|
13 | 14 |
import retrofit2.Response; |
14 | 15 |
|
15 | 16 |
public class Result { |
@@ -43,7 +44,7 @@ public class Result { |
||
43 | 44 |
|
44 | 45 |
public static <T extends Result> Error buildError(@NonNull Response<T> response) { |
45 | 46 |
try { |
46 |
- return ApiClient.gson.fromJson(response.errorBody().string(), Error.class); |
|
47 |
+ return BoxClient.gson.fromJson(response.errorBody().string(), Error.class); |
|
47 | 48 |
} catch (IOException | JsonSyntaxException e) { |
48 | 49 |
Error error = new Error(); |
49 | 50 |
error.success = false; |
@@ -1,57 +0,0 @@ |
||
1 |
-package ai.pai.lensman.box; |
|
2 |
- |
|
3 |
-import com.google.gson.Gson; |
|
4 |
-import com.google.gson.GsonBuilder; |
|
5 |
- |
|
6 |
-import java.io.IOException; |
|
7 |
-import java.util.concurrent.TimeUnit; |
|
8 |
- |
|
9 |
-import ai.pai.lensman.BuildConfig; |
|
10 |
-import okhttp3.Interceptor; |
|
11 |
-import okhttp3.OkHttpClient; |
|
12 |
-import okhttp3.Request; |
|
13 |
-import okhttp3.Response; |
|
14 |
-import okhttp3.logging.HttpLoggingInterceptor; |
|
15 |
-import retrofit2.Retrofit; |
|
16 |
-import retrofit2.converter.gson.GsonConverterFactory; |
|
17 |
- |
|
18 |
-public final class ApiClient { |
|
19 |
- |
|
20 |
- private static final String BASE_URL = " http://120.27.44.52:8001/"; |
|
21 |
- |
|
22 |
- private static final OkHttpClient client = new OkHttpClient.Builder() |
|
23 |
- .retryOnConnectionFailure(true) |
|
24 |
- .connectTimeout(10, TimeUnit.SECONDS) |
|
25 |
-// .addInterceptor(createUserAgentInterceptor()) |
|
26 |
-// .addInterceptor(createHttpLoggingInterceptor()) |
|
27 |
- .build(); |
|
28 |
- |
|
29 |
- public static final Gson gson = new GsonBuilder().create(); |
|
30 |
- |
|
31 |
- public static final ApiService service = new Retrofit.Builder() |
|
32 |
- .baseUrl(BASE_URL) |
|
33 |
- .client(client) |
|
34 |
- .addConverterFactory(GsonConverterFactory.create(gson)) |
|
35 |
- .build() |
|
36 |
- .create(ApiService.class); |
|
37 |
- |
|
38 |
- private static Interceptor createUserAgentInterceptor() { |
|
39 |
- return new Interceptor() { |
|
40 |
- |
|
41 |
- @Override |
|
42 |
- public Response intercept(Chain chain) throws IOException { |
|
43 |
- Request request = chain.request().newBuilder() |
|
44 |
- .build(); |
|
45 |
- return chain.proceed(request); |
|
46 |
- } |
|
47 |
- |
|
48 |
- }; |
|
49 |
- } |
|
50 |
- |
|
51 |
- private static Interceptor createHttpLoggingInterceptor() { |
|
52 |
- HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); |
|
53 |
- loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE); |
|
54 |
- return loggingInterceptor; |
|
55 |
- } |
|
56 |
- |
|
57 |
-} |
@@ -0,0 +1,30 @@ |
||
1 |
+package ai.pai.lensman.box; |
|
2 |
+ |
|
3 |
+import com.google.gson.Gson; |
|
4 |
+import com.google.gson.GsonBuilder; |
|
5 |
+ |
|
6 |
+import java.util.concurrent.TimeUnit; |
|
7 |
+ |
|
8 |
+import okhttp3.OkHttpClient; |
|
9 |
+import retrofit2.Retrofit; |
|
10 |
+import retrofit2.converter.gson.GsonConverterFactory; |
|
11 |
+ |
|
12 |
+public final class BoxClient { |
|
13 |
+ |
|
14 |
+ private static final String BASE_URL = " http://120.27.44.52:8001/"; |
|
15 |
+ |
|
16 |
+ private static final OkHttpClient client = new OkHttpClient.Builder() |
|
17 |
+ .retryOnConnectionFailure(true) |
|
18 |
+ .connectTimeout(10, TimeUnit.SECONDS) |
|
19 |
+ .build(); |
|
20 |
+ |
|
21 |
+ public static final Gson gson = new GsonBuilder().create(); |
|
22 |
+ |
|
23 |
+ public static final BoxHttpService service = new Retrofit.Builder() |
|
24 |
+ .baseUrl(BASE_URL) |
|
25 |
+ .client(client) |
|
26 |
+ .addConverterFactory(GsonConverterFactory.create(gson)) |
|
27 |
+ .build() |
|
28 |
+ .create(BoxHttpService.class); |
|
29 |
+ |
|
30 |
+} |
@@ -8,7 +8,7 @@ import retrofit2.http.Field; |
||
8 | 8 |
import retrofit2.http.FormUrlEncoded; |
9 | 9 |
import retrofit2.http.POST; |
10 | 10 |
|
11 |
-public interface ApiService { |
|
11 |
+public interface BoxHttpService { |
|
12 | 12 |
|
13 | 13 |
|
14 | 14 |
@POST("session_start") |
@@ -1,5 +1,6 @@ |
||
1 | 1 |
package ai.pai.lensman.box; |
2 | 2 |
|
3 |
+import ai.pai.lensman.bean.Result; |
|
3 | 4 |
import retrofit2.Response; |
4 | 5 |
|
5 | 6 |
public interface CallbackLifecycle<T> { |
@@ -37,7 +37,7 @@ public class UploadTask extends AsyncTask<String,Integer,Boolean> { |
||
37 | 37 |
File photo = new File(photoPath); |
38 | 38 |
LogHelper.d(TAG,"上传照片,路径为 = "+photoPath); |
39 | 39 |
if(photo.exists() &&photo.isFile()){ |
40 |
- PhotoUploadUtils photoUploadUtils = new PhotoUploadUtils(UrlContainer.HOME_PHOTO_URL+"?timestamp="+System.currentTimeMillis()); |
|
40 |
+ PhotoUploadUtils photoUploadUtils = new PhotoUploadUtils(UrlContainer.PHOTO_UPLOAD_URL+"?timestamp="+System.currentTimeMillis()); |
|
41 | 41 |
photoUploadUtils.addFileParameter("photo", photo); |
42 | 42 |
photoUploadUtils.addTextParameter("user_id", Preferences.getInstance(context).getLensManId()); |
43 | 43 |
photoUploadUtils.addTextParameter("group_id", groupId); |
@@ -7,7 +7,7 @@ import java.util.Timer; |
||
7 | 7 |
import java.util.TimerTask; |
8 | 8 |
|
9 | 9 |
import ai.pai.lensman.bean.PhotoBean; |
10 |
-import ai.pai.lensman.box.ApiClient; |
|
10 |
+import ai.pai.lensman.box.BoxClient; |
|
11 | 11 |
import ai.pai.lensman.db.Preferences; |
12 | 12 |
import retrofit2.Call; |
13 | 13 |
import retrofit2.Callback; |
@@ -40,7 +40,7 @@ public class SessionInteractor { |
||
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
public void startSession(){ |
43 |
- ApiClient.service.startNewSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
43 |
+ BoxClient.service.startNewSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
44 | 44 |
@Override |
45 | 45 |
public void onResponse(Call<String> call, Response<String> response) { |
46 | 46 |
listener.onSessionStartSuccess(sessionId); |
@@ -62,7 +62,7 @@ public class SessionInteractor { |
||
62 | 62 |
timer.schedule(new TimerTask() { |
63 | 63 |
@Override |
64 | 64 |
public void run() { |
65 |
- ApiClient.service.fetchSessionThumbnails(sessionId,lensmanId).enqueue(new Callback<List<PhotoBean>>() { |
|
65 |
+ BoxClient.service.fetchSessionThumbnails(sessionId,lensmanId).enqueue(new Callback<List<PhotoBean>>() { |
|
66 | 66 |
@Override |
67 | 67 |
public void onResponse(Call<List<PhotoBean>> call, Response<List<PhotoBean>> response) { |
68 | 68 |
|
@@ -82,7 +82,7 @@ public class SessionInteractor { |
||
82 | 82 |
timer.cancel(); |
83 | 83 |
timer = null; |
84 | 84 |
} |
85 |
- ApiClient.service.endSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
85 |
+ BoxClient.service.endSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
86 | 86 |
@Override |
87 | 87 |
public void onResponse(Call<String> call, Response<String> response) { |
88 | 88 |
listener.onSessionEnd(sessionId); |
@@ -7,8 +7,14 @@ public class UrlContainer { |
||
7 | 7 |
|
8 | 8 |
public static final String HOST_URL = "http://api.pai.ai/"; |
9 | 9 |
|
10 |
- public static final String HOME_PHOTO_URL = HOST_URL+"pai2/home"; |
|
11 |
- |
|
12 | 10 |
public static final String CHECK_UPDATE_URL = HOST_URL+"op/upgrade"; |
13 | 11 |
|
12 |
+ public static final String LOGIN_URL = HOST_URL+"login"; |
|
13 |
+ |
|
14 |
+ public static final String SESSION_IDS_CREATE = HOST_URL+"uuid_init"; |
|
15 |
+ |
|
16 |
+ public static final String PHOTO_UPLOAD_URL = HOST_URL+"photos/upload"; |
|
17 |
+ |
|
18 |
+ |
|
19 |
+ |
|
14 | 20 |
} |