@@ -9,7 +9,7 @@ public class SessionBean implements Serializable{ |
||
9 | 9 |
|
10 | 10 |
public int sessionSeq; |
11 | 11 |
public long sessionDate; |
12 |
- public String sessionId; |
|
12 |
+ public String sessionId ="chengzhenyu_test"; |
|
13 | 13 |
public ArrayList<PhotoBean> sessionPhotos; |
14 | 14 |
|
15 | 15 |
} |
@@ -2,7 +2,7 @@ package ai.pai.lensman.box; |
||
2 | 2 |
|
3 | 3 |
public final class BoxUrlContainer { |
4 | 4 |
|
5 |
- private static final String BASE_URL = " http://120.27.44.52:8001/"; |
|
5 |
+ private static final String BASE_URL = "http://192.168.1.190:8002/"; |
|
6 | 6 |
|
7 | 7 |
public static final String SESSION_START_URL = BASE_URL+"session_start"; |
8 | 8 |
|
@@ -14,6 +14,7 @@ public class UploadService extends IntentService { |
||
14 | 14 |
@Override |
15 | 15 |
protected void onHandleIntent(Intent intent) { |
16 | 16 |
|
17 |
+ |
|
17 | 18 |
} |
18 | 19 |
|
19 | 20 |
} |
@@ -5,21 +5,23 @@ import android.content.Intent; |
||
5 | 5 |
import android.os.Bundle; |
6 | 6 |
import android.support.v7.widget.LinearLayoutManager; |
7 | 7 |
import android.support.v7.widget.RecyclerView; |
8 |
+import android.view.View; |
|
8 | 9 |
import android.widget.TextView; |
10 |
+import android.widget.Toast; |
|
9 | 11 |
|
10 | 12 |
import ai.pai.lensman.R; |
11 | 13 |
import ai.pai.lensman.base.BaseActivity; |
12 | 14 |
import ai.pai.lensman.bean.PhotoBean; |
13 |
-import ai.pai.lensman.qrcode.QRCaptureActivity; |
|
14 | 15 |
import ai.pai.lensman.bean.SessionBean; |
16 |
+import ai.pai.lensman.db.Preferences; |
|
17 |
+import ai.pai.lensman.qrcode.QRCaptureActivity; |
|
15 | 18 |
import butterknife.BindView; |
16 | 19 |
import butterknife.ButterKnife; |
17 | 20 |
import butterknife.OnClick; |
18 | 21 |
|
19 | 22 |
public class SessionActivity extends BaseActivity implements SessionContract.View { |
20 | 23 |
|
21 |
- @BindView(R.id.icon_no_data) |
|
22 |
- android.view.View noPhotoLayout; |
|
24 |
+ @BindView(R.id.icon_no_data) View noPhotoLayout; |
|
23 | 25 |
@BindView(R.id.title_bar_middle_txt) TextView titleTextView; |
24 | 26 |
@BindView(R.id.recycler_view_photos) RecyclerView photosRecyclerView; |
25 | 27 |
private PhotoRecyclerAdapter adapter; |
@@ -34,7 +36,8 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
34 | 36 |
setContentView(R.layout.activity_session); |
35 | 37 |
ButterKnife.bind(this); |
36 | 38 |
sessionBean =(SessionBean)getIntent().getSerializableExtra("session"); |
37 |
- presenter = new SessionPresenter(this,sessionBean.sessionId,this); |
|
39 |
+ String lensmanId = Preferences.getInstance(this).getLensManId(); |
|
40 |
+ presenter = new SessionPresenter(lensmanId,sessionBean.sessionId,this); |
|
38 | 41 |
|
39 | 42 |
titleTextView.setText(getString(R.string.scene)+sessionBean.sessionSeq); |
40 | 43 |
adapter = new PhotoRecyclerAdapter(this); |
@@ -77,37 +80,26 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
77 | 80 |
} |
78 | 81 |
|
79 | 82 |
@Override |
80 |
- public void addNewPhoto(final PhotoBean bean) { |
|
81 |
- runOnUiThread(new Runnable() { |
|
82 |
- @Override |
|
83 |
- public void run() { |
|
84 |
- adapter.addPhotoBean(bean); |
|
85 |
- photosRecyclerView.smoothScrollToPosition(0); |
|
86 |
- } |
|
87 |
- }); |
|
88 |
- |
|
83 |
+ public synchronized void addNewPhoto(final PhotoBean bean) { |
|
84 |
+ adapter.addPhotoBean(bean); |
|
85 |
+ photosRecyclerView.smoothScrollToPosition(0); |
|
89 | 86 |
} |
90 | 87 |
|
91 | 88 |
@Override |
92 | 89 |
public void showPhotoRecyclerView() { |
93 |
- runOnUiThread(new Runnable() { |
|
94 |
- @Override |
|
95 |
- public void run() { |
|
96 |
- noPhotoLayout.setVisibility(android.view.View.GONE); |
|
97 |
- photosRecyclerView.setVisibility(android.view.View.VISIBLE); |
|
98 |
- } |
|
99 |
- }); |
|
90 |
+ noPhotoLayout.setVisibility(android.view.View.GONE); |
|
91 |
+ photosRecyclerView.setVisibility(android.view.View.VISIBLE); |
|
100 | 92 |
} |
101 | 93 |
|
102 | 94 |
@Override |
103 | 95 |
public void showEmptyView() { |
104 |
- runOnUiThread(new Runnable() { |
|
105 |
- @Override |
|
106 |
- public void run() { |
|
107 |
- photosRecyclerView.setVisibility(android.view.View.GONE); |
|
108 |
- noPhotoLayout.setVisibility(android.view.View.VISIBLE); |
|
109 |
- } |
|
110 |
- }); |
|
96 |
+ photosRecyclerView.setVisibility(android.view.View.GONE); |
|
97 |
+ noPhotoLayout.setVisibility(android.view.View.VISIBLE); |
|
98 |
+ } |
|
99 |
+ |
|
100 |
+ @Override |
|
101 |
+ public void showToast(String toast) { |
|
102 |
+ Toast.makeText(this,toast,Toast.LENGTH_SHORT).show(); |
|
111 | 103 |
} |
112 | 104 |
|
113 | 105 |
@Override |
@@ -118,7 +110,6 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
118 | 110 |
return; |
119 | 111 |
} |
120 | 112 |
} |
121 |
- |
|
122 | 113 |
} |
123 | 114 |
|
124 | 115 |
} |
@@ -13,6 +13,7 @@ public class SessionContract { |
||
13 | 13 |
void addNewPhoto(PhotoBean bean); |
14 | 14 |
void showPhotoRecyclerView(); |
15 | 15 |
void showEmptyView(); |
16 |
+ void showToast(String toast); |
|
16 | 17 |
} |
17 | 18 |
|
18 | 19 |
interface Presenter extends BasePresenter{ |
@@ -1,41 +1,88 @@ |
||
1 | 1 |
package ai.pai.lensman.session; |
2 | 2 |
|
3 |
-import android.content.Context; |
|
3 |
+import android.os.AsyncTask; |
|
4 | 4 |
|
5 |
+import com.android.common.executors.ThreadExecutor; |
|
6 |
+import com.android.common.utils.LogHelper; |
|
7 |
+ |
|
8 |
+import org.json.JSONArray; |
|
9 |
+import org.json.JSONObject; |
|
10 |
+ |
|
11 |
+import java.util.ArrayList; |
|
12 |
+import java.util.HashMap; |
|
5 | 13 |
import java.util.Timer; |
6 | 14 |
import java.util.TimerTask; |
7 | 15 |
|
8 | 16 |
import ai.pai.lensman.bean.PhotoBean; |
9 |
-import ai.pai.lensman.db.Preferences; |
|
17 |
+import ai.pai.lensman.box.BoxUrlContainer; |
|
18 |
+import ai.pai.lensman.utils.HttpPostTask; |
|
10 | 19 |
|
11 | 20 |
/** |
12 | 21 |
* Created by chengzhenyu on 2016/7/7. |
13 | 22 |
*/ |
14 | 23 |
public class SessionInteractor { |
15 | 24 |
|
16 |
- private Context context; |
|
17 | 25 |
private String sessionId; |
18 | 26 |
private String lensmanId; |
19 | 27 |
private Timer timer; |
20 | 28 |
private SessionListener listener; |
29 |
+ private HttpPostTask sessionStartTask; |
|
30 |
+ private HttpPostTask sessionEndTask; |
|
31 |
+ private HttpPostTask fetchThumbnailTask; |
|
32 |
+ private HttpPostTask fetchOriginTask; |
|
33 |
+ |
|
34 |
+ private static final String TAG = "SessionInteractor"; |
|
21 | 35 |
|
22 |
- public SessionInteractor(Context context,String sessionId, SessionListener listener) { |
|
23 |
- this.context = context; |
|
36 |
+ public SessionInteractor(String lensmanId,String sessionId, SessionListener listener) { |
|
37 |
+ this.lensmanId = lensmanId; |
|
24 | 38 |
this.listener = listener; |
25 | 39 |
this.sessionId = sessionId; |
26 |
- this.lensmanId = Preferences.getInstance(context).getLensManId(); |
|
40 |
+ |
|
27 | 41 |
} |
28 | 42 |
|
29 | 43 |
public interface SessionListener { |
30 | 44 |
|
31 | 45 |
void onSessionStartSuccess(String session); |
32 | 46 |
void onSessionStartError(String session); |
33 |
- void onSessionPhotoCaptured(PhotoBean bean); |
|
47 |
+ void onSessionPhotoCaptured(ArrayList<PhotoBean> bean); |
|
34 | 48 |
void onSessionEnd(String session); |
35 | 49 |
} |
36 | 50 |
|
37 | 51 |
public void startSession(){ |
52 |
+ cancelTask(sessionStartTask); |
|
53 |
+ HashMap<String,String> params = new HashMap<>(); |
|
54 |
+ params.put("lensman",lensmanId); |
|
55 |
+ params.put("session",sessionId); |
|
56 |
+ sessionStartTask = new HttpPostTask(params){ |
|
57 |
+ @Override |
|
58 |
+ protected boolean parseResponse(String response) { |
|
59 |
+ LogHelper.d(TAG,"startSession get response string = "+response); |
|
60 |
+ try{ |
|
61 |
+ JSONObject json = new JSONObject(response); |
|
62 |
+ int status = json.getInt("status"); |
|
63 |
+ if(status == 200){ |
|
64 |
+ return true; |
|
65 |
+ } |
|
66 |
+ }catch (Exception e){ |
|
67 |
+ e.printStackTrace(); |
|
68 |
+ } |
|
69 |
+ return false; |
|
70 |
+ } |
|
38 | 71 |
|
72 |
+ @Override |
|
73 |
+ protected void onPostFail() { |
|
74 |
+ super.onPostFail(); |
|
75 |
+ listener.onSessionStartError(sessionId); |
|
76 |
+ } |
|
77 |
+ |
|
78 |
+ @Override |
|
79 |
+ protected void onPostSuccess() { |
|
80 |
+ super.onPostSuccess(); |
|
81 |
+ listener.onSessionStartSuccess(sessionId); |
|
82 |
+ startCapture(); |
|
83 |
+ } |
|
84 |
+ }; |
|
85 |
+ sessionStartTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_START_URL); |
|
39 | 86 |
} |
40 | 87 |
|
41 | 88 |
public void startCapture() { |
@@ -46,16 +93,85 @@ public class SessionInteractor { |
||
46 | 93 |
timer = new Timer(); |
47 | 94 |
timer.schedule(new TimerTask() { |
48 | 95 |
@Override |
49 |
- public void run() {} |
|
50 |
- },1000,1000); |
|
96 |
+ public void run() { |
|
97 |
+ fetchThumbnailTask(); |
|
98 |
+ } |
|
99 |
+ },1000,5000); |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ private void fetchThumbnailTask(){ |
|
103 |
+ cancelTask(fetchThumbnailTask); |
|
104 |
+ HashMap<String,String> params = new HashMap<>(); |
|
105 |
+ params.put("lensman",lensmanId); |
|
106 |
+ params.put("session",sessionId); |
|
107 |
+ fetchThumbnailTask = new HttpPostTask(params){ |
|
108 |
+ ArrayList<PhotoBean> photoList = new ArrayList<>(); |
|
109 |
+ @Override |
|
110 |
+ protected boolean parseResponse(String response) { |
|
111 |
+ LogHelper.d(TAG,"fetchThumbnailTask get response string = "+response); |
|
112 |
+ try{ |
|
113 |
+ JSONObject json = new JSONObject(response); |
|
114 |
+ int status = json.getInt("status"); |
|
115 |
+ if(status == 200){ |
|
116 |
+ JSONObject data = json.getJSONObject("data"); |
|
117 |
+ JSONArray files = data.getJSONArray("files"); |
|
118 |
+ if(files!=null && files.length()>0){ |
|
119 |
+ for(int k = 0 ; k< files.length();k++){ |
|
120 |
+ JSONObject file = files.getJSONObject(k); |
|
121 |
+ PhotoBean bean = new PhotoBean(); |
|
122 |
+ bean.photoName = file.getString("name"); |
|
123 |
+ bean.photoId = file.getLong("id"); |
|
124 |
+ bean.photoPath = file.getString("path"); |
|
125 |
+ bean.captureTime = bean.photoId; |
|
126 |
+ bean.isRawPhoto = false; |
|
127 |
+ bean.isUploaded = false; |
|
128 |
+ bean.sessionId = sessionId; |
|
129 |
+ photoList.add(bean); |
|
130 |
+ } |
|
131 |
+ } |
|
132 |
+ return true; |
|
133 |
+ } |
|
134 |
+ }catch (Exception e){ |
|
135 |
+ e.printStackTrace(); |
|
136 |
+ } |
|
137 |
+ return false; |
|
138 |
+ } |
|
139 |
+ |
|
140 |
+ @Override |
|
141 |
+ protected void onPostFail() { |
|
142 |
+ super.onPostFail(); |
|
143 |
+ } |
|
144 |
+ |
|
145 |
+ @Override |
|
146 |
+ protected void onPostSuccess() { |
|
147 |
+ super.onPostSuccess(); |
|
148 |
+ listener.onSessionPhotoCaptured(photoList); |
|
149 |
+ } |
|
150 |
+ }; |
|
151 |
+ fetchThumbnailTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_THUMBNAIL_URL); |
|
51 | 152 |
} |
52 | 153 |
|
53 | 154 |
public void endSession(){ |
155 |
+ cancelTask(sessionEndTask); |
|
156 |
+ HashMap<String,String> params = new HashMap<>(); |
|
157 |
+ params.put("lensman",lensmanId); |
|
158 |
+ params.put("session",sessionId); |
|
159 |
+ sessionEndTask = new HttpPostTask(params); |
|
160 |
+ sessionEndTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_END_URL); |
|
54 | 161 |
if(timer!=null){ |
55 | 162 |
timer.cancel(); |
56 | 163 |
timer = null; |
57 | 164 |
} |
165 |
+ listener.onSessionEnd(sessionId); |
|
166 |
+ } |
|
58 | 167 |
|
168 |
+ private void cancelTask(HttpPostTask task){ |
|
169 |
+ if(task==null){ |
|
170 |
+ return; |
|
171 |
+ } |
|
172 |
+ if(task.getStatus()== AsyncTask.Status.RUNNING){ |
|
173 |
+ task.cancel(true); |
|
174 |
+ } |
|
59 | 175 |
} |
60 | 176 |
|
61 | 177 |
} |
@@ -1,23 +1,19 @@ |
||
1 | 1 |
package ai.pai.lensman.session; |
2 | 2 |
|
3 |
-import android.content.Context; |
|
4 |
- |
|
5 | 3 |
import java.util.ArrayList; |
6 | 4 |
|
7 | 5 |
import ai.pai.lensman.bean.PhotoBean; |
8 | 6 |
|
9 | 7 |
public class SessionPresenter implements SessionContract.Presenter,SessionInteractor.SessionListener{ |
10 | 8 |
|
11 |
- private Context context; |
|
12 | 9 |
private SessionInteractor interactor; |
13 | 10 |
private ArrayList<PhotoBean> photoList; |
14 | 11 |
private SessionContract.View sessionView; |
15 | 12 |
|
16 |
- public SessionPresenter(Context context, String sessionId, SessionContract.View view){ |
|
17 |
- this.context = context; |
|
13 |
+ public SessionPresenter(String lensmanId, String sessionId, SessionContract.View view){ |
|
18 | 14 |
this.sessionView = view; |
19 | 15 |
photoList = new ArrayList<>(); |
20 |
- interactor = new SessionInteractor(context,sessionId,this); |
|
16 |
+ interactor = new SessionInteractor(lensmanId,sessionId,this); |
|
21 | 17 |
} |
22 | 18 |
|
23 | 19 |
@Override |
@@ -37,18 +33,21 @@ public class SessionPresenter implements SessionContract.Presenter,SessionIntera |
||
37 | 33 |
|
38 | 34 |
@Override |
39 | 35 |
public void onSessionStartSuccess(String session) { |
40 |
- |
|
36 |
+ sessionView.showToast("session启动成功"); |
|
41 | 37 |
} |
42 | 38 |
|
43 | 39 |
@Override |
44 | 40 |
public void onSessionStartError(String session) { |
45 |
- |
|
41 |
+ sessionView.showToast("session启动失败"); |
|
46 | 42 |
} |
47 | 43 |
|
48 | 44 |
@Override |
49 |
- public void onSessionPhotoCaptured(final PhotoBean bean) { |
|
45 |
+ public void onSessionPhotoCaptured(final ArrayList<PhotoBean> beans) { |
|
50 | 46 |
sessionView.showPhotoRecyclerView(); |
51 |
- sessionView.addNewPhoto(bean); |
|
47 |
+ sessionView.showToast("发现新增照片"+beans.size()+"张"); |
|
48 |
+ for (PhotoBean bean : beans){ |
|
49 |
+ sessionView.addNewPhoto(bean); |
|
50 |
+ } |
|
52 | 51 |
} |
53 | 52 |
|
54 | 53 |
@Override |