@@ -231,7 +231,6 @@ class MainPresenter implements MainContract.Presenter,BaseInteractor.InteractorL |
||
| 231 | 231 |
}else{
|
| 232 | 232 |
isBoxConnected = false; |
| 233 | 233 |
view.showBoxDisconnectedView(); |
| 234 |
- boxStatusInteractor.startJob(); |
|
| 235 | 234 |
} |
| 236 | 235 |
} |
| 237 | 236 |
|
@@ -7,6 +7,9 @@ import com.android.common.executors.ThreadExecutor; |
||
| 7 | 7 |
|
| 8 | 8 |
import org.json.JSONObject; |
| 9 | 9 |
|
| 10 |
+import java.util.Timer; |
|
| 11 |
+import java.util.TimerTask; |
|
| 12 |
+ |
|
| 10 | 13 |
import ai.pai.lensman.base.BaseInteractor; |
| 11 | 14 |
import ai.pai.lensman.utils.BoxUrlContainer; |
| 12 | 15 |
import ai.pai.lensman.utils.HttpPostTask; |
@@ -15,6 +18,7 @@ public class QueryBoxStatusInteractor implements BaseInteractor{
|
||
| 15 | 18 |
|
| 16 | 19 |
private HttpPostTask queryBoxTask; |
| 17 | 20 |
private BoxStatusListener listener; |
| 21 |
+ private Timer queryTimer; |
|
| 18 | 22 |
|
| 19 | 23 |
public QueryBoxStatusInteractor(BoxStatusListener listener){
|
| 20 | 24 |
this.listener = listener; |
@@ -23,6 +27,17 @@ public class QueryBoxStatusInteractor implements BaseInteractor{
|
||
| 23 | 27 |
@Override |
| 24 | 28 |
public void startJob() {
|
| 25 | 29 |
cancelJob(); |
| 30 |
+ queryTimer = new Timer(); |
|
| 31 |
+ queryTimer.schedule(new TimerTask() {
|
|
| 32 |
+ @Override |
|
| 33 |
+ public void run() {
|
|
| 34 |
+ queryBoxStatus(); |
|
| 35 |
+ } |
|
| 36 |
+ },100,6000); |
|
| 37 |
+ |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ private void queryBoxStatus(){
|
|
| 26 | 41 |
queryBoxTask = new HttpPostTask(null){
|
| 27 | 42 |
|
| 28 | 43 |
String boxStatusNum; |
@@ -64,6 +79,10 @@ public class QueryBoxStatusInteractor implements BaseInteractor{
|
||
| 64 | 79 |
|
| 65 | 80 |
@Override |
| 66 | 81 |
public void cancelJob() {
|
| 82 |
+ if(queryTimer!=null){
|
|
| 83 |
+ queryTimer.cancel(); |
|
| 84 |
+ queryTimer = null; |
|
| 85 |
+ } |
|
| 67 | 86 |
if(queryBoxTask==null){
|
| 68 | 87 |
return; |
| 69 | 88 |
} |
@@ -13,6 +13,7 @@ import android.widget.TextView; |
||
| 13 | 13 |
import android.widget.Toast; |
| 14 | 14 |
|
| 15 | 15 |
import com.android.common.utils.LogHelper; |
| 16 |
+import com.android.common.utils.NetworkUtil; |
|
| 16 | 17 |
|
| 17 | 18 |
import ai.pai.lensman.R; |
| 18 | 19 |
import ai.pai.lensman.base.BaseActivity; |
@@ -147,6 +148,16 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
| 147 | 148 |
} |
| 148 | 149 |
|
| 149 | 150 |
@Override |
| 151 |
+ public void showBoxDisconnectedView() {
|
|
| 152 |
+ Toast.makeText(this,NetworkUtil.isWifiConnected(this) ? R.string.box_status_error : R.string.network_disconnect,Toast.LENGTH_SHORT).show(); |
|
| 153 |
+ } |
|
| 154 |
+ |
|
| 155 |
+ @Override |
|
| 156 |
+ public void showBoxConnectedView() {
|
|
| 157 |
+ |
|
| 158 |
+ } |
|
| 159 |
+ |
|
| 160 |
+ @Override |
|
| 150 | 161 |
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
| 151 | 162 |
super.onActivityResult(requestCode,resultCode,data); |
| 152 | 163 |
if (resultCode == Activity.RESULT_OK) {
|
@@ -14,6 +14,8 @@ public class SessionContract {
|
||
| 14 | 14 |
void showPhotoRecyclerView(); |
| 15 | 15 |
void showEmptyView(); |
| 16 | 16 |
void showToast(String toast); |
| 17 |
+ void showBoxDisconnectedView(); |
|
| 18 |
+ void showBoxConnectedView(); |
|
| 17 | 19 |
} |
| 18 | 20 |
|
| 19 | 21 |
interface Presenter extends BasePresenter{
|
@@ -12,12 +12,15 @@ import ai.pai.lensman.bean.PhotoBean; |
||
| 12 | 12 |
import ai.pai.lensman.bean.SessionBean; |
| 13 | 13 |
import ai.pai.lensman.db.DBService; |
| 14 | 14 |
import ai.pai.lensman.db.Preferences; |
| 15 |
+import ai.pai.lensman.main.QueryBoxStatusInteractor; |
|
| 15 | 16 |
import ai.pai.lensman.service.UploadService; |
| 16 | 17 |
|
| 17 | 18 |
|
| 18 |
-public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener {
|
|
| 19 |
+public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener, |
|
| 20 |
+ QueryBoxStatusInteractor.BoxStatusListener {
|
|
| 19 | 21 |
|
| 20 | 22 |
private SessionInteractor interactor; |
| 23 |
+ private QueryBoxStatusInteractor boxStatusInteractor; |
|
| 21 | 24 |
private ArrayList<PhotoBean> photoList; |
| 22 | 25 |
private SessionContract.View sessionView; |
| 23 | 26 |
private SessionBean sessionBean; |
@@ -34,6 +37,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
| 34 | 37 |
public void start() {
|
| 35 | 38 |
LogHelper.d(TAG,"SessionPresenter start "+sessionBean); |
| 36 | 39 |
interactor = new SessionInteractor(sessionBean, this); |
| 40 |
+ boxStatusInteractor = new QueryBoxStatusInteractor(this); |
|
| 37 | 41 |
photoList = DBService.getInstance().getPhotoListBySessionId(sessionBean.sessionId); |
| 38 | 42 |
if (photoList.size() == 0) {
|
| 39 | 43 |
LogHelper.d(TAG,"SessionPresenter start and found no old photos"); |
@@ -46,11 +50,13 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
| 46 | 50 |
} |
| 47 | 51 |
} |
| 48 | 52 |
interactor.startSession(); |
| 53 |
+ boxStatusInteractor.startJob(); |
|
| 49 | 54 |
Preferences.getInstance().setCurrentSession(sessionBean.sessionId); |
| 50 | 55 |
} |
| 51 | 56 |
|
| 52 | 57 |
@Override |
| 53 | 58 |
public void stop() {
|
| 59 |
+ boxStatusInteractor.cancelJob(); |
|
| 54 | 60 |
interactor.endSession(); |
| 55 | 61 |
Preferences.getInstance().setCurrentSession("");
|
| 56 | 62 |
isWorking = false; |
@@ -116,4 +122,13 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
| 116 | 122 |
start(); |
| 117 | 123 |
} |
| 118 | 124 |
|
| 125 |
+ @Override |
|
| 126 |
+ public void onBoxStatusFetched(String boxNo, String boxStatus, String boxStatusCode) {
|
|
| 127 |
+ LogHelper.d(TAG,"onBoxStatusFetched 盒子当前状态 "+boxStatus+" code = "+boxStatusCode); |
|
| 128 |
+ if("0".equals(boxStatusCode)){
|
|
| 129 |
+ sessionView.showBoxConnectedView(); |
|
| 130 |
+ }else{
|
|
| 131 |
+ sessionView.showBoxDisconnectedView(); |
|
| 132 |
+ } |
|
| 133 |
+ } |
|
| 119 | 134 |
} |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 |
<string name="qr_scan_flash_off">关灯</string> |
| 37 | 37 |
|
| 38 | 38 |
<string name="scan_qr_join_group">扫描二维码获取照片</string> |
| 39 |
- <string name="check_permission_when_open_camera_error">相机打开出错,请检查是否已打开应用的相机权限</string> |
|
| 39 |
+ <string name="check_permission_when_open_camera_error">相机打开出错,请检查是否已允许拍爱的相机权限</string> |
|
| 40 | 40 |
|
| 41 | 41 |
<string name="ok">确定</string> |
| 42 | 42 |
|
@@ -157,4 +157,6 @@ |
||
| 157 | 157 |
<string name="set_price_success">价格设置成功</string> |
| 158 | 158 |
|
| 159 | 159 |
<string name="set_price_fail">价格设置失败,请重试</string> |
| 160 |
+ |
|
| 161 |
+ <string name="box_status_error">盒子状态错误,请检查或直接重启盒子</string> |
|
| 160 | 162 |
</resources> |