1. 迁移个人信息获取位置,放到了ExtensionsFragment
2. 设计未出图,界面暂未实现
This commit is contained in:
@@ -11,8 +11,12 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.module.extensions.userinfo.UserInfo;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* 天气,消息,个人头像
|
||||
*
|
||||
* @author congtaowang
|
||||
* @since 2020-01-05
|
||||
* <p>
|
||||
@@ -92,4 +96,9 @@ public class ExtensionsFragment extends MvpFragment< ExtensionsView, ExtensionsP
|
||||
mMsgContainer.setVisibility( hasMsg ? View.VISIBLE : View.GONE );
|
||||
mMsgCounter.setText( amount > MAX_DISPLAY_MSG_AMOUNT ? getString( R.string.module_ext_str_dots ) : String.valueOf( amount ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderUserInfo(UserInfo userInfo) {
|
||||
Logger.d(TAG, "renderUserInfo: " + userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,36 @@
|
||||
package com.mogo.module.extensions;
|
||||
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.module.extensions.net.UserInfoNetApiServices;
|
||||
import com.mogo.module.extensions.userinfo.UserInfo;
|
||||
import com.mogo.module.extensions.userinfo.UserInfoConstant;
|
||||
import com.mogo.module.extensions.userinfo.UserInfoResponse;
|
||||
import com.mogo.module.extensions.utils.ExtensionsConfig;
|
||||
import com.mogo.module.extensions.weather.Phenomena;
|
||||
import com.mogo.module.extensions.weather.WeatherCallback;
|
||||
import com.mogo.module.extensions.weather.WeatherInfo;
|
||||
import com.mogo.module.extensions.weather.WeatherModel;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.network.IMogoNetwork;
|
||||
import com.mogo.service.statusmanager.IMogoMsgCenter;
|
||||
import com.mogo.service.statusmanager.IMogoMsgCenterListener;
|
||||
import com.mogo.utils.digest.DigestUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.auto.platform.util.DeviceUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.SingleObserver;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
@@ -29,9 +48,13 @@ public class ExtensionsPresenter extends Presenter< ExtensionsView > implements
|
||||
|
||||
private IMogoMsgCenter mMsgCenter;
|
||||
|
||||
private IMogoNetwork mNetWork;
|
||||
|
||||
public ExtensionsPresenter( ExtensionsView view ) {
|
||||
super( view );
|
||||
mWeatherModel = new WeatherModel( getContext() );
|
||||
mNetWork =
|
||||
((IMogoServiceApis) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(view.getContext())).getNetworkApi();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,6 +88,10 @@ public class ExtensionsPresenter extends Presenter< ExtensionsView > implements
|
||||
@Override
|
||||
public void onResume( @NonNull LifecycleOwner owner ) {
|
||||
super.onResume( owner );
|
||||
if(ExtensionsConfig.needRequestUserInfo()){
|
||||
// 相当于每次onResume都会请求一下个人信息,目的是能够相对及时的同步手机端的个人信息修改
|
||||
requestUserInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,4 +109,49 @@ public class ExtensionsPresenter extends Presenter< ExtensionsView > implements
|
||||
mMsgCenter.unregisterMsgCenterListener( this );
|
||||
}
|
||||
}
|
||||
|
||||
private UserInfo userInfo;
|
||||
public void requestUserInfo() {
|
||||
Map<String, String> params = new ArrayMap<>();
|
||||
params.put("sn", DeviceUtil.getSn());
|
||||
params.put("source", "2");
|
||||
String sign = createSign(params, "JGqZw9");
|
||||
params.put("sig", sign);
|
||||
mNetWork.create(UserInfoNetApiServices.class, UserInfoConstant.getUserInfoBaseUrl()).requestUserInfo(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<UserInfoResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(UserInfoResponse userInfoBaseResponse) {
|
||||
userInfo = userInfoBaseResponse.getResult();
|
||||
Logger.d(TAG, "获取个人信息成功: " + userInfo);
|
||||
mView.renderUserInfo(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
e.printStackTrace();
|
||||
Logger.e(TAG, e, "获取个人信息失败==");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String createSign(Map<String, String> map, String salt) {
|
||||
try {
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
queryString.append(entry.getKey())
|
||||
.append("=")
|
||||
.append(entry.getValue())
|
||||
.append("&");
|
||||
}
|
||||
queryString.append("key=").append(DigestUtils.shaHex(salt));
|
||||
return DigestUtils.shaHex(queryString.toString()).toUpperCase();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Logger.e(TAG, e, "createSign()");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.module.extensions;
|
||||
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.module.extensions.userinfo.UserInfo;
|
||||
import com.mogo.module.extensions.weather.WeatherInfo;
|
||||
|
||||
/**
|
||||
@@ -27,4 +28,10 @@ public interface ExtensionsView extends IView {
|
||||
* @param amount 消息数量
|
||||
*/
|
||||
void renderMsgInfo( boolean hasMsg, int amount );
|
||||
|
||||
/**
|
||||
* 刷新个人信息
|
||||
* @param userInfo 个人信息
|
||||
*/
|
||||
void renderUserInfo(UserInfo userInfo);
|
||||
}
|
||||
|
||||
@@ -553,9 +553,4 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
|
||||
// 30s 后无论成功与否,停止动画
|
||||
mUploadFrameAnimHandler.sendEmptyMessageDelayed( MSG_STOP_ANIM, 30_000 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUserInfo( UserInfo userInfo ) {
|
||||
Logger.d( TAG, "刷新用户信息: " + userInfo );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +65,6 @@ public class EntrancePresenter extends Presenter<EntranceView> {
|
||||
private String mVoiceCmdType; //一级命令
|
||||
private String mVoiceCmdShareType; //对某些一级命令里面细分的类型做处理
|
||||
private IMogoStatusManager mStatusManager;
|
||||
private IMogoNetwork mNetWork;
|
||||
|
||||
private UserInfo userInfo = null;
|
||||
|
||||
public EntrancePresenter(Context context, EntranceView view,
|
||||
IMogoAuthorizeModuleManager authorizeModuleManager) {
|
||||
@@ -79,8 +76,6 @@ public class EntrancePresenter extends Presenter<EntranceView> {
|
||||
mogoIntentManager = apis.getIntentManagerApi();
|
||||
mIMogoAuthorizeModuleManager = authorizeModuleManager;
|
||||
mStatusManager = apis.getStatusManagerApi();
|
||||
mNetWork = apis.getNetworkApi();
|
||||
|
||||
|
||||
registerUnWake();
|
||||
registerAwakeVoice();
|
||||
@@ -100,9 +95,6 @@ public class EntrancePresenter extends Presenter<EntranceView> {
|
||||
@Override
|
||||
public void onResume(@NonNull LifecycleOwner owner) {
|
||||
super.onResume(owner);
|
||||
if (ExtensionsConfig.needRequestUserInfo() && userInfo == null) {
|
||||
requestUserInfo();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,48 +407,4 @@ public class EntrancePresenter extends Presenter<EntranceView> {
|
||||
AIAssist.getInstance(mContext).unregisterUnWakeupCommand(ExtensionsModuleConst.UPLOAD_TRAFFIC_CHECK);
|
||||
AIAssist.getInstance(mContext).unregisterUnWakeupCommand(ExtensionsModuleConst.UPLOAD_ROAD_CLOSURE);
|
||||
}
|
||||
|
||||
public void requestUserInfo() {
|
||||
Map<String, String> params = new ArrayMap<>();
|
||||
params.put("sn", DeviceUtil.getSn());
|
||||
params.put("source", "2");
|
||||
String sign = createSign(params, "JGqZw9");
|
||||
params.put("sig", sign);
|
||||
mNetWork.create(UserInfoNetApiServices.class, UserInfoConstant.getUserInfoBaseUrl()).requestUserInfo(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<UserInfoResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(UserInfoResponse userInfoBaseResponse) {
|
||||
userInfo = userInfoBaseResponse.getResult();
|
||||
Logger.d(TAG, "获取个人信息成功: " + userInfo);
|
||||
mView.refreshUserInfo(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
e.printStackTrace();
|
||||
Logger.e(TAG, e, "获取个人信息失败==");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String createSign(Map<String, String> map, String salt) {
|
||||
try {
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
queryString.append(entry.getKey())
|
||||
.append("=")
|
||||
.append(entry.getValue())
|
||||
.append("&");
|
||||
}
|
||||
queryString.append("key=").append(DigestUtils.shaHex(salt));
|
||||
return DigestUtils.shaHex(queryString.toString()).toUpperCase();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Logger.e(TAG, e, "createSign()");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,4 @@ import com.mogo.module.extensions.userinfo.UserInfo;
|
||||
* 描述
|
||||
*/
|
||||
public interface EntranceView extends IView {
|
||||
|
||||
void refreshUserInfo(UserInfo userInfo);
|
||||
|
||||
}
|
||||
|
||||
@@ -95,4 +95,19 @@ public class UserInfo {
|
||||
public void setActiveTime(String activeTime) {
|
||||
this.activeTime = activeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"userId='" + userId + '\'' +
|
||||
", phone='" + phone + '\'' +
|
||||
", displayName='" + displayName + '\'' +
|
||||
", additionalOne=" + additionalOne +
|
||||
", headImgurl='" + headImgurl + '\'' +
|
||||
", ownerAuthState=" + ownerAuthState +
|
||||
", score=" + score +
|
||||
", memberLevel='" + memberLevel + '\'' +
|
||||
", activeTime='" + activeTime + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user