@@ -11,6 +11,7 @@ import com.android.views.progressbar.ProgressWheel; |
||
11 | 11 |
|
12 | 12 |
import ai.pai.lensman.R; |
13 | 13 |
import ai.pai.lensman.base.BaseActivity; |
14 |
+import ai.pai.lensman.db.Preferences; |
|
14 | 15 |
import ai.pai.lensman.upload.UploadActivity; |
15 | 16 |
import butterknife.BindView; |
16 | 17 |
import butterknife.ButterKnife; |
@@ -29,7 +30,7 @@ public class LoginActivity extends BaseActivity implements LoginContract.View{ |
||
29 | 30 |
super.onCreate(savedInstanceState); |
30 | 31 |
setContentView(R.layout.activity_login); |
31 | 32 |
ButterKnife.bind(this); |
32 |
- presenter = new LoginPresenter(this); |
|
33 |
+ presenter = new LoginPresenter(this,this); |
|
33 | 34 |
} |
34 | 35 |
|
35 | 36 |
|
@@ -4,6 +4,8 @@ import android.os.AsyncTask; |
||
4 | 4 |
|
5 | 5 |
import com.android.common.executors.ThreadExecutor; |
6 | 6 |
|
7 |
+import org.json.JSONObject; |
|
8 |
+ |
|
7 | 9 |
import java.util.HashMap; |
8 | 10 |
|
9 | 11 |
import ai.pai.lensman.base.BaseInteractor; |
@@ -30,26 +32,41 @@ public class LoginInteractor implements BaseInteractor{ |
||
30 | 32 |
public void startJob() { |
31 | 33 |
cancelJob(); |
32 | 34 |
HashMap<String,String> params = new HashMap<>(); |
33 |
- params.put("account",userName); |
|
35 |
+ params.put("username",userName); |
|
34 | 36 |
params.put("password",password); |
35 | 37 |
|
36 | 38 |
loginTask = new HttpPostTask(params){ |
37 | 39 |
|
40 |
+ String lensmanId; |
|
41 |
+ String message; |
|
38 | 42 |
@Override |
39 | 43 |
protected boolean parseResponse(String response) { |
40 |
- return super.parseResponse(response); |
|
44 |
+ try{ |
|
45 |
+ JSONObject json = new JSONObject(response); |
|
46 |
+ int status = json.getInt("status"); |
|
47 |
+ if(status == 200){ |
|
48 |
+ JSONObject info = json.getJSONObject("data"); |
|
49 |
+ lensmanId = info.getString("user_id"); |
|
50 |
+ return true; |
|
51 |
+ }else{ |
|
52 |
+ message = json.getString("message"); |
|
53 |
+ } |
|
54 |
+ }catch (Exception e){ |
|
55 |
+ e.printStackTrace(); |
|
56 |
+ } |
|
57 |
+ return false; |
|
41 | 58 |
} |
42 | 59 |
|
43 | 60 |
@Override |
44 | 61 |
protected void onPostFail() { |
45 | 62 |
super.onPostFail(); |
46 |
- listener.onInteractFail(""); |
|
63 |
+ listener.onInteractFail(message); |
|
47 | 64 |
} |
48 | 65 |
|
49 | 66 |
@Override |
50 | 67 |
protected void onPostSuccess() { |
51 | 68 |
super.onPostSuccess(); |
52 |
- listener.onInteractSuccess(""); |
|
69 |
+ listener.onInteractSuccess(lensmanId); |
|
53 | 70 |
} |
54 | 71 |
}; |
55 | 72 |
loginTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.LOGIN_URL); |
@@ -1,17 +1,22 @@ |
||
1 | 1 |
package ai.pai.lensman.login; |
2 | 2 |
|
3 |
+import android.content.Context; |
|
4 |
+ |
|
3 | 5 |
import ai.pai.lensman.base.BaseInteractor; |
6 |
+import ai.pai.lensman.db.Preferences; |
|
4 | 7 |
|
5 | 8 |
/** |
6 | 9 |
* Created by chengzhenyu on 2016/8/11. |
7 | 10 |
*/ |
8 | 11 |
public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.InteractorListener<String> { |
9 | 12 |
|
13 |
+ private Context context; |
|
10 | 14 |
private LoginContract.View view; |
11 | 15 |
private LoginInteractor interactor; |
12 | 16 |
|
13 |
- public LoginPresenter(LoginContract.View view){ |
|
17 |
+ public LoginPresenter(Context context,LoginContract.View view){ |
|
14 | 18 |
this.view = view; |
19 |
+ this.context = context; |
|
15 | 20 |
} |
16 | 21 |
|
17 | 22 |
@Override |
@@ -37,6 +42,8 @@ public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.In |
||
37 | 42 |
@Override |
38 | 43 |
public void onInteractSuccess(String result) { |
39 | 44 |
view.hideProgressView(); |
45 |
+ Preferences.getInstance(context).setLensManId(result); |
|
46 |
+ view.jumpMain(); |
|
40 | 47 |
} |
41 | 48 |
|
42 | 49 |
@Override |
@@ -44,4 +51,5 @@ public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.In |
||
44 | 51 |
view.hideProgressView(); |
45 | 52 |
view.showLoginHint(errorMsg); |
46 | 53 |
} |
54 |
+ |
|
47 | 55 |
} |