审查日期:2017-08-10
审查人员:鸣人
代码文件:SystemSettingActivity(系统设置页面)
一、代码描述
这段代码为系统设置页面
二、代码规范
注:1、注释名称过少
2、屏蔽代码很多,未删除
3、命名还不够直观
public voidgetUserPush() {
//json里面的字段
//要闻推送、编辑精选、自选股重大事件、VIP参考推送、全部推送、夜间是否推送
finalString[] nameList = {"importantNewsPush","editSelectPush","mystockImportantEventPush","vipInsiderPush","freeInsiderPush","nightClosePush"};
finalMap nameWithValue =newHashMap<>(6);
finalString userId = SharedPreferencesUtil.readString(this, SpConstant.FILE_USER_INFO, SpConstant.KEY_USER_ID);
String token = SharedPreferencesUtil.readString(this, SpConstant.FILE_USER_INFO, SpConstant.KEY_TOKEN);
Log.i("c1117","token:"+ token);
newHttpClient().createService(PushNetService.class)
.get_setting_info(userId, token)
.enqueue(newCallbackAdapter(this) {
@Override
public voidonMyResponse(Call call, Response response, String errorCode, String data, String msg) {
Log.i(TAG,"get system setting errorCode:"+ errorCode +", data: "+ data +", msg: "+ msg);
if("0".equals(errorCode)) {
try{
// json格式: {"error_code":"0","data":{"userId":"98272","importantNewsPush":"1","mystockImportantEventPush":"1","editSelectPush":"0","vipInsiderPush":"1"},"msg":""}
JSONObject jsonObject =newJSONObject(data);
for(String aNameList :nameList) {
nameWithValue.put(aNameList, jsonObject.get(aNameList).toString());
}
}catch(Exception e) {
e.printStackTrace();
}
Log.i(TAG,"name with value: "+nameWithValue);
booleanvalue2 ="1".equals(nameWithValue.get(nameList[0]));
if(mSwitchView2.isOpened() != value2) {
mSwitchView2.toggleSwitch(value2);
}
booleanvalue3 ="1".equals(nameWithValue.get(nameList[1]));
if(mSwitchView3.isOpened() != value3) {
mSwitchView3.toggleSwitch(value3);
}
booleanvalue4 ="1".equals(nameWithValue.get(nameList[2]));
if(mSwitchView4.isOpened() != value4) {
mSwitchView4.toggleSwitch(value4);
}
booleanvalue5;
//不是VIP
if(!isVip) {
value5 =false;
mSwitchView5.toggleSwitch(false);
}else{
value5 ="1".equals(nameWithValue.get(nameList[3]));
if(mSwitchView5.isOpened() != value5) {
mSwitchView5.toggleSwitch(value5);
}
}
booleanvalue6 ="1".equals(nameWithValue.get(nameList[4]));
if(mSwitchView6.isOpened() != value6) {
mSwitchView6.toggleSwitch(value6);
}
booleanvalue7 ="1".equals(nameWithValue.get(nameList[5]));
if(mSwitchView7.isOpened() != value7) {
mSwitchView7.toggleSwitch(value7);
}
//保存本地数据
SharedPreferencesUtil.save(SystemSettingActivity.this, SpConstant.FILE_SYSTEM_SETTING,userId+"_"+ SpConstant.KEY_SEND_LOCAL_SETTING,true);
SharedPreferencesUtil.save(SystemSettingActivity.this, SpConstant.FILE_SYSTEM_SETTING,userId+"_"+ SpConstant.KEY_SEND_NEWS, value2);
SharedPreferencesUtil.save(SystemSettingActivity.this, SpConstant.FILE_SYSTEM_SETTING,userId+"_"+ SpConstant.KEY_SEND_CHOICE, value3);
SharedPreferencesUtil.save(SystemSettingActivity.this, SpConstant.FILE_SYSTEM_SETTING,userId+"_"+ SpConstant.KEY_SEND_IMPORT, value4);
SharedPreferencesUtil.save(SystemSettingActivity.this, SpConstant.FILE_SYSTEM_SETTING,userId+"_"+ SpConstant.KEY_SEND_VIP, value5);
SharedPreferencesUtil.save(SystemSettingActivity.this, SpConstant.FILE_SYSTEM_SETTING,userId+"_"+ SpConstant.KEY_SEND_All, value6);
SharedPreferencesUtil.save(SystemSettingActivity.this, SpConstant.FILE_SYSTEM_SETTING,userId+"_"+ SpConstant.KEY_SEND_NIGHT, value7);
}
}
@Override
public voidonMyFailure(Call call, Throwable t) {
Log.i(TAG, t.getMessage(), t);
}
});
}
三、注释填充
注:1、相同的方法可以提取出来,定义成一个方法
四、逻辑调整
(无)