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

+ 91 - 0
app/src/main/java/ai/pai/lensman/upload/FetchSessionIdsInteractor.java

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

+ 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
 

kodo - Gogs: Go Git Service

Keine Beschreibung

storage_utils.py 4.3KB

    # -*- coding: utf-8 -*- import os import shortuuid from django.conf import settings from django.core.files.storage import default_storage from django.db import transaction from django_file_md5 import calculate_md5 from photo.models import PhotoUUIDInfo from utils.thumbnail_utils import make_thumbnail from utils.watermark_utils import watermark_wrap class DotDict(dict): """ dot.notation access to dictionary attributes """ def __getattr__(self, attr): return self.get(attr) __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ @transaction.atomic def file_save(file_=None, file_path=None, prefix='img', ext='.jpeg', watermark=False, thumbnail=False): # Photo file_ = file_ or default_storage.open(file_path) # Ext ext = os.path.splitext(file_.name)[-1] or ext # Photo MD5 photo_md5 = calculate_md5(file_) # Photo UUID Get or Create photo, created = PhotoUUIDInfo.objects.select_for_update().get_or_create(photo_md5=photo_md5) # 无水印 if not photo.photo_path: photo_path = '{}/{}{}'.format(prefix, shortuuid.uuid(), ext) if default_storage.exists(photo_path): default_storage.delete(photo_path) default_storage.save(photo_path, file_) photo.photo_path = photo_path photo.save() # 有水印 if watermark: if not photo.photo_watermark_path: if settings.WATERMARK_OR_NOT: photo_watermark_path = 'photo/{}{}'.format(shortuuid.uuid(), ext) watermark_wrap( os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'), settings.WATERMARK_LOGO_PATH, os.path.join(settings.MEDIA_ROOT, photo_watermark_path).replace('\\', '/') ) photo.photo_watermark_path = photo_watermark_path else: photo.photo_watermark_path = photo_path photo.save() # 缩略图 if thumbnail: if not photo.photo_thumbnail_path: # 双列: 540, 40-50K photo_thumbnail_path = photo_path.replace('.', '_thumbnail.') photo_w, photo_h, photo_thumbnail_w, photo_thumbnail_h = make_thumbnail( os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'), os.path.join(settings.MEDIA_ROOT, photo_thumbnail_path).replace('\\', '/'), settings.THUMBNAIL_MAX_WIDTH ) photo.photo_w = photo_w photo.photo_h = photo_h photo.photo_thumbnail_path = photo_thumbnail_path photo.photo_thumbnail_w = photo_thumbnail_w photo.photo_thumbnail_h = photo_thumbnail_h if not photo.photo_thumbnail2_path: # 单列: 1080, xx-100K photo_thumbnail2_path = photo_path.replace('.', '_thumbnail2.') photo_w, photo_h, photo_thumbnail2_w, photo_thumbnail2_h = make_thumbnail( os.path.join(settings.MEDIA_ROOT, photo_path).replace('\\', '/'), os.path.join(settings.MEDIA_ROOT, photo_thumbnail2_path).replace('\\', '/'), settings.THUMBNAIL_MAX_WIDTH2 ) if watermark and settings.WATERMARK_OR_NOT: watermark_wrap( os.path.join(settings.MEDIA_ROOT, photo_thumbnail2_path).replace('\\', '/'), settings.WATERMARK_LOGO_PATH, os.path.join(settings.MEDIA_ROOT, photo_thumbnail2_path).replace('\\', '/') ) photo.photo_w = photo_w photo.photo_h = photo_h photo.photo_thumbnail2_path = photo_thumbnail2_path photo.photo_thumbnail2_w = photo_thumbnail2_w photo.photo_thumbnail2_h = photo_thumbnail2_h photo.save() return DotDict({ 'ext': ext, 'photo_md5': photo_md5, 'photo_path': photo.photo_path, 'photo_w': photo.photo_w, 'photo_h': photo.photo_h, 'photo_watermark_path': photo.photo_watermark_path, 'photo_thumbnail_path': photo.photo_thumbnail_path, 'photo_thumbnail_w': photo.photo_thumbnail_w, 'photo_thumbnail_h': photo.photo_thumbnail_h, 'photo_thumbnail2_path': photo.photo_thumbnail2_path, 'photo_thumbnail2_w': photo.photo_thumbnail2_w, 'photo_thumbnail2_h': photo.photo_thumbnail2_h, })