@@ -41,10 +41,6 @@ dependencies { |
||
41 | 41 |
compile 'com.android.support:design:24.0.0' |
42 | 42 |
compile 'com.jakewharton:butterknife:8.2.1' |
43 | 43 |
apt 'com.jakewharton:butterknife-compiler:8.2.1' |
44 |
- compile 'com.squareup.okhttp3:okhttp:3.4.1' |
|
45 |
- compile 'com.squareup.okhttp3:logging-interceptor:3.3.1' |
|
46 |
- compile 'com.squareup.retrofit2:retrofit:2.1.0' |
|
47 | 44 |
compile 'com.google.code.gson:gson:2.7' |
48 |
- compile 'com.squareup.retrofit2:converter-gson:2.1.0' |
|
49 | 45 |
|
50 | 46 |
} |
@@ -16,8 +16,6 @@ |
||
16 | 16 |
|
17 | 17 |
package ai.pai.lensman.base; |
18 | 18 |
|
19 |
-public interface BaseView<T> { |
|
20 |
- |
|
21 |
- void setPresenter(T presenter); |
|
19 |
+public interface BaseView { |
|
22 | 20 |
|
23 | 21 |
} |
@@ -1,103 +0,0 @@ |
||
1 |
-package ai.pai.lensman.bean; |
|
2 |
- |
|
3 |
-import android.support.annotation.NonNull; |
|
4 |
- |
|
5 |
-import com.google.gson.JsonSyntaxException; |
|
6 |
-import com.google.gson.annotations.SerializedName; |
|
7 |
- |
|
8 |
-import java.io.IOException; |
|
9 |
-import java.net.ConnectException; |
|
10 |
-import java.net.SocketTimeoutException; |
|
11 |
-import java.net.UnknownHostException; |
|
12 |
- |
|
13 |
-import ai.pai.lensman.box.BoxClient; |
|
14 |
-import retrofit2.Response; |
|
15 |
- |
|
16 |
-public class Result { |
|
17 |
- |
|
18 |
- protected boolean success; |
|
19 |
- |
|
20 |
- public boolean isSuccess() { |
|
21 |
- return success; |
|
22 |
- } |
|
23 |
- |
|
24 |
- public static class Data<T> extends Result { |
|
25 |
- |
|
26 |
- private T data; |
|
27 |
- |
|
28 |
- public T getData() { |
|
29 |
- return data; |
|
30 |
- } |
|
31 |
- |
|
32 |
- } |
|
33 |
- |
|
34 |
- public static class Error extends Result { |
|
35 |
- |
|
36 |
- @SerializedName("error_msg") |
|
37 |
- private String errorMessage; |
|
38 |
- |
|
39 |
- public String getErrorMessage() { |
|
40 |
- return errorMessage; |
|
41 |
- } |
|
42 |
- |
|
43 |
- } |
|
44 |
- |
|
45 |
- public static <T extends Result> Error buildError(@NonNull Response<T> response) { |
|
46 |
- try { |
|
47 |
- return BoxClient.gson.fromJson(response.errorBody().string(), Error.class); |
|
48 |
- } catch (IOException | JsonSyntaxException e) { |
|
49 |
- Error error = new Error(); |
|
50 |
- error.success = false; |
|
51 |
- switch (response.code()) { |
|
52 |
- case 400: |
|
53 |
- error.errorMessage = "请求参数有误"; |
|
54 |
- break; |
|
55 |
- case 403: |
|
56 |
- error.errorMessage = "请求被拒绝"; |
|
57 |
- break; |
|
58 |
- case 404: |
|
59 |
- error.errorMessage = "资源未找到"; |
|
60 |
- break; |
|
61 |
- case 405: |
|
62 |
- error.errorMessage = "请求方式不被允许"; |
|
63 |
- break; |
|
64 |
- case 408: |
|
65 |
- error.errorMessage = "请求超时"; |
|
66 |
- break; |
|
67 |
- case 422: |
|
68 |
- error.errorMessage = "请求语义错误"; |
|
69 |
- break; |
|
70 |
- case 500: |
|
71 |
- error.errorMessage = "服务器逻辑错误"; |
|
72 |
- break; |
|
73 |
- case 502: |
|
74 |
- error.errorMessage = "服务器网关错误"; |
|
75 |
- break; |
|
76 |
- case 504: |
|
77 |
- error.errorMessage = "服务器网关超时"; |
|
78 |
- break; |
|
79 |
- default: |
|
80 |
- error.errorMessage = response.message(); |
|
81 |
- break; |
|
82 |
- } |
|
83 |
- return error; |
|
84 |
- } |
|
85 |
- } |
|
86 |
- |
|
87 |
- public static Error buildError(@NonNull Throwable t) { |
|
88 |
- Error error = new Error(); |
|
89 |
- error.success = false; |
|
90 |
- if (t instanceof UnknownHostException || t instanceof ConnectException) { |
|
91 |
- error.errorMessage = "网络无法连接"; |
|
92 |
- } else if (t instanceof SocketTimeoutException) { |
|
93 |
- error.errorMessage = "网络访问超时"; |
|
94 |
- } else if (t instanceof JsonSyntaxException) { |
|
95 |
- error.errorMessage = "响应数据格式错误"; |
|
96 |
- } else { |
|
97 |
- error.errorMessage = "未知错误:" + t.getLocalizedMessage(); |
|
98 |
- } |
|
99 |
- return error; |
|
100 |
- } |
|
101 |
- |
|
102 |
- |
|
103 |
-} |
@@ -1,30 +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.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 |
-} |
@@ -1,31 +0,0 @@ |
||
1 |
-package ai.pai.lensman.box; |
|
2 |
- |
|
3 |
-import java.util.List; |
|
4 |
- |
|
5 |
-import ai.pai.lensman.bean.PhotoBean; |
|
6 |
-import retrofit2.Call; |
|
7 |
-import retrofit2.http.Field; |
|
8 |
-import retrofit2.http.FormUrlEncoded; |
|
9 |
-import retrofit2.http.POST; |
|
10 |
- |
|
11 |
-public interface BoxHttpService { |
|
12 |
- |
|
13 |
- |
|
14 |
- @POST("session_start") |
|
15 |
- @FormUrlEncoded |
|
16 |
- Call<String> startNewSession(@Field("session") String sessionId ,@Field("lensman") String lensmanId); |
|
17 |
- |
|
18 |
- @POST("session_end") |
|
19 |
- @FormUrlEncoded |
|
20 |
- Call<String> endSession(@Field("session") String sessionId, @Field("lensman") String lensmanId); |
|
21 |
- |
|
22 |
- @POST("fetch_thumbnail") |
|
23 |
- @FormUrlEncoded |
|
24 |
- Call<List<PhotoBean>> fetchSessionThumbnails(@Field("session") String sessionId, @Field("lensman") String lensmanId); |
|
25 |
- |
|
26 |
- @POST("fetch_origin") |
|
27 |
- @FormUrlEncoded |
|
28 |
- Call<String> fetchSessionOriginPhoto(@Field("session") String sessionId, @Field("lensman") String lensmanId, @Field("name") String name); |
|
29 |
- |
|
30 |
- |
|
31 |
-} |
@@ -0,0 +1,16 @@ |
||
1 |
+package ai.pai.lensman.box; |
|
2 |
+ |
|
3 |
+public final class BoxUrlContainer { |
|
4 |
+ |
|
5 |
+ private static final String BASE_URL = " http://120.27.44.52:8001/"; |
|
6 |
+ |
|
7 |
+ public static final String SESSION_START_URL = BASE_URL+"session_start"; |
|
8 |
+ |
|
9 |
+ public static final String SESSION_END_URL = BASE_URL+"session_end"; |
|
10 |
+ |
|
11 |
+ public static final String FETCH_THUMBNAIL_URL = BASE_URL+"fetch_thumbnail"; |
|
12 |
+ |
|
13 |
+ public static final String FETCH_ORIGIN_URL = BASE_URL+"fetch_origin"; |
|
14 |
+ |
|
15 |
+ |
|
16 |
+} |
@@ -1,18 +0,0 @@ |
||
1 |
-package ai.pai.lensman.box; |
|
2 |
- |
|
3 |
-import ai.pai.lensman.bean.Result; |
|
4 |
-import retrofit2.Response; |
|
5 |
- |
|
6 |
-public interface CallbackLifecycle<T> { |
|
7 |
- |
|
8 |
- boolean onResultOk(Response<T> response, T result); |
|
9 |
- |
|
10 |
- boolean onResultError(Response<T> response, Result.Error error); |
|
11 |
- |
|
12 |
- boolean onCallCancel(); |
|
13 |
- |
|
14 |
- boolean onCallException(Throwable t, Result.Error error); |
|
15 |
- |
|
16 |
- void onFinish(); |
|
17 |
- |
|
18 |
-} |
@@ -65,8 +65,4 @@ public class LoginActivity extends BaseActivity implements LoginContract.View{ |
||
65 | 65 |
finish(); |
66 | 66 |
} |
67 | 67 |
|
68 |
- @Override |
|
69 |
- public void setPresenter(LoginContract.Presenter presenter) { |
|
70 |
- |
|
71 |
- } |
|
72 | 68 |
} |
@@ -5,7 +5,7 @@ import ai.pai.lensman.base.BaseView; |
||
5 | 5 |
|
6 | 6 |
public class LoginContract { |
7 | 7 |
|
8 |
- interface View extends BaseView<Presenter>{ |
|
8 |
+ interface View extends BaseView{ |
|
9 | 9 |
void showLoginHint(String hint); |
10 | 10 |
void showProgressView(); |
11 | 11 |
void hideProgressView(); |
@@ -121,8 +121,4 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
121 | 121 |
|
122 | 122 |
} |
123 | 123 |
|
124 |
- @Override |
|
125 |
- public void setPresenter(SessionContract.Presenter presenter) { |
|
126 |
- |
|
127 |
- } |
|
128 | 124 |
} |
@@ -9,7 +9,7 @@ import ai.pai.lensman.bean.PhotoBean; |
||
9 | 9 |
*/ |
10 | 10 |
public class SessionContract { |
11 | 11 |
|
12 |
- interface View extends BaseView<Presenter>{ |
|
12 |
+ interface View extends BaseView{ |
|
13 | 13 |
void addNewPhoto(PhotoBean bean); |
14 | 14 |
void showPhotoRecyclerView(); |
15 | 15 |
void showEmptyView(); |
@@ -2,16 +2,11 @@ package ai.pai.lensman.session; |
||
2 | 2 |
|
3 | 3 |
import android.content.Context; |
4 | 4 |
|
5 |
-import java.util.List; |
|
6 | 5 |
import java.util.Timer; |
7 | 6 |
import java.util.TimerTask; |
8 | 7 |
|
9 | 8 |
import ai.pai.lensman.bean.PhotoBean; |
10 |
-import ai.pai.lensman.box.BoxClient; |
|
11 | 9 |
import ai.pai.lensman.db.Preferences; |
12 |
-import retrofit2.Call; |
|
13 |
-import retrofit2.Callback; |
|
14 |
-import retrofit2.Response; |
|
15 | 10 |
|
16 | 11 |
/** |
17 | 12 |
* Created by chengzhenyu on 2016/7/7. |
@@ -40,17 +35,7 @@ public class SessionInteractor { |
||
40 | 35 |
} |
41 | 36 |
|
42 | 37 |
public void startSession(){ |
43 |
- BoxClient.service.startNewSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
44 |
- @Override |
|
45 |
- public void onResponse(Call<String> call, Response<String> response) { |
|
46 |
- listener.onSessionStartSuccess(sessionId); |
|
47 |
- } |
|
48 | 38 |
|
49 |
- @Override |
|
50 |
- public void onFailure(Call<String> call, Throwable t) { |
|
51 |
- listener.onSessionStartError(sessionId); |
|
52 |
- } |
|
53 |
- }); |
|
54 | 39 |
} |
55 | 40 |
|
56 | 41 |
public void startCapture() { |
@@ -61,19 +46,7 @@ public class SessionInteractor { |
||
61 | 46 |
timer = new Timer(); |
62 | 47 |
timer.schedule(new TimerTask() { |
63 | 48 |
@Override |
64 |
- public void run() { |
|
65 |
- BoxClient.service.fetchSessionThumbnails(sessionId,lensmanId).enqueue(new Callback<List<PhotoBean>>() { |
|
66 |
- @Override |
|
67 |
- public void onResponse(Call<List<PhotoBean>> call, Response<List<PhotoBean>> response) { |
|
68 |
- |
|
69 |
- } |
|
70 |
- |
|
71 |
- @Override |
|
72 |
- public void onFailure(Call<List<PhotoBean>> call, Throwable t) { |
|
73 |
- |
|
74 |
- } |
|
75 |
- }); |
|
76 |
- } |
|
49 |
+ public void run() {} |
|
77 | 50 |
},1000,1000); |
78 | 51 |
} |
79 | 52 |
|
@@ -82,17 +55,7 @@ public class SessionInteractor { |
||
82 | 55 |
timer.cancel(); |
83 | 56 |
timer = null; |
84 | 57 |
} |
85 |
- BoxClient.service.endSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
86 |
- @Override |
|
87 |
- public void onResponse(Call<String> call, Response<String> response) { |
|
88 |
- listener.onSessionEnd(sessionId); |
|
89 |
- } |
|
90 |
- |
|
91 |
- @Override |
|
92 |
- public void onFailure(Call<String> call, Throwable t) { |
|
93 | 58 |
|
94 |
- } |
|
95 |
- }); |
|
96 | 59 |
} |
97 | 60 |
|
98 | 61 |
} |
@@ -137,8 +137,4 @@ public class UploadActivity extends BaseActivity implements UploadContract.View |
||
137 | 137 |
}); |
138 | 138 |
} |
139 | 139 |
|
140 |
- @Override |
|
141 |
- public void setPresenter(UploadContract.Presenter presenter) { |
|
142 |
- |
|
143 |
- } |
|
144 | 140 |
} |
@@ -11,7 +11,7 @@ import ai.pai.lensman.bean.SessionBean; |
||
11 | 11 |
*/ |
12 | 12 |
public class UploadContract { |
13 | 13 |
|
14 |
- interface View extends BaseView<Presenter> { |
|
14 |
+ interface View extends BaseView { |
|
15 | 15 |
|
16 | 16 |
void addNewSessionView(SessionBean bean); |
17 | 17 |
void showBTDisconnectedView(); |