SystemSettingActivity(review代码4)

审查日期: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、相同的方法可以提取出来,定义成一个方法

四、逻辑调整

(无)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,946评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,452评论 19 139
  • 你的美丽 碎了一地 我的帅气 淹没在了日子里 每天都在努力 拼命的奔走在 寻找幸福的路上 过犹不及 每天都不厌其烦...
    琢玉书生阅读 1,287评论 0 8
  • 亭止阅读 682评论 0 0