+public class SplashPresenter implements SplashContract.Presenter {
+
+ private Context context;
+ private SplashContract.View view;
+ private Handler mHandler;
+ private static final int NORMAL_DELAY_TIME = 1500;
+
+ public SplashPresenter(Context context, SplashContract.View view){
+ this.view = view;
+ this.context = context;
+ mHandler = new Handler();
+ }
+
+ @Override
+ public void start() {
+ if(TextUtils.isEmpty(Preferences.getInstance(context).getLensManId())){
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ view.jump2Login();
+ }
+ }, NORMAL_DELAY_TIME);
+ return;
+ }
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ view.jump2Main();
+ }
+ }, NORMAL_DELAY_TIME);
+ String curDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+ if(Preferences.getInstance(context).getLastRunDate().equals(curDate)){
+ return;
+ }
+// checkUpdate();
+ Preferences.getInstance(context).setLastRunDate(curDate);
+ }
+
+ @Override
+ public void stop() {
+ mHandler.removeCallbacksAndMessages(null);
+ }
+
+ private void checkUpdate() {
+ if(NetworkUtil.isWifiConnected(context)){
+ Intent intent = new Intent(context, UpgradeService.class);
+ context.startService(intent);
+ }
+ }
+
+}
@@ -0,0 +1,91 @@ |
||
| 1 |
+package ai.pai.lensman.upload; |
|
| 2 |
+ |
|
| 3 |
+import android.os.AsyncTask; |
|
| 4 |
+ |
|
| 5 |
+import com.android.common.executors.ThreadExecutor; |
|
| 6 |
+ |
|
| 7 |
+import org.json.JSONArray; |
|
| 8 |
+import org.json.JSONObject; |
|
| 9 |
+ |
|
| 10 |
+import java.util.ArrayList; |
|
| 11 |
+import java.util.HashMap; |
|
| 12 |
+ |
|
| 13 |
+import ai.pai.lensman.base.BaseInteractor; |
|
| 14 |
+import ai.pai.lensman.utils.HttpPostTask; |
|
| 15 |
+import ai.pai.lensman.utils.UrlContainer; |
|
| 16 |
+ |
|
| 17 |
+/** |
|
| 18 |
+ * Created by chengzhenyu on 2016/8/14. |
|
| 19 |
+ */ |
|
| 20 |
+public class FetchSessionIdsInteractor implements BaseInteractor {
|
|
| 21 |
+ |
|
| 22 |
+ private HttpPostTask fetchSessionIdsTask; |
|
| 23 |
+ private String lensmanId; |
|
| 24 |
+ private int num; |
|
| 25 |
+ private InteractorListener<ArrayList<String>> listener; |
|
| 26 |
+ |
|
| 27 |
+ public FetchSessionIdsInteractor(String lensmanId, int num, InteractorListener<ArrayList<String>> listener){
|
|
| 28 |
+ this.num = num; |
|
| 29 |
+ this.listener = listener; |
|
| 30 |
+ this.lensmanId = lensmanId; |
|
| 31 |
+ } |
|
| 32 |
+ |
|
| 33 |
+ @Override |
|
| 34 |
+ public void startJob() {
|
|
| 35 |
+ cancelJob(); |
|
| 36 |
+ HashMap<String,String> params = new HashMap<>(); |
|
| 37 |
+ params.put("user_id",lensmanId);
|
|
| 38 |
+ params.put("num",String.valueOf(num));
|
|
| 39 |
+ fetchSessionIdsTask = new HttpPostTask(params){
|
|
| 40 |
+ |
|
| 41 |
+ String message; |
|
| 42 |
+ ArrayList<String> sessionIds; |
|
| 43 |
+ @Override |
|
| 44 |
+ protected boolean parseResponse(String response) {
|
|
| 45 |
+ try{
|
|
| 46 |
+ JSONObject json = new JSONObject(response); |
|
| 47 |
+ int status = json.getInt("status");
|
|
| 48 |
+ if(status == 200){
|
|
| 49 |
+ JSONArray sessionArray = json.getJSONArray("data");
|
|
| 50 |
+ if(sessionArray!=null && sessionArray.length()>0){
|
|
| 51 |
+ sessionIds = new ArrayList<>(); |
|
| 52 |
+ for(int k = 0; k< sessionArray.length();k++){
|
|
| 53 |
+ sessionIds.add(sessionArray.getString(k)); |
|
| 54 |
+ } |
|
| 55 |
+ } |
|
| 56 |
+ return true; |
|
| 57 |
+ }else{
|
|
| 58 |
+ message = json.getString("message");
|
|
| 59 |
+ } |
|
| 60 |
+ }catch (Exception e){
|
|
| 61 |
+ e.printStackTrace(); |
|
| 62 |
+ } |
|
| 63 |
+ return false; |
|
| 64 |
+ } |
|
| 65 |
+ |
|
| 66 |
+ @Override |
|
| 67 |
+ protected void onPostFail() {
|
|
| 68 |
+ super.onPostFail(); |
|
| 69 |
+ listener.onInteractFail(message); |
|
| 70 |
+ } |
|
| 71 |
+ |
|
| 72 |
+ @Override |
|
| 73 |
+ protected void onPostSuccess() {
|
|
| 74 |
+ super.onPostSuccess(); |
|
| 75 |
+ listener.onInteractSuccess(sessionIds); |
|
| 76 |
+ } |
|
| 77 |
+ }; |
|
| 78 |
+ fetchSessionIdsTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.SESSION_IDS_CREATE); |
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ @Override |
|
| 82 |
+ public void cancelJob() {
|
|
| 83 |
+ if(fetchSessionIdsTask==null){
|
|
| 84 |
+ return; |
|
| 85 |
+ } |
|
| 86 |
+ if(fetchSessionIdsTask.getStatus()== AsyncTask.Status.RUNNING){
|
|
| 87 |
+ fetchSessionIdsTask.cancel(true); |
|
| 88 |
+ } |
|
| 89 |
+ fetchSessionIdsTask = null; |
|
| 90 |
+ } |
|
| 91 |
+} |
@@ -25,6 +25,7 @@ public class UploadActivity extends BaseActivity implements UploadContract.View |
||
| 25 | 25 |
@BindView(R.id.tv_box_status) TextView boxStatusTextView; |
| 26 | 26 |
@BindView(R.id.iv_box_status) ImageView boxStatusImageView; |
| 27 | 27 |
@BindView(R.id.icon_no_data) android.view.View noDataLayout; |
| 28 |
+ @BindView(R.id.iv_add_session) ImageView addSessionBtn; |
|
| 28 | 29 |
@BindView(R.id.recycler_view_sessions) RecyclerView sessionsRecyclerView; |
| 29 | 30 |
private SessionRecyclerAdapter adapter; |
| 30 | 31 |
private UploadContract.Presenter presenter; |
@@ -69,7 +70,6 @@ public class UploadActivity extends BaseActivity implements UploadContract.View |
||
| 69 | 70 |
|
| 70 | 71 |
} |
| 71 | 72 |
|
| 72 |
- |
|
| 73 | 73 |
@Override |
| 74 | 74 |
public void showBoxDisconnectedView() {
|
| 75 | 75 |
boxStatusTextView.setText(R.string.bt_disconnected); |
@@ -106,6 +106,11 @@ public class UploadActivity extends BaseActivity implements UploadContract.View |
||
| 106 | 106 |
adapter.addSessionBeans(sessionList); |
| 107 | 107 |
} |
| 108 | 108 |
|
| 109 |
+ @Override |
|
| 110 |
+ public void setNewSessionBtnEnabled(boolean isEnabled) {
|
|
| 111 |
+ addSessionBtn.setEnabled(isEnabled); |
|
| 112 |
+ } |
|
| 113 |
+ |
|
| 109 | 114 |
|
| 110 | 115 |
private void jumpToSelectedSession(SessionBean sessionBean) {
|
| 111 | 116 |
Intent intent = new Intent(this, SessionActivity.class); |
@@ -16,6 +16,7 @@ public class UploadContract {
|
||
| 16 | 16 |
void showSessionViews(); |
| 17 | 17 |
void updateSessionUploadView(SessionBean bean); |
| 18 | 18 |
void refreshSessionViews(ArrayList<SessionBean> sessionList); |
| 19 |
+ void setNewSessionBtnEnabled(boolean isEnabled); |
|
| 19 | 20 |
} |
| 20 | 21 |
|
| 21 | 22 |
interface Presenter extends BasePresenter{
|
@@ -4,24 +4,37 @@ import java.text.SimpleDateFormat; |
||
| 4 | 4 |
import java.util.ArrayList; |
| 5 | 5 |
import java.util.Date; |
| 6 | 6 |
|
| 7 |
+import ai.pai.lensman.base.BaseInteractor; |
|
| 7 | 8 |
import ai.pai.lensman.bean.SessionBean; |
| 8 | 9 |
import ai.pai.lensman.db.DBService; |
| 9 | 10 |
|
| 10 |
-public class UploadPresenter implements UploadContract.Presenter {
|
|
| 11 |
+public class UploadPresenter implements UploadContract.Presenter,BaseInteractor.InteractorListener<ArrayList<String>> {
|
|
| 11 | 12 |
|
| 12 | 13 |
private UploadContract.View uploadView; |
| 13 | 14 |
private ArrayList<SessionBean> sessionList; |
| 14 | 15 |
private String lensmanId; |
| 15 | 16 |
private int sessionSeq; |
| 17 |
+ private ArrayList<String> sessionIds; |
|
| 18 |
+ private FetchSessionIdsInteractor interactor; |
|
| 16 | 19 |
|
| 17 | 20 |
public UploadPresenter(UploadContract.View view,String lensmanId){
|
| 18 | 21 |
this.uploadView = view; |
| 19 | 22 |
this.lensmanId = lensmanId; |
| 23 |
+ sessionIds = new ArrayList<>(); |
|
| 24 |
+ interactor = new FetchSessionIdsInteractor(lensmanId,100,this); |
|
| 20 | 25 |
} |
| 21 | 26 |
|
| 22 | 27 |
|
| 23 | 28 |
@Override |
| 24 | 29 |
public void start() {
|
| 30 |
+ if(sessionIds==null|| sessionIds.size()<20){
|
|
| 31 |
+ interactor.startJob(); |
|
| 32 |
+ } |
|
| 33 |
+ if(sessionIds==null || sessionIds.size()<1){
|
|
| 34 |
+ uploadView.setNewSessionBtnEnabled(false); |
|
| 35 |
+ }else{
|
|
| 36 |
+ uploadView.setNewSessionBtnEnabled(true); |
|
| 37 |
+ } |
|
| 25 | 38 |
sessionList = DBService.getInstance().getSessionBeanListByDay(getSessionDateInLongFormat()); |
| 26 | 39 |
if(sessionList.size()==0){
|
| 27 | 40 |
uploadView.showEmptyView(); |
@@ -39,12 +52,14 @@ public class UploadPresenter implements UploadContract.Presenter {
|
||
| 39 | 52 |
|
| 40 | 53 |
@Override |
| 41 | 54 |
public SessionBean createNewSession() {
|
| 55 |
+ |
|
| 42 | 56 |
SessionBean sessionBean = new SessionBean(); |
| 43 | 57 |
sessionBean.lensmanId = lensmanId; |
| 44 | 58 |
sessionBean.sessionDate=getSessionDateInLongFormat(); |
| 45 | 59 |
sessionBean.sessionSeq = sessionSeq+1; |
| 46 |
- sessionBean.sessionId ="chengzhenyu_test"+sessionBean.sessionSeq; |
|
| 60 |
+ sessionBean.sessionId =sessionIds.get(0); |
|
| 47 | 61 |
sessionList.add(sessionBean); |
| 62 |
+ sessionIds.remove(0); |
|
| 48 | 63 |
return sessionBean; |
| 49 | 64 |
} |
| 50 | 65 |
|
@@ -53,4 +68,16 @@ public class UploadPresenter implements UploadContract.Presenter {
|
||
| 53 | 68 |
String dateStr = format.format(new Date()); |
| 54 | 69 |
return Long.parseLong(dateStr); |
| 55 | 70 |
} |
| 71 |
+ |
|
| 72 |
+ @Override |
|
| 73 |
+ public void onInteractSuccess(ArrayList<String> sessionIds) {
|
|
| 74 |
+ this.sessionIds.addAll(sessionIds); |
|
| 75 |
+ uploadView.setNewSessionBtnEnabled(true); |
|
| 76 |
+ } |
|
| 77 |
+ |
|
| 78 |
+ @Override |
|
| 79 |
+ public void onInteractFail(String errorMsg) {
|
|
| 80 |
+// interactor.startJob(); |
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 56 | 83 |
} |
@@ -11,7 +11,7 @@ public class UrlContainer {
|
||
| 11 | 11 |
|
| 12 | 12 |
public static final String LOGIN_URL = HOST_URL+"login"; |
| 13 | 13 |
|
| 14 |
- public static final String SESSION_IDS_CREATE = HOST_URL+"uuid_init"; |
|
| 14 |
+ public static final String SESSION_IDS_CREATE = HOST_URL+"uuid"; |
|
| 15 | 15 |
|
| 16 | 16 |
public static final String PHOTO_UPLOAD_URL = HOST_URL+"photos/upload"; |
| 17 | 17 |
|