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
+}

+ 6 - 1
app/src/main/java/ai/pai/lensman/upload/UploadActivity.java

@@ -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);

+ 1 - 0
app/src/main/java/ai/pai/lensman/upload/UploadContract.java

@@ -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{

+ 29 - 2
app/src/main/java/ai/pai/lensman/upload/UploadPresenter.java

@@ -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
 }

+ 1 - 1
app/src/main/java/ai/pai/lensman/utils/UrlContainer.java

@@ -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
 

pai2 - Gogs: Go Git Service

拍爱

models.py 4.9KB

    # -*- coding: utf-8 -*- from django.db import models from django.utils.translation import ugettext_lazy as _ from pai2.basemodels import CreateUpdateMixin from utils.qiniucdn import qiniu_file_url class UUIDInfo(CreateUpdateMixin): uuid = models.CharField(_(u'uuid'), max_length=22, blank=True, null=True, help_text=u'唯一标识', db_index=True, unique=True) lensman_id = models.CharField(_(u'lensman_id'), max_length=255, blank=True, null=True, help_text=u'摄影师唯一标识', db_index=True) class Meta: verbose_name = _('uuidinfo') verbose_name_plural = _('uuidinfo') def __unicode__(self): return u'{0.pk}'.format(self) @property def data(self): return { 'pk': self.pk, 'uuid': self.uuid, 'lensman_id': self.lensman_id, } class PhotoUUIDInfo(CreateUpdateMixin): photo_md5 = models.CharField(_(u'photo_md5'), max_length=255, blank=True, null=True, help_text=u'照片唯一标识', db_index=True, unique=True) photo_path = models.CharField(_(u'photo_path'), max_length=255, blank=True, null=True, help_text=u'照片路径') photo_w = models.IntegerField(_(u'photo_w'), default=0, help_text=u'照片宽度') photo_h = models.IntegerField(_(u'photo_h'), default=0, help_text=u'照片高度') photo_watermark_path = models.CharField(_(u'photo_watermark_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径,Box上传,有水印,服务器添加') photo_watermark_w = models.IntegerField(_(u'photo_watermark_w'), default=0, help_text=u'照片水印图宽度') photo_watermark_h = models.IntegerField(_(u'photo_watermark_h'), default=0, help_text=u'照片水印图高度') photo_thumbnail_path = models.CharField(_(u'photo_thumbnail_path'), max_length=255, blank=True, null=True, help_text=u'照片缩略图存放路径') photo_thumbnail_w = models.IntegerField(_(u'photo_thumbnail_w'), default=0, help_text=u'照片缩略图宽度') photo_thumbnail_h = models.IntegerField(_(u'photo_thumbnail_h'), default=0, help_text=u'照片缩略图高度') photo_thumbnail2_path = models.CharField(_(u'photo_thumbnail2_path'), max_length=255, blank=True, null=True, help_text=u'照片缩略图存放路径') photo_thumbnail2_w = models.IntegerField(_(u'photo_thumbnail2_w'), default=0, help_text=u'照片缩略图宽度') photo_thumbnail2_h = models.IntegerField(_(u'photo_thumbnail2_h'), default=0, help_text=u'照片缩略图高度') class Meta: verbose_name = _('photouuidinfo') verbose_name_plural = _('photouuidinfo') def __unicode__(self): return u'{0.pk}'.format(self) class PhotosInfo(CreateUpdateMixin): lensman_id = models.CharField(_(u'lensman_id'), max_length=255, blank=True, null=True, help_text=u'摄影师唯一标识', db_index=True) session_id = models.CharField(_(u'session_id'), max_length=255, blank=True, null=True, help_text=u'照片组唯一标识', db_index=True) photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'照片唯一标识', db_index=True) p_photo_path = models.CharField(_(u'p_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径,Box上传,有水印,服务器添加') m_photo_path = models.CharField(_(u'm_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径,Box上传,无水印') l_photo_path = models.CharField(_(u'l_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径,美化大图') r_photo_path = models.CharField(_(u'r_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径,高清大图') class Meta: verbose_name = _('photosinfo') verbose_name_plural = _('photosinfo') index_together = [ ['lensman_id', 'session_id'], ] unique_together = ( ('lensman_id', 'session_id', 'photo_id'), ) def __unicode__(self): return u'{0.pk}'.format(self) @property def p_photo_url(self): return qiniu_file_url(self.p_photo_path, bucket='watermark') @property def m_photo_url(self): return qiniu_file_url(self.m_photo_path, bucket='photo') @property def l_photo_url(self): return qiniu_file_url(self.l_photo_path, bucket='prettify') @property def r_photo_url(self): return qiniu_file_url(self.r_photo_path, bucket='original') @property def data(self): return { 'pk': self.pk, 'user_id': self.lensman_id, 'session_id': self.session_id, 'photo_id': self.photo_id, } @property def detail(self): return { 'pk': self.pk, 'user_id': self.lensman_id, 'session_id': self.session_id, 'photo_id': self.photo_id, 'photo_url': self.p_photo_url, }