審查日期:2017-08-10
審查人員:鳴人
代碼文件:SystemSettingActivity(系統(tǒng)設(shè)置頁(yè)面)
一秕衙、代碼描述
這段代碼為系統(tǒng)設(shè)置頁(yè)面
二姥敛、代碼規(guī)范
注:1、注釋名稱(chēng)過(guò)少
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);
}
//保存本地?cái)?shù)據(jù)
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伐债、相同的方法可以提取出來(lái),定義成一個(gè)方法
四致开、邏輯調(diào)整
(無(wú))