Commit beafeb7e49dd7c7613635167f2598996dfdfa650
1 parent
32846fe9
Exists in
yxb_dev
and in
2 other branches
no message
Showing
7 changed files
with
209 additions
and
28 deletions
Show diff stats
app/src/main/java/com/shunzhi/parent/AppContext.java
1 | package com.shunzhi.parent; | 1 | package com.shunzhi.parent; |
2 | 2 | ||
3 | +import android.content.Context; | ||
3 | import android.content.Intent; | 4 | import android.content.Intent; |
5 | +import android.content.SharedPreferences; | ||
4 | import android.util.Log; | 6 | import android.util.Log; |
5 | 7 | ||
6 | import com.amap.api.location.AMapLocation; | 8 | import com.amap.api.location.AMapLocation; |
7 | import com.amap.api.location.AMapLocationClient; | 9 | import com.amap.api.location.AMapLocationClient; |
8 | import com.amap.api.location.AMapLocationClientOption; | 10 | import com.amap.api.location.AMapLocationClientOption; |
9 | import com.amap.api.location.AMapLocationListener; | 11 | import com.amap.api.location.AMapLocationListener; |
12 | +import com.netease.nimlib.sdk.NIMClient; | ||
13 | +import com.netease.nimlib.sdk.SDKOptions; | ||
14 | +import com.netease.nimlib.sdk.StatusBarNotificationConfig; | ||
15 | +import com.netease.nimlib.sdk.auth.LoginInfo; | ||
10 | import com.share.mvpsdk.global.GlobalApplication; | 16 | import com.share.mvpsdk.global.GlobalApplication; |
11 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; | 17 | import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; |
12 | 18 | ||
@@ -17,9 +23,9 @@ import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; | @@ -17,9 +23,9 @@ import com.amap.api.location.AMapLocationClientOption.AMapLocationMode; | ||
17 | public class AppContext extends GlobalApplication { | 23 | public class AppContext extends GlobalApplication { |
18 | private static AppContext appContext; | 24 | private static AppContext appContext; |
19 | 25 | ||
20 | - public final static int LOCATION_CITYNAME=0x00; | 26 | + public final static int LOCATION_CITYNAME = 0x00; |
21 | 27 | ||
22 | - public String cityName="",district=""; | 28 | + public String cityName = "", district = ""; |
23 | 29 | ||
24 | public static AppContext getInstance() { | 30 | public static AppContext getInstance() { |
25 | return appContext; | 31 | return appContext; |
@@ -29,14 +35,39 @@ public class AppContext extends GlobalApplication { | @@ -29,14 +35,39 @@ public class AppContext extends GlobalApplication { | ||
29 | public AMapLocationClient mLocationClient = null; | 35 | public AMapLocationClient mLocationClient = null; |
30 | 36 | ||
31 | //声明AMapLocationClientOption对象 | 37 | //声明AMapLocationClientOption对象 |
32 | - public AMapLocationClientOption mLocationOption=null; | 38 | + public AMapLocationClientOption mLocationOption = null; |
33 | 39 | ||
34 | @Override | 40 | @Override |
35 | public void onCreate() { | 41 | public void onCreate() { |
36 | - appContext=this; | 42 | + appContext = this; |
37 | super.onCreate(); | 43 | super.onCreate(); |
38 | //开启地图地位 | 44 | //开启地图地位 |
39 | initMapLocal(); | 45 | initMapLocal(); |
46 | + NIMClient.init(this, loginInfo(), options()); | ||
47 | + } | ||
48 | + | ||
49 | + private SDKOptions options() { | ||
50 | + SDKOptions options = new SDKOptions(); | ||
51 | + | ||
52 | + // 如果将新消息通知提醒托管给 SDK 完成,需要添加以下配置。否则无需设置。 | ||
53 | + StatusBarNotificationConfig config = new StatusBarNotificationConfig(); | ||
54 | + //config.notificationEntrance = MainActivity.class; // 点击通知栏跳转到该Activity | ||
55 | + config.notificationSmallIconId = R.mipmap.ic_launcher; | ||
56 | + options.sdkStorageRootPath = getExternalFilesDir(null).getPath() + "/nim"; | ||
57 | + options.statusBarNotificationConfig = config; | ||
58 | + //options.preloadAttach=false; | ||
59 | + return options; | ||
60 | + } | ||
61 | + | ||
62 | + | ||
63 | + private LoginInfo loginInfo() { | ||
64 | + SharedPreferences sp = getSharedPreferences("info", Context.MODE_PRIVATE); | ||
65 | + String account = sp.getString("account", ""); | ||
66 | + String token = sp.getString("token", ""); | ||
67 | + if (account.length() > 0 && token.length() > 0) { | ||
68 | + return new LoginInfo(account, token); | ||
69 | + } | ||
70 | + return null; | ||
40 | } | 71 | } |
41 | 72 | ||
42 | private void initMapLocal() { | 73 | private void initMapLocal() { |
@@ -66,47 +97,47 @@ public class AppContext extends GlobalApplication { | @@ -66,47 +97,47 @@ public class AppContext extends GlobalApplication { | ||
66 | mLocationOption.setHttpTimeOut(20000); | 97 | mLocationOption.setHttpTimeOut(20000); |
67 | //关闭缓存机制 | 98 | //关闭缓存机制 |
68 | mLocationOption.setLocationCacheEnable(false); | 99 | mLocationOption.setLocationCacheEnable(false); |
69 | - if (null!=mLocationClient) | 100 | + if (null != mLocationClient) |
70 | mLocationClient.setLocationOption(mLocationOption); | 101 | mLocationClient.setLocationOption(mLocationOption); |
71 | //启动定位 | 102 | //启动定位 |
72 | startLocation(); | 103 | startLocation(); |
73 | 104 | ||
74 | } | 105 | } |
75 | 106 | ||
76 | - public void startLocation(){ | 107 | + public void startLocation() { |
77 | //启动定位 | 108 | //启动定位 |
78 | - if (null!=mLocationClient){ | 109 | + if (null != mLocationClient) { |
79 | // mLocationClient.setLocationOption(mLocationOption); | 110 | // mLocationClient.setLocationOption(mLocationOption); |
80 | //设置场景模式后最好调用一次stop,再调用start以保证场景模式生效 | 111 | //设置场景模式后最好调用一次stop,再调用start以保证场景模式生效 |
81 | stopLocation(); | 112 | stopLocation(); |
82 | mLocationClient.startLocation(); | 113 | mLocationClient.startLocation(); |
83 | - }else initMapLocal(); | 114 | + } else initMapLocal(); |
84 | } | 115 | } |
85 | 116 | ||
86 | - public void stopLocation(){ | ||
87 | - if (null!=mLocationClient)mLocationClient.stopLocation(); | 117 | + public void stopLocation() { |
118 | + if (null != mLocationClient) mLocationClient.stopLocation(); | ||
88 | } | 119 | } |
89 | 120 | ||
90 | - public void destoryLocation(){ | ||
91 | - if (null!=mLocationClient)mLocationClient.onDestroy(); | 121 | + public void destoryLocation() { |
122 | + if (null != mLocationClient) mLocationClient.onDestroy(); | ||
92 | } | 123 | } |
93 | 124 | ||
94 | //声明定位回调监听器 | 125 | //声明定位回调监听器 |
95 | public AMapLocationListener mLocationListener = new AMapLocationListener() { | 126 | public AMapLocationListener mLocationListener = new AMapLocationListener() { |
96 | @Override | 127 | @Override |
97 | public void onLocationChanged(AMapLocation aMapLocation) { | 128 | public void onLocationChanged(AMapLocation aMapLocation) { |
98 | - if(null!=aMapLocation){ | 129 | + if (null != aMapLocation) { |
99 | 130 | ||
100 | - if (aMapLocation.getErrorCode()==0){ | ||
101 | - cityName=aMapLocation.getCity(); | ||
102 | - district=aMapLocation.getDistrict(); | 131 | + if (aMapLocation.getErrorCode() == 0) { |
132 | + cityName = aMapLocation.getCity(); | ||
133 | + district = aMapLocation.getDistrict(); | ||
103 | aMapLocation.getCityCode(); | 134 | aMapLocation.getCityCode(); |
104 | - Intent intent=new Intent(); | ||
105 | - intent.setAction(LOCATION_CITYNAME+""); | 135 | + Intent intent = new Intent(); |
136 | + intent.setAction(LOCATION_CITYNAME + ""); | ||
106 | sendBroadcast(intent); | 137 | sendBroadcast(intent); |
107 | stopLocation(); | 138 | stopLocation(); |
108 | - }else { | ||
109 | - cityName="定位失败"; | 139 | + } else { |
140 | + cityName = "定位失败"; | ||
110 | // Log.d("mlocation:","errorCode="+aMapLocation.getErrorCode()+"errorInfo="+aMapLocation.getErrorInfo()); | 141 | // Log.d("mlocation:","errorCode="+aMapLocation.getErrorCode()+"errorInfo="+aMapLocation.getErrorInfo()); |
111 | } | 142 | } |
112 | 143 |
app/src/main/java/com/shunzhi/parent/bean/NIMLoginResultBean.java
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +package com.shunzhi.parent.bean; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by 10501 on 2018/3/19. | ||
5 | + */ | ||
6 | + | ||
7 | +public class NIMLoginResultBean { | ||
8 | + public NIMLoginResultBean() { | ||
9 | + } | ||
10 | + | ||
11 | + public NIMLoginResultBean(boolean isSuccess, int resultCode, Throwable throwable) { | ||
12 | + this.isSuccess = isSuccess; | ||
13 | + this.resultCode = resultCode; | ||
14 | + this.throwable = throwable; | ||
15 | + } | ||
16 | + | ||
17 | + private boolean isSuccess; | ||
18 | + private int resultCode; | ||
19 | + private Throwable throwable; | ||
20 | + | ||
21 | + public boolean isSuccess() { | ||
22 | + return isSuccess; | ||
23 | + } | ||
24 | + | ||
25 | + public void setSuccess(boolean success) { | ||
26 | + isSuccess = success; | ||
27 | + } | ||
28 | + | ||
29 | + public int getResultCode() { | ||
30 | + return resultCode; | ||
31 | + } | ||
32 | + | ||
33 | + public void setResultCode(int resultCode) { | ||
34 | + this.resultCode = resultCode; | ||
35 | + } | ||
36 | + | ||
37 | + public Throwable getThrowable() { | ||
38 | + return throwable; | ||
39 | + } | ||
40 | + | ||
41 | + public void setThrowable(Throwable throwable) { | ||
42 | + this.throwable = throwable; | ||
43 | + } | ||
44 | +} |
app/src/main/java/com/shunzhi/parent/contract/loginandregister/LoginAndRegisterContract.java
@@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | ||
4 | import com.share.mvpsdk.base.BasePresenter; | 4 | import com.share.mvpsdk.base.BasePresenter; |
5 | import com.share.mvpsdk.base.IBaseFragment; | 5 | import com.share.mvpsdk.base.IBaseFragment; |
6 | import com.share.mvpsdk.base.IBaseModel; | 6 | import com.share.mvpsdk.base.IBaseModel; |
7 | +import com.shunzhi.parent.bean.NIMLoginResultBean; | ||
7 | import com.shunzhi.parent.bean.UserInfo; | 8 | import com.shunzhi.parent.bean.UserInfo; |
8 | 9 | ||
9 | import io.reactivex.Observable; | 10 | import io.reactivex.Observable; |
@@ -22,6 +23,8 @@ public interface LoginAndRegisterContract { | @@ -22,6 +23,8 @@ public interface LoginAndRegisterContract { | ||
22 | public abstract void idCodeResult(String phoneNumber); | 23 | public abstract void idCodeResult(String phoneNumber); |
23 | 24 | ||
24 | public abstract void getUserInfo(String mobile,int school_id,String captcha); | 25 | public abstract void getUserInfo(String mobile,int school_id,String captcha); |
26 | + | ||
27 | + public abstract void nimLogin(String account,String password); | ||
25 | } | 28 | } |
26 | 29 | ||
27 | interface ILoginModel extends IBaseModel{ | 30 | interface ILoginModel extends IBaseModel{ |
@@ -33,6 +36,8 @@ public interface LoginAndRegisterContract { | @@ -33,6 +36,8 @@ public interface LoginAndRegisterContract { | ||
33 | 36 | ||
34 | //获取登录用户信息 | 37 | //获取登录用户信息 |
35 | Observable<UserInfo> getUserInfo(String mobile, int school_id, String captcha); | 38 | Observable<UserInfo> getUserInfo(String mobile, int school_id, String captcha); |
39 | + | ||
40 | + Observable<NIMLoginResultBean> nimLoginResult(String account, String token); | ||
36 | } | 41 | } |
37 | interface ILoginView extends IBaseFragment { | 42 | interface ILoginView extends IBaseFragment { |
38 | 43 |
app/src/main/java/com/shunzhi/parent/manager/MessageManager.java
1 | package com.shunzhi.parent.manager; | 1 | package com.shunzhi.parent.manager; |
2 | 2 | ||
3 | +import android.content.Context; | ||
4 | +import android.content.SharedPreferences; | ||
5 | +import android.support.annotation.NonNull; | ||
6 | + | ||
3 | import com.netease.nimlib.sdk.NIMClient; | 7 | import com.netease.nimlib.sdk.NIMClient; |
4 | import com.netease.nimlib.sdk.Observer; | 8 | import com.netease.nimlib.sdk.Observer; |
9 | +import com.netease.nimlib.sdk.RequestCallback; | ||
5 | import com.netease.nimlib.sdk.auth.AuthService; | 10 | import com.netease.nimlib.sdk.auth.AuthService; |
6 | import com.netease.nimlib.sdk.auth.LoginInfo; | 11 | import com.netease.nimlib.sdk.auth.LoginInfo; |
7 | import com.netease.nimlib.sdk.msg.MsgServiceObserve; | 12 | import com.netease.nimlib.sdk.msg.MsgServiceObserve; |
8 | import com.netease.nimlib.sdk.msg.model.CustomNotification; | 13 | import com.netease.nimlib.sdk.msg.model.CustomNotification; |
9 | import com.netease.nimlib.sdk.msg.model.IMMessage; | 14 | import com.netease.nimlib.sdk.msg.model.IMMessage; |
15 | +import com.share.mvpsdk.utils.ToastUtils; | ||
16 | +import com.shunzhi.parent.AppContext; | ||
17 | +import com.shunzhi.parent.bean.NIMLoginResultBean; | ||
10 | 18 | ||
11 | import java.util.List; | 19 | import java.util.List; |
12 | 20 | ||
21 | +import io.reactivex.Observable; | ||
22 | +import io.reactivex.subjects.PublishSubject; | ||
23 | +import timber.log.Timber; | ||
24 | + | ||
13 | /** | 25 | /** |
14 | * Created by 10501 on 2018/3/17. | 26 | * Created by 10501 on 2018/3/17. |
15 | */ | 27 | */ |
@@ -20,7 +32,7 @@ public class MessageManager { | @@ -20,7 +32,7 @@ public class MessageManager { | ||
20 | static final MessageManager instance = new MessageManager(); | 32 | static final MessageManager instance = new MessageManager(); |
21 | } | 33 | } |
22 | 34 | ||
23 | - public MessageManager getInstance() { | 35 | + public static MessageManager getInstance() { |
24 | return InstanceHolder.instance; | 36 | return InstanceHolder.instance; |
25 | } | 37 | } |
26 | 38 | ||
@@ -52,8 +64,36 @@ public class MessageManager { | @@ -52,8 +64,36 @@ public class MessageManager { | ||
52 | 64 | ||
53 | } | 65 | } |
54 | 66 | ||
55 | - public void login(String account, String password) { | ||
56 | - NIMClient.getService(AuthService.class).login(new LoginInfo(account, password)); | 67 | + public Observable<NIMLoginResultBean> login(String account, String password) { |
68 | + final PublishSubject<NIMLoginResultBean> subject = PublishSubject.create(); | ||
69 | + SharedPreferences sp = AppContext.getInstance().getApplicationContext().getSharedPreferences("info", Context.MODE_PRIVATE); | ||
70 | + sp.edit().putString("account", account).apply(); | ||
71 | + sp.edit().putString("token", password).apply(); | ||
72 | + NIMClient.getService(AuthService.class) | ||
73 | + .login(new LoginInfo(account, password)) | ||
74 | + .setCallback(new RequestCallback() { | ||
75 | + @Override | ||
76 | + public void onSuccess(Object o) { | ||
77 | + NIMLoginResultBean bean = new NIMLoginResultBean(true, 200, null); | ||
78 | + subject.onNext(bean); | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public void onFailed(int i) { | ||
83 | + Timber.i("------nim login failed : %s", i); | ||
84 | + ToastUtils.showToast("云信服务器登录失败:" + i); | ||
85 | + NIMLoginResultBean bean = new NIMLoginResultBean(false, i, null); | ||
86 | + subject.onNext(bean); | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public void onException(Throwable throwable) { | ||
91 | + if (throwable != null) throwable.printStackTrace(); | ||
92 | + NIMLoginResultBean bean = new NIMLoginResultBean(false, 0, throwable); | ||
93 | + subject.onNext(bean); | ||
94 | + } | ||
95 | + }); | ||
96 | + return subject; | ||
57 | } | 97 | } |
58 | 98 | ||
59 | 99 | ||
@@ -62,4 +102,8 @@ public class MessageManager { | @@ -62,4 +102,8 @@ public class MessageManager { | ||
62 | NIMClient.getService(MsgServiceObserve.class).observeCustomNotification(customNotificationObserver, false); | 102 | NIMClient.getService(MsgServiceObserve.class).observeCustomNotification(customNotificationObserver, false); |
63 | NIMClient.getService(AuthService.class).logout(); | 103 | NIMClient.getService(AuthService.class).logout(); |
64 | } | 104 | } |
105 | + | ||
106 | + public interface NIMLoginCallback { | ||
107 | + void onResult(boolean isSuccess, int resultCode, Throwable throwable); | ||
108 | + } | ||
65 | } | 109 | } |
app/src/main/java/com/shunzhi/parent/model/loginandregister/LoginAndRegisterModel.java
@@ -5,8 +5,10 @@ import com.share.mvpsdk.base.BaseModel; | @@ -5,8 +5,10 @@ import com.share.mvpsdk.base.BaseModel; | ||
5 | import com.share.mvpsdk.helper.RetrofitCreateHelper; | 5 | import com.share.mvpsdk.helper.RetrofitCreateHelper; |
6 | import com.share.mvpsdk.helper.RxHelper; | 6 | import com.share.mvpsdk.helper.RxHelper; |
7 | import com.shunzhi.parent.api.LoginRegisterApi; | 7 | import com.shunzhi.parent.api.LoginRegisterApi; |
8 | +import com.shunzhi.parent.bean.NIMLoginResultBean; | ||
8 | import com.shunzhi.parent.bean.UserInfo; | 9 | import com.shunzhi.parent.bean.UserInfo; |
9 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; | 10 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
11 | +import com.shunzhi.parent.manager.MessageManager; | ||
10 | 12 | ||
11 | import io.reactivex.Observable; | 13 | import io.reactivex.Observable; |
12 | 14 | ||
@@ -47,4 +49,9 @@ public class LoginAndRegisterModel extends BaseModel implements LoginAndRegiste | @@ -47,4 +49,9 @@ public class LoginAndRegisterModel extends BaseModel implements LoginAndRegiste | ||
47 | .compose(RxHelper.<UserInfo>rxSchedulerHelper()); | 49 | .compose(RxHelper.<UserInfo>rxSchedulerHelper()); |
48 | } | 50 | } |
49 | 51 | ||
52 | + @Override | ||
53 | + public Observable<NIMLoginResultBean> nimLoginResult(String account, String token) { | ||
54 | + return MessageManager.getInstance().login(account, token); | ||
55 | + } | ||
56 | + | ||
50 | } | 57 | } |
app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java
@@ -10,10 +10,13 @@ import com.share.mvpsdk.utils.ToastUtils; | @@ -10,10 +10,13 @@ import com.share.mvpsdk.utils.ToastUtils; | ||
10 | import com.shunzhi.parent.AppConfig; | 10 | import com.shunzhi.parent.AppConfig; |
11 | import com.shunzhi.parent.AppContext; | 11 | import com.shunzhi.parent.AppContext; |
12 | import com.shunzhi.parent.bean.CurrentBean; | 12 | import com.shunzhi.parent.bean.CurrentBean; |
13 | +import com.shunzhi.parent.bean.NIMLoginResultBean; | ||
13 | import com.shunzhi.parent.bean.UserInfo; | 14 | import com.shunzhi.parent.bean.UserInfo; |
14 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; | 15 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
16 | +import com.shunzhi.parent.manager.MessageManager; | ||
15 | import com.shunzhi.parent.model.loginandregister.LoginAndRegisterModel; | 17 | import com.shunzhi.parent.model.loginandregister.LoginAndRegisterModel; |
16 | import com.shunzhi.parent.ui.fragment.loginandregistfragment.LoginAndRegistFragment; | 18 | import com.shunzhi.parent.ui.fragment.loginandregistfragment.LoginAndRegistFragment; |
19 | +import com.shunzhi.parent.util.Utils; | ||
17 | 20 | ||
18 | import java.util.regex.Matcher; | 21 | import java.util.regex.Matcher; |
19 | import java.util.regex.Pattern; | 22 | import java.util.regex.Pattern; |
@@ -125,12 +128,11 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | @@ -125,12 +128,11 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | ||
125 | } | 128 | } |
126 | 129 | ||
127 | @Override | 130 | @Override |
128 | - | ||
129 | public void getUserInfo(final String mobile, int school_id, String captcha) { | 131 | public void getUserInfo(final String mobile, int school_id, String captcha) { |
130 | mRxManager.register(mIModel.getUserInfo(mobile, school_id, captcha).subscribe(new Consumer<UserInfo>() { | 132 | mRxManager.register(mIModel.getUserInfo(mobile, school_id, captcha).subscribe(new Consumer<UserInfo>() { |
131 | @Override | 133 | @Override |
132 | public void accept(UserInfo userInfo) throws Exception { | 134 | public void accept(UserInfo userInfo) throws Exception { |
133 | - Log.d("6666","userInfo="+userInfo.toString()); | 135 | + Log.d("6666", "userInfo=" + userInfo.toString()); |
134 | if (userInfo != null) { | 136 | if (userInfo != null) { |
135 | CurrentBean currentBean = userInfo.getData(); | 137 | CurrentBean currentBean = userInfo.getData(); |
136 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.LOGIN_NAME, currentBean.getMobile()); | 138 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.LOGIN_NAME, currentBean.getMobile()); |
@@ -138,9 +140,10 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | @@ -138,9 +140,10 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | ||
138 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.USER_IMAGE, currentBean.getImage()); | 140 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.USER_IMAGE, currentBean.getImage()); |
139 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.USER_SEX, String.valueOf(currentBean.getSex())); | 141 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.USER_SEX, String.valueOf(currentBean.getSex())); |
140 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.PARENT_ID, String.valueOf(currentBean.getParentId())); | 142 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.PARENT_ID, String.valueOf(currentBean.getParentId())); |
141 | - AppConfig.getAppConfig(AppContext.getContext()).set(AppConfig.USER_ID,currentBean.getUserid()); | ||
142 | - mIView.getUserInfo(0); | ||
143 | - | 143 | + AppConfig.getAppConfig(AppContext.getContext()).set(AppConfig.USER_ID, currentBean.getUserid()); |
144 | + String account = currentBean.getUserid(); | ||
145 | + String token = Utils.MD5(account); | ||
146 | + nimLogin(account, token); | ||
144 | } else { | 147 | } else { |
145 | LoginAndRegistFragment.progressDialog.dismiss(); | 148 | LoginAndRegistFragment.progressDialog.dismiss(); |
146 | ToastUtils.showToast("错误"); | 149 | ToastUtils.showToast("错误"); |
@@ -155,6 +158,17 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | @@ -155,6 +158,17 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | ||
155 | })); | 158 | })); |
156 | } | 159 | } |
157 | 160 | ||
161 | + @Override | ||
162 | + public void nimLogin(String account, String password) { | ||
163 | + mRxManager.register(mIModel.nimLoginResult(account, password).subscribe(new Consumer<NIMLoginResultBean>() { | ||
164 | + @Override | ||
165 | + public void accept(NIMLoginResultBean bean) throws Exception { | ||
166 | + if (bean.isSuccess()) | ||
167 | + mIView.getUserInfo(0); | ||
168 | + } | ||
169 | + })); | ||
170 | + } | ||
171 | + | ||
158 | 172 | ||
159 | @Override | 173 | @Override |
160 | public LoginAndRegisterContract.ILoginModel getModel() { | 174 | public LoginAndRegisterContract.ILoginModel getModel() { |
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +package com.shunzhi.parent.util; | ||
2 | + | ||
3 | +public class Utils { | ||
4 | + private Utils() {} | ||
5 | + | ||
6 | + public static String MD5(String str) { | ||
7 | + try { | ||
8 | + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); | ||
9 | + byte[] array = md.digest(str.getBytes("utf-8")); | ||
10 | + StringBuilder sb = new StringBuilder(); | ||
11 | + for (int i = 0; i < array.length; ++i) { | ||
12 | + sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); | ||
13 | + } | ||
14 | + return sb.toString().toUpperCase(); | ||
15 | + } catch (Exception e) { | ||
16 | + e.printStackTrace(); | ||
17 | + } | ||
18 | + return ""; | ||
19 | + } | ||
20 | + | ||
21 | + public static String md5(String str) { | ||
22 | + try { | ||
23 | + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); | ||
24 | + byte[] array = md.digest(str.getBytes("utf-8")); | ||
25 | + StringBuilder sb = new StringBuilder(); | ||
26 | + for (int i = 0; i < array.length; ++i) { | ||
27 | + sb.append(Integer.toHexString((array[i] & 0xff) | 0x100).substring(1, 3)); | ||
28 | + } | ||
29 | + return sb.toString().toUpperCase(); | ||
30 | + } catch (Exception e) { | ||
31 | + e.printStackTrace(); | ||
32 | + } | ||
33 | + return ""; | ||
34 | + } | ||
35 | + | ||
36 | +} |