@@ -33,7 +33,7 @@ public class SessionActivity extends AppCompatActivity implements SessionContrac |
||
33 | 33 |
setContentView(R.layout.activity_session); |
34 | 34 |
ButterKnife.bind(this); |
35 | 35 |
sessionBean =(SessionBean)getIntent().getSerializableExtra("session"); |
36 |
- presenter = new SessionPresenterImpl(sessionBean.sessionId,this); |
|
36 |
+ presenter = new SessionPresenterImpl(this,sessionBean.sessionId,this); |
|
37 | 37 |
|
38 | 38 |
titleTextView.setText(getString(R.string.scene)+sessionBean.sessionSeq); |
39 | 39 |
adapter = new PhotoRecyclerAdapter(this); |
@@ -62,7 +62,7 @@ public class SessionActivity extends AppCompatActivity implements SessionContrac |
||
62 | 62 |
|
63 | 63 |
@OnClick(R.id.iv_qrcode) |
64 | 64 |
void showQRCodeForSession(){ |
65 |
- new SessionQRPopup(this, String.valueOf(sessionBean.sessionSeq)).showPopupWindow(); |
|
65 |
+ new SessionQRPopup(this, sessionBean.sessionId).showPopupWindow(); |
|
66 | 66 |
} |
67 | 67 |
|
68 | 68 |
@OnClick(R.id.title_bar_back_layout) |
@@ -117,5 +117,6 @@ public class SessionActivity extends AppCompatActivity implements SessionContrac |
||
117 | 117 |
return; |
118 | 118 |
} |
119 | 119 |
} |
120 |
+ |
|
120 | 121 |
} |
121 | 122 |
} |
@@ -1,16 +1,33 @@ |
||
1 | 1 |
package ai.pai.lensman.session; |
2 | 2 |
|
3 |
+import android.content.Context; |
|
4 |
+ |
|
5 |
+import java.util.List; |
|
6 |
+import java.util.Timer; |
|
7 |
+import java.util.TimerTask; |
|
8 |
+ |
|
9 |
+import ai.pai.lensman.box.ApiClient; |
|
10 |
+import ai.pai.lensman.db.Preferences; |
|
11 |
+import retrofit2.Call; |
|
12 |
+import retrofit2.Callback; |
|
13 |
+import retrofit2.Response; |
|
14 |
+ |
|
3 | 15 |
/** |
4 | 16 |
* Created by chengzhenyu on 2016/7/7. |
5 | 17 |
*/ |
6 | 18 |
public class SessionInteractor { |
7 | 19 |
|
20 |
+ private Context context; |
|
8 | 21 |
private String sessionId; |
22 |
+ private String lensmanId; |
|
23 |
+ private Timer timer; |
|
9 | 24 |
private SessionListener listener; |
10 | 25 |
|
11 |
- public SessionInteractor(String sessionId, SessionListener listener) { |
|
26 |
+ public SessionInteractor(Context context,String sessionId, SessionListener listener) { |
|
27 |
+ this.context = context; |
|
12 | 28 |
this.listener = listener; |
13 | 29 |
this.sessionId = sessionId; |
30 |
+ this.lensmanId = Preferences.getInstance(context).getLensManId(); |
|
14 | 31 |
} |
15 | 32 |
|
16 | 33 |
public interface SessionListener { |
@@ -22,14 +39,59 @@ public class SessionInteractor { |
||
22 | 39 |
} |
23 | 40 |
|
24 | 41 |
public void startSession(){ |
42 |
+ ApiClient.service.startNewSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
43 |
+ @Override |
|
44 |
+ public void onResponse(Call<String> call, Response<String> response) { |
|
45 |
+ listener.onSessionStartSuccess(sessionId); |
|
46 |
+ } |
|
25 | 47 |
|
48 |
+ @Override |
|
49 |
+ public void onFailure(Call<String> call, Throwable t) { |
|
50 |
+ listener.onSessionStartError(sessionId); |
|
51 |
+ } |
|
52 |
+ }); |
|
26 | 53 |
} |
27 | 54 |
|
28 | 55 |
public void startCapture() { |
56 |
+ if(timer!=null){ |
|
57 |
+ timer.cancel(); |
|
58 |
+ timer = null; |
|
59 |
+ } |
|
60 |
+ timer = new Timer(); |
|
61 |
+ timer.schedule(new TimerTask() { |
|
62 |
+ @Override |
|
63 |
+ public void run() { |
|
64 |
+ ApiClient.service.fetchSessionThumbnails(sessionId,lensmanId).enqueue(new Callback<List<PhotoBean>>() { |
|
65 |
+ @Override |
|
66 |
+ public void onResponse(Call<List<PhotoBean>> call, Response<List<PhotoBean>> response) { |
|
67 |
+ |
|
68 |
+ } |
|
69 |
+ |
|
70 |
+ @Override |
|
71 |
+ public void onFailure(Call<List<PhotoBean>> call, Throwable t) { |
|
72 |
+ |
|
73 |
+ } |
|
74 |
+ }); |
|
75 |
+ } |
|
76 |
+ },1000,1000); |
|
29 | 77 |
} |
30 | 78 |
|
31 | 79 |
public void endSession(){ |
80 |
+ if(timer!=null){ |
|
81 |
+ timer.cancel(); |
|
82 |
+ timer = null; |
|
83 |
+ } |
|
84 |
+ ApiClient.service.endSession(sessionId,lensmanId).enqueue(new Callback<String>() { |
|
85 |
+ @Override |
|
86 |
+ public void onResponse(Call<String> call, Response<String> response) { |
|
87 |
+ listener.onSessionEnd(sessionId); |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ @Override |
|
91 |
+ public void onFailure(Call<String> call, Throwable t) { |
|
32 | 92 |
|
93 |
+ } |
|
94 |
+ }); |
|
33 | 95 |
} |
34 | 96 |
|
35 | 97 |
} |
@@ -1,17 +1,21 @@ |
||
1 | 1 |
package ai.pai.lensman.session; |
2 | 2 |
|
3 |
+import android.content.Context; |
|
4 |
+ |
|
3 | 5 |
import java.util.ArrayList; |
4 | 6 |
|
5 | 7 |
public class SessionPresenterImpl implements SessionContract.SessionPresenter ,SessionInteractor.SessionListener{ |
6 | 8 |
|
9 |
+ private Context context; |
|
7 | 10 |
private SessionInteractor interactor; |
8 | 11 |
private ArrayList<PhotoBean> photoList; |
9 | 12 |
private SessionContract.SessionView sessionView; |
10 | 13 |
|
11 |
- public SessionPresenterImpl(String sessionId, SessionContract.SessionView view){ |
|
14 |
+ public SessionPresenterImpl(Context context,String sessionId, SessionContract.SessionView view){ |
|
15 |
+ this.context = context; |
|
12 | 16 |
this.sessionView = view; |
13 | 17 |
photoList = new ArrayList<>(); |
14 |
- interactor = new SessionInteractor(sessionId,this); |
|
18 |
+ interactor = new SessionInteractor(context,sessionId,this); |
|
15 | 19 |
} |
16 | 20 |
|
17 | 21 |
@Override |