@@ -181,6 +181,7 @@ public class SessionInteractor {
|
||
| 181 | 181 |
protected Boolean doInBackground(PhotoBean... params) {
|
| 182 | 182 |
PhotoBean photoBean = params[0]; |
| 183 | 183 |
String path = BoxUrlContainer.PHOTO_PATH_PREFIX_URL+photoBean.photoPath; |
| 184 |
+ //TODO for test |
|
| 184 | 185 |
if(photoBean.photoPath.contains("baidu")){
|
| 185 | 186 |
path = photoBean.photoPath; |
| 186 | 187 |
} |
@@ -2,69 +2,48 @@ package ai.pai.lensman.splash; |
||
| 2 | 2 |
|
| 3 | 3 |
import android.content.Intent; |
| 4 | 4 |
import android.os.Bundle; |
| 5 |
-import android.os.Handler; |
|
| 6 | 5 |
import android.support.v4.app.FragmentActivity; |
| 7 | 6 |
|
| 8 |
-import com.android.common.utils.NetworkUtil; |
|
| 9 |
- |
|
| 10 |
-import java.text.SimpleDateFormat; |
|
| 11 |
-import java.util.Date; |
|
| 12 |
- |
|
| 13 | 7 |
import ai.pai.lensman.R; |
| 14 |
-import ai.pai.lensman.db.Preferences; |
|
| 15 | 8 |
import ai.pai.lensman.login.LoginActivity; |
| 16 |
-import ai.pai.lensman.service.UpgradeService; |
|
| 17 | 9 |
import ai.pai.lensman.upload.UploadActivity; |
| 18 | 10 |
|
| 19 |
-public class SplashActivity extends FragmentActivity {
|
|
| 11 |
+public class SplashActivity extends FragmentActivity implements SplashContract.View {
|
|
| 20 | 12 |
|
| 21 |
- private Handler mHandler; |
|
| 22 |
- private static final int NORMAL_DELAY_TIME = 1500; |
|
| 13 |
+ private SplashPresenter presenter; |
|
| 23 | 14 |
|
| 24 | 15 |
@Override |
| 25 | 16 |
protected void onCreate(Bundle savedInstanceState) {
|
| 26 | 17 |
super.onCreate(savedInstanceState); |
| 27 | 18 |
setContentView(R.layout.activity_splash); |
| 28 |
- mHandler = new Handler(); |
|
| 19 |
+ presenter = new SplashPresenter(this,this); |
|
| 20 |
+ |
|
| 29 | 21 |
} |
| 30 | 22 |
|
| 31 | 23 |
@Override |
| 32 | 24 |
protected void onResume() {
|
| 33 | 25 |
super.onResume(); |
| 34 |
- checkUpdateAndSplash(); |
|
| 35 |
- mHandler.postDelayed(new Runnable() {
|
|
| 36 |
- @Override |
|
| 37 |
- public void run() {
|
|
| 38 |
- Intent intent ; |
|
| 39 |
- if(Preferences.getInstance(getApplicationContext()).getLensManId().isEmpty()){
|
|
| 40 |
- intent = new Intent(SplashActivity.this, LoginActivity.class); |
|
| 41 |
- }else{
|
|
| 42 |
- intent = new Intent(SplashActivity.this, UploadActivity.class); |
|
| 43 |
- } |
|
| 44 |
- startActivity(intent); |
|
| 45 |
- finish(); |
|
| 46 |
- } |
|
| 47 |
- }, NORMAL_DELAY_TIME); |
|
| 26 |
+ presenter.start(); |
|
| 27 |
+ |
|
| 48 | 28 |
} |
| 49 | 29 |
|
| 50 | 30 |
@Override |
| 51 | 31 |
protected void onStop() {
|
| 52 | 32 |
super.onStop(); |
| 53 |
- mHandler.removeCallbacksAndMessages(null); |
|
| 33 |
+ presenter.stop(); |
|
| 54 | 34 |
} |
| 55 | 35 |
|
| 56 |
- private void checkUpdateAndSplash() {
|
|
| 57 |
- try {
|
|
| 58 |
- String curDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
| 59 |
- if (!Preferences.getInstance(this).getLastRunDate().equals(curDate) && NetworkUtil.isWifiConnected(this)) {
|
|
| 60 |
- Preferences.getInstance(this).setLastRunDate(curDate); |
|
| 61 |
- Intent intent = new Intent(this, UpgradeService.class); |
|
| 62 |
- startService(intent); |
|
| 63 |
- } |
|
| 64 |
- } catch (Exception e) {
|
|
| 65 |
- e.printStackTrace(); |
|
| 66 |
- } |
|
| 36 |
+ @Override |
|
| 37 |
+ public void jump2Main() {
|
|
| 38 |
+ Intent intent = new Intent(SplashActivity.this, UploadActivity.class); |
|
| 39 |
+ startActivity(intent); |
|
| 40 |
+ finish(); |
|
| 67 | 41 |
} |
| 68 | 42 |
|
| 69 |
- |
|
| 43 |
+ @Override |
|
| 44 |
+ public void jump2Login() {
|
|
| 45 |
+ Intent intent = new Intent(SplashActivity.this, LoginActivity.class); |
|
| 46 |
+ startActivity(intent); |
|
| 47 |
+ finish(); |
|
| 48 |
+ } |
|
| 70 | 49 |
} |
@@ -0,0 +1,20 @@ |
||
| 1 |
+package ai.pai.lensman.splash; |
|
| 2 |
+ |
|
| 3 |
+import ai.pai.lensman.base.BasePresenter; |
|
| 4 |
+import ai.pai.lensman.base.BaseView; |
|
| 5 |
+ |
|
| 6 |
+/** |
|
| 7 |
+ * Created by chengzhenyu on 2016/8/14. |
|
| 8 |
+ */ |
|
| 9 |
+public class SplashContract {
|
|
| 10 |
+ |
|
| 11 |
+ interface View extends BaseView{
|
|
| 12 |
+ void jump2Main(); |
|
| 13 |
+ void jump2Login(); |
|
| 14 |
+ } |
|
| 15 |
+ |
|
| 16 |
+ interface Presenter extends BasePresenter{
|
|
| 17 |
+ |
|
| 18 |
+ } |
|
| 19 |
+ |
|
| 20 |
+} |
@@ -0,0 +1,69 @@ |
||
| 1 |
+package ai.pai.lensman.splash; |
|
| 2 |
+ |
|
| 3 |
+import android.content.Context; |
|
| 4 |
+import android.content.Intent; |
|
| 5 |
+import android.os.Handler; |
|
| 6 |
+import android.text.TextUtils; |
|
| 7 |
+ |
|
| 8 |
+import com.android.common.utils.NetworkUtil; |
|
| 9 |
+ |
|
| 10 |
+import java.text.SimpleDateFormat; |
|
| 11 |
+import java.util.Date; |
|
| 12 |
+ |
|
| 13 |
+import ai.pai.lensman.db.Preferences; |
|
| 14 |
+import ai.pai.lensman.service.UpgradeService; |
|
| 15 |
+ |
|
| 16 |
+/** |
|
| 17 |
+ * Created by chengzhenyu on 2016/8/14. |
|
| 18 |
+ */ |
|
| 19 |
+public class SplashPresenter implements SplashContract.Presenter {
|
|
| 20 |
+ |
|
| 21 |
+ private Context context; |
|
| 22 |
+ private SplashContract.View view; |
|
| 23 |
+ private Handler mHandler; |
|
| 24 |
+ private static final int NORMAL_DELAY_TIME = 1500; |
|
| 25 |
+ |
|
| 26 |
+ public SplashPresenter(Context context, SplashContract.View view){
|
|
| 27 |
+ this.view = view; |
|
| 28 |
+ this.context = context; |
|
| 29 |
+ mHandler = new Handler(); |
|
| 30 |
+ } |
|
| 31 |
+ |
|
| 32 |
+ @Override |
|
| 33 |
+ public void start() {
|
|
| 34 |
+ if(TextUtils.isEmpty(Preferences.getInstance(context).getLensManId())){
|
|
| 35 |
+ mHandler.postDelayed(new Runnable() {
|
|
| 36 |
+ @Override |
|
| 37 |
+ public void run() {
|
|
| 38 |
+ view.jump2Login(); |
|
| 39 |
+ } |
|
| 40 |
+ }, NORMAL_DELAY_TIME); |
|
| 41 |
+ return; |
|
| 42 |
+ } |
|
| 43 |
+ mHandler.postDelayed(new Runnable() {
|
|
| 44 |
+ @Override |
|
| 45 |
+ public void run() {
|
|
| 46 |
+ view.jump2Main(); |
|
| 47 |
+ } |
|
| 48 |
+ }, NORMAL_DELAY_TIME); |
|
| 49 |
+ String curDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
| 50 |
+ if(Preferences.getInstance(context).getLastRunDate().equals(curDate)){
|
|
| 51 |
+ return; |
|
| 52 |
+ } |
|
| 53 |
+// checkUpdate(); |
|
| 54 |
+ Preferences.getInstance(context).setLastRunDate(curDate); |
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+ @Override |
|
| 58 |
+ public void stop() {
|
|
| 59 |
+ mHandler.removeCallbacksAndMessages(null); |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ private void checkUpdate() {
|
|
| 63 |
+ if(NetworkUtil.isWifiConnected(context)){
|
|
| 64 |
+ Intent intent = new Intent(context, UpgradeService.class); |
|
| 65 |
+ context.startService(intent); |
|
| 66 |
+ } |
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 69 |
+} |
@@ -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 |
|