d class="lines-num lines-num-old"> 34
void onSessionEnd(String session);
}
public void startSession(){
+ cancelTask(sessionStartTask);
+ HashMap<String,String> params = new HashMap<>();
+ params.put("lensman",lensmanId);
+ params.put("session",sessionId);
+ sessionStartTask = new HttpPostTask(params){
+ @Override
+ protected boolean parseResponse(String response) {
+ LogHelper.d(TAG,"startSession get response string = "+response);
+ try{
+ JSONObject json = new JSONObject(response);
+ int status = json.getInt("status");
+ if(status == 200){
+ return true;
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return false;
+ }
+ @Override
+ protected void onPostFail() {
+ super.onPostFail();
+ listener.onSessionStartError(sessionId);
+ }
+
+ @Override
+ protected void onPostSuccess() {
+ super.onPostSuccess();
+ listener.onSessionStartSuccess(sessionId);
+ startCapture();
+ }
+ };
+ sessionStartTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_START_URL);
}
public void startCapture() {
@@ -46,16 +93,85 @@ public class SessionInteractor {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
- public void run() {}
- },1000,1000);
+ public void run() {
+ fetchThumbnailTask();
+ }
+ },1000,5000);
+ }
+
+ private void fetchThumbnailTask(){
+ cancelTask(fetchThumbnailTask);
+ HashMap<String,String> params = new HashMap<>();
+ params.put("lensman",lensmanId);
+ params.put("session",sessionId);
+ fetchThumbnailTask = new HttpPostTask(params){
+ ArrayList<PhotoBean> photoList = new ArrayList<>();
+ @Override
+ protected boolean parseResponse(String response) {
+ LogHelper.d(TAG,"fetchThumbnailTask get response string = "+response);
+ try{
+ JSONObject json = new JSONObject(response);
+ int status = json.getInt("status");
+ if(status == 200){
+ JSONObject data = json.getJSONObject("data");
+ JSONArray files = data.getJSONArray("files");
+ if(files!=null && files.length()>0){
+ for(int k = 0 ; k< files.length();k++){
+ JSONObject file = files.getJSONObject(k);
+ PhotoBean bean = new PhotoBean();
+ bean.photoName = file.getString("name");
+ bean.photoId = file.getLong("id");
+ bean.photoPath = file.getString("path");
+ bean.captureTime = bean.photoId;
+ bean.isRawPhoto = false;
+ bean.isUploaded = false;
+ bean.sessionId = sessionId;
+ photoList.add(bean);
+ }
+ }
+ return true;
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ @Override
+ protected void onPostFail() {
+ super.onPostFail();
+ }
+
+ @Override
+ protected void onPostSuccess() {
+ super.onPostSuccess();
+ listener.onSessionPhotoCaptured(photoList);
+ }
+ };
+ fetchThumbnailTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.FETCH_THUMBNAIL_URL);
}
public void endSession(){
+ cancelTask(sessionEndTask);
+ HashMap<String,String> params = new HashMap<>();
+ params.put("lensman",lensmanId);
+ params.put("session",sessionId);
+ sessionEndTask = new HttpPostTask(params);
+ sessionEndTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SESSION_END_URL);
if(timer!=null){
timer.cancel();
timer = null;
}
+ listener.onSessionEnd(sessionId);
+ }
+ private void cancelTask(HttpPostTask task){
+ if(task==null){
+ return;
+ }
+ if(task.getStatus()== AsyncTask.Status.RUNNING){
+ task.cancel(true);
+ }
}
}
@@ -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 |