nl-6 ol-6"> 4 6
  * Created by chengzhenyu on 2016/8/11.
5 7
  */
6
-public class LoginPresenter implements LoginContract.Presenter {
8
+public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.InteractorListener<String> {
7 9
 
8 10
     private LoginContract.View view;
11
+    private LoginInteractor interactor;
9 12
 
10 13
     public LoginPresenter(LoginContract.View view){
11 14
         this.view = view;
@@ -14,7 +17,8 @@ public class LoginPresenter implements LoginContract.Presenter {
14 17
     @Override
15 18
     public void login(String userName, String pwd) {
16 19
         view.showProgressView();
17
-
20
+        interactor = new LoginInteractor(userName,pwd,this);
21
+        interactor.startJob();
18 22
     }
19 23
 
20 24
     @Override
@@ -24,7 +28,20 @@ public class LoginPresenter implements LoginContract.Presenter {
24 28
 
25 29
     @Override
26 30
     public void stop() {
31
+        if(interactor!=null){
32
+            interactor.cancelJob();
33
+        }
34
+    }
35
+
27 36
 
37
+    @Override
38
+    public void onInteractSuccess(String result) {
39
+        view.hideProgressView();
28 40
     }
29 41
 
42
+    @Override
43
+    public void onInteractFail(String errorMsg) {
44
+        view.hideProgressView();
45
+        view.showLoginHint(errorMsg);
46
+    }
30 47
 }

+ 53 - 0
app/src/main/java/ai/pai/lensman/utils/HttpPostTask.java

@@ -0,0 +1,53 @@
1
+package ai.pai.lensman.utils;
2
+
3
+import android.os.AsyncTask;
4
+
5
+import com.android.common.http.HttpUtils;
6
+
7
+import java.util.HashMap;
8
+
9
+import ai.pai.lensman.BuildConfig;
10
+
11
+
12
+public  class HttpPostTask extends AsyncTask<String,Integer,Boolean> {
13
+
14
+
15
+    private HashMap<String,String> httpParams;
16
+
17
+    public HttpPostTask(HashMap<String,String> httpParams){
18
+        this.httpParams = httpParams;
19
+    }
20
+
21
+    @Override
22
+    protected Boolean doInBackground(String... params) {
23
+        String rootUrl = params[0];
24
+        if(rootUrl.contains("?")){
25
+            rootUrl+="&platform=android";
26
+        }else{
27
+            rootUrl+="?platform=android";
28
+        }
29
+        rootUrl+="&version="+ BuildConfig.VERSION_NAME;
30
+        rootUrl+="&channel="+"guanwang";
31
+        String response= HttpUtils.doHttpPost(rootUrl,httpParams);
32
+        return parseResponse(response);
33
+    }
34
+
35
+    @Override
36
+    protected void onPostExecute(Boolean result) {
37
+        super.onPostExecute(result);
38
+        if(result){
39
+            onPostSuccess();
40
+        }else{
41
+            onPostFail();
42
+        }
43
+    }
44
+
45
+    protected  boolean parseResponse(String response){return true;}
46
+
47
+    protected void onPostFail(){ }
48
+
49
+    protected  void onPostSuccess(){ }
50
+
51
+
52
+
53
+}

kodo - Gogs: Go Git Service

Nav apraksta

Brightcells: 018d52f61d Update package django_xxx 8 gadi atpakaļ
..
migrations 41c58ec3f7 Add box api loginqr 8 gadi atpakaļ
__init__.py 41c58ec3f7 Add box api loginqr 8 gadi atpakaļ
admin.py 41c58ec3f7 Add box api loginqr 8 gadi atpakaļ
models.py 41c58ec3f7 Add box api loginqr 8 gadi atpakaļ
tests.py 41c58ec3f7 Add box api loginqr 8 gadi atpakaļ
views.py 018d52f61d Update package django_xxx 8 gadi atpakaļ