增加session工作日志

chengzhenyu 8 年之前
父节点
当前提交
656bb8e8be

+ 9 - 0
app/src/main/java/ai/pai/lensman/bean/SessionBean.java

@@ -13,4 +13,13 @@ public class SessionBean implements Serializable{
13 13
     public String sessionId;
14 14
     public ArrayList<PhotoBean> sessionPhotos;
15 15
 
16
+    @Override
17
+    public String toString() {
18
+        return "SessionBean{" +
19
+                "sessionSeq=" + sessionSeq +
20
+                ", sessionDate=" + sessionDate +
21
+                ", lensmanId='" + lensmanId + '\'' +
22
+                ", sessionId='" + sessionId + '\'' +
23
+                '}';
24
+    }
16 25
 }

+ 5 - 0
app/src/main/java/ai/pai/lensman/main/MainActivity.java

@@ -10,6 +10,8 @@ import android.widget.ImageView;
10 10
 import android.widget.TextView;
11 11
 import android.widget.Toast;
12 12
 
13
+import com.android.common.utils.LogHelper;
14
+
13 15
 import java.util.ArrayList;
14 16
 
15 17
 import ai.pai.lensman.R;
@@ -50,12 +52,14 @@ public class MainActivity extends BaseActivity implements MainContract.View {
50 52
     protected void onResume() {
51 53
         super.onResume();
52 54
         presenter.start();
55
+        LogHelper.d(TAG,"onResume");
53 56
     }
54 57
 
55 58
     @Override
56 59
     protected void onStop() {
57 60
         super.onStop();
58 61
         presenter.stop();
62
+        LogHelper.d(TAG,"onStop");
59 63
     }
60 64
 
61 65
     @OnClick(R.id.iv_briefs)
@@ -65,6 +69,7 @@ public class MainActivity extends BaseActivity implements MainContract.View {
65 69
 
66 70
     @OnClick(R.id.iv_add_session)
67 71
     void jumpToNewSession(){
72
+        LogHelper.d(TAG,"jumpToNewSession");
68 73
         jumpToSelectedSession( presenter.createNewSession());
69 74
     }
70 75
 

+ 0 - 4
app/src/main/java/ai/pai/lensman/main/MainPresenter.java

@@ -177,7 +177,6 @@ class MainPresenter implements MainContract.Presenter,BaseInteractor.InteractorL
177 177
         if(position < 0 || position>=sessionList.size()){
178 178
             return;
179 179
         }
180
-        LogHelper.d("czy","onPhotoUploaded and notify UI change at "+position);
181 180
         SessionBean sessionBean = sessionList.get(position);
182 181
         ArrayList<PhotoBean> photoList = sessionBean.sessionPhotos;
183 182
         if(photoList==null || photoList.size()==0){
@@ -186,7 +185,6 @@ class MainPresenter implements MainContract.Presenter,BaseInteractor.InteractorL
186 185
         }else{
187 186
             for(PhotoBean photoBean : photoList){
188 187
                 if(photoBean.photoId == bean.photoId){
189
-                    LogHelper.d("czy","onPhotoUploaded and found data change "+position);
190 188
                     photoBean.uploadStatus = PhotoBean.UploadStatus.STATUS_SUCCESS;
191 189
                     break;
192 190
                 }
@@ -202,7 +200,6 @@ class MainPresenter implements MainContract.Presenter,BaseInteractor.InteractorL
202 200
         if(position < 0 || position>=sessionList.size()){
203 201
             return;
204 202
         }
205
-        LogHelper.d("czy","onPhotoUploadError and notify UI change at "+position);
206 203
         SessionBean sessionBean = sessionList.get(position);
207 204
         ArrayList<PhotoBean> photoList = sessionBean.sessionPhotos;
208 205
         if(photoList==null || photoList.size()==0){
@@ -211,7 +208,6 @@ class MainPresenter implements MainContract.Presenter,BaseInteractor.InteractorL
211 208
         }else{
212 209
             for(PhotoBean photoBean : photoList){
213 210
                 if(photoBean.photoId == bean.photoId){
214
-                    LogHelper.d("czy","onPhotoUploaded and found data change "+position);
215 211
                     photoBean.uploadStatus = PhotoBean.UploadStatus.STATUS_ERROR;
216 212
                     break;
217 213
                 }

+ 5 - 1
app/src/main/java/ai/pai/lensman/session/SessionActivity.java

@@ -20,7 +20,6 @@ import ai.pai.lensman.bean.PhotoBean;
20 20
 import ai.pai.lensman.bean.SessionBean;
21 21
 import ai.pai.lensman.printer.PrinterSettingActivity;
22 22
 import ai.pai.lensman.qrcode.QRCaptureActivity;
23
-import ai.pai.lensman.utils.UrlContainer;
24 23
 import butterknife.BindView;
25 24
 import butterknife.ButterKnife;
26 25
 import butterknife.OnClick;
@@ -84,12 +83,16 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
84 83
         itemTouchHelper.attachToRecyclerView(photosRecyclerView);
85 84
 
86 85
         presenter.start();
86
+
87
+        LogHelper.d(TAG,"onCreate");
88
+        LogHelper.d(TAG,"session info = "+sessionBean);
87 89
     }
88 90
 
89 91
     @Override
90 92
     protected void onDestroy() {
91 93
         super.onDestroy();
92 94
         presenter.stop();
95
+        LogHelper.d(TAG,"onDestroy");
93 96
     }
94 97
 
95 98
     @OnClick(R.id.iv_scan)
@@ -119,6 +122,7 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
119 122
 
120 123
     @Override
121 124
     public synchronized void addNewPhoto(final PhotoBean bean) {
125
+        LogHelper.d(TAG,"addNewPhoto to UI "+bean);
122 126
         adapter.addPhotoBean(bean);
123 127
         photosRecyclerView.smoothScrollToPosition(0);
124 128
     }

+ 23 - 6
app/src/main/java/ai/pai/lensman/session/SessionInteractor.java

@@ -52,6 +52,7 @@ public class SessionInteractor {
52 52
     }
53 53
 
54 54
     public void startSession(){
55
+        LogHelper.d(TAG,"startSession");
55 56
         if(BuildConfig.isTestMode){
56 57
             isWorking = true;
57 58
             listener.onSessionStartSuccess(sessionBean.sessionId);
@@ -81,6 +82,7 @@ public class SessionInteractor {
81 82
 
82 83
             @Override
83 84
             protected void onPostFail() {
85
+                LogHelper.d(TAG,"sessionStartTask onPostFail sessionId = "+randomSessionId);
84 86
                 super.onPostFail();
85 87
                 listener.onSessionStartError(sessionBean.sessionId);
86 88
             }
@@ -90,10 +92,12 @@ public class SessionInteractor {
90 92
                 super.onPostSuccess();
91 93
                 listener.onSessionStartSuccess(sessionBean.sessionId);
92 94
                 isWorking = true;
95
+                LogHelper.d(TAG,"sessionStartTask onPostSuccess sessionId = "+randomSessionId + "and startCapture");
93 96
                 startCapture();
94 97
             }
95 98
         };
96 99
         sessionStartTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_START_URL);
100
+        LogHelper.d(TAG,"startSession sessionStartTask execute");
97 101
     }
98 102
 
99 103
     public void startCapture() {
@@ -107,13 +111,14 @@ public class SessionInteractor {
107 111
             public void run() {
108 112
                 fetchThumbnailTask();
109 113
             }
110
-        },1000,10000);
114
+        },1000,3000);
111 115
     }
112 116
 
113 117
     private void fetchThumbnailTask(){
114 118
         if(!isWorking){
115 119
             return;
116 120
         }
121
+
117 122
         if(BuildConfig.isTestMode){
118 123
             PhotoBean bean = new PhotoBean();
119 124
             long milisec = System.currentTimeMillis();
@@ -174,25 +179,29 @@ public class SessionInteractor {
174 179
                         return true;
175 180
                     }
176 181
                 }catch (Exception e){
177
-                    e.printStackTrace();
182
+                    LogHelper.e(TAG,"fetchThumbnailTask exception occurs "+e);
178 183
                 }
179 184
                 return false;
180 185
             }
181 186
 
182 187
             @Override
183 188
             protected void onPostFail() {
189
+                LogHelper.d(TAG,"fetchThumbnailTask onPostFail");
184 190
                 super.onPostFail();
185 191
             }
186 192
 
187 193
             @Override
188 194
             protected void onPostSuccess() {
189 195
                 super.onPostSuccess();
196
+                LogHelper.d(TAG,"fetchThumbnailTask onPostSuccess with photo number = "+photoList.size());
190 197
                 for(PhotoBean bean :photoList){
191 198
                     new SavePhotoTask(bean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),bean);
199
+                    LogHelper.d(TAG,"SavePhotoTask starts "+bean);
192 200
                 }
193 201
             }
194 202
         };
195 203
         fetchThumbnailTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_THUMBNAIL_URL);
204
+        LogHelper.d(TAG,"fetchThumbnailTask starts");
196 205
     }
197 206
 
198 207
 
@@ -210,7 +219,7 @@ public class SessionInteractor {
210 219
             if(BuildConfig.isTestMode){
211 220
                 path = photoBean.photoPath;
212 221
             }
213
-            LogHelper.d(TAG,"保存照片到本地,图片链接地址为"+path);
222
+            LogHelper.d(TAG,"SavePhotoTask save photo to phone , photo remote url = "+path);
214 223
             FileOutputStream fOut = null;
215 224
             HttpURLConnection conn = null;
216 225
             InputStream inStream = null;
@@ -233,11 +242,11 @@ public class SessionInteractor {
233 242
                         fOut.flush();
234 243
                     }
235 244
                     fOut.flush();
236
-                    LogHelper.d(TAG,"保存照片到本地,图片保存至"+file.getAbsolutePath()+"图片大小为"+file.length()+"字节\n\n");
245
+                    LogHelper.d(TAG,"SavePhotoTask save photo to local path = "+file.getAbsolutePath()+" photo bytes = "+file.length()+"\n");
237 246
                 }
238 247
                 return true;
239 248
             } catch (Exception e) {
240
-                e.printStackTrace();
249
+                LogHelper.e(TAG,"SavePhotoTask exception occurs "+e);
241 250
             } finally {
242 251
                 try{
243 252
                     inStream.close();
@@ -247,6 +256,11 @@ public class SessionInteractor {
247 256
                     e.printStackTrace();
248 257
                 }
249 258
             }
259
+            try{
260
+                Thread.sleep(2000);
261
+            }catch (Exception e){
262
+                e.printStackTrace();
263
+            }
250 264
             return false;
251 265
         }
252 266
 
@@ -254,8 +268,10 @@ public class SessionInteractor {
254 268
         protected void onPostExecute(Boolean result) {
255 269
             super.onPostExecute(result);
256 270
             if (result) {
271
+                LogHelper.d(TAG,"SavePhotoTask onPostExecute success " + photoBean);
257 272
                 listener.onSessionPhotoCaptured(photoBean);
258 273
             }else{
274
+                LogHelper.d(TAG,"SavePhotoTask onPostExecute fail and retry "+photoBean);
259 275
                 new SavePhotoTask(photoBean).executeOnExecutor(ThreadExecutor.getInstance().getExecutor(),photoBean);
260 276
             }
261 277
         }
@@ -275,7 +291,7 @@ public class SessionInteractor {
275 291
         params.put("session",randomSessionId);
276 292
         sessionEndTask = new HttpPostTask(params);
277 293
         sessionEndTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_END_URL);
278
-
294
+        LogHelper.d(TAG,"sessionEndTask execute ");
279 295
         listener.onSessionEnd(sessionBean.sessionId);
280 296
     }
281 297
 
@@ -288,6 +304,7 @@ public class SessionInteractor {
288 304
         params.put("path",photoBean.photoPath);
289 305
         HttpPostTask deleteTask = new HttpPostTask(params);
290 306
         deleteTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.DELETE_PHOTO_URL);
307
+        LogHelper.d(TAG,"deletePhoto execute "+photoBean);
291 308
     }
292 309
 
293 310
     private void cancelTask(HttpPostTask task){

+ 10 - 3
app/src/main/java/ai/pai/lensman/session/SessionPresenter.java

@@ -23,7 +23,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
23 23
     private SessionBean sessionBean;
24 24
     private boolean isWorking;
25 25
 
26
-
26
+    private static final String TAG = "SessionPresenter";
27 27
 
28 28
     public SessionPresenter(SessionBean sessionBean, SessionContract.View view) {
29 29
         this.sessionView = view;
@@ -32,11 +32,14 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
32 32
 
33 33
     @Override
34 34
     public void start() {
35
+        LogHelper.d(TAG,"SessionPresenter start "+sessionBean);
35 36
         interactor = new SessionInteractor(sessionBean, this);
36 37
         photoList = DBService.getInstance().getPhotoListBySessionId(sessionBean.sessionId);
37 38
         if (photoList.size() == 0) {
39
+            LogHelper.d(TAG,"SessionPresenter start and found no old photos");
38 40
             sessionView.showEmptyView();
39 41
         } else {
42
+            LogHelper.d(TAG,"SessionPresenter start and found  old photos, size = "+photoList.size());
40 43
             sessionView.showPhotoRecyclerView();
41 44
             for (PhotoBean photoBean : photoList) {
42 45
                 sessionView.addNewPhoto(photoBean);
@@ -51,12 +54,14 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
51 54
         interactor.endSession();
52 55
         Preferences.getInstance().setCurrentSession("");
53 56
         isWorking = false;
57
+        LogHelper.d(TAG,"stop");
54 58
     }
55 59
 
56 60
     @Override
57 61
     public void onSessionStartSuccess(String session) {
58 62
         isWorking = true;
59 63
         sessionView.showToast("session启动成功");
64
+        LogHelper.d(TAG,"onSessionStartSuccess session启动成功"+session);
60 65
     }
61 66
 
62 67
     @Override
@@ -66,6 +71,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
66 71
         }
67 72
         sessionView.showToast("session启动失败,自动重试中");
68 73
         interactor.startSession();
74
+        LogHelper.d(TAG,"onSessionStartError session启动失败,自动重试中");
69 75
     }
70 76
 
71 77
     @Override
@@ -78,6 +84,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
78 84
                 return;
79 85
             }
80 86
         }
87
+        LogHelper.d(TAG,"onSessionPhotoCaptured "+bean);
81 88
         DBService.getInstance().addPhotoBean(bean);
82 89
         sessionView.showPhotoRecyclerView();
83 90
         sessionView.addNewPhoto(bean);
@@ -87,7 +94,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
87 94
 
88 95
     @Override
89 96
     public void onSessionEnd(String session) {
90
-
97
+        LogHelper.d(TAG,"onSessionEnd "+session);
91 98
     }
92 99
 
93 100
     @Override
@@ -103,7 +110,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
103 110
 
104 111
     @Override
105 112
     public void change2QRCodeSessionId(String sessionId) {
106
-        LogHelper.d("czy","change2QRCodeSessionId ="+sessionId);
113
+        LogHelper.d(TAG,"change2QRCodeSessionId 使用新sessionId = "+sessionId);
107 114
         this.sessionBean.sessionId = sessionId;
108 115
         stop();
109 116
         start();