Volley接口使用的重构

最近在做手机rom OTA项目,项目不算大但原来的代码耦合比较高,对后期维护不是很好,,设计的好处不用多说增强代码复用、更容易扩展、更容易读懂、更容易维护,索性大刀阔斧逐步进行代码重构、优化,其中对volley的使用也是问题比较多,所以优先重构了下,后续将逐步对各个不合理的地方重构,后面每个项目都会规划思维导图、类图进行设计不在做码农,具体代码如附件,整体设计类图如下(当然画类图的水平还有待提升):





重构前代码:

public void startCheckUpdateTask() {
        // If it is checking for updates, then not allowed to check again.
        if (isCheckingUpdate)
            return;
        // Start checking for updates
        isCheckingUpdate = true;


        // Get the actual ROM Update Server URL
        URI updateServerUri = RequestBuilder.CHECK_UPDATE_VERSION4_URI_JSON;
        UpdatesJsonObjectRequest request;
        try {
            request = new UpdatesJsonObjectRequest(updateServerUri.toASCIIString(), Utils.getUserAgentString(this), CommonUtil.buildUpdateRequest(this), this, this);
            // Set the tag for the request, reuse logging tag
            request.setTag(TAG);
        } catch (JSONException e) {
            Log.e(TAG, "Could not build request", e);
            return;
        }


        ((OTApplication) getApplicationContext()).getQueue().cancelAll(TAG);
        ((OTApplication) getApplicationContext()).getQueue().getCache().clear();
        ((OTApplication) getApplicationContext()).getQueue().add(request);
    }



重构后代码:

 ApiContext.getDefault().getUpdateRequest(this, new ICallback<EntireResponse>() {
            
            @Override
            public void onSuccess(EntireResponse obj) {
              
            }
            
            @Override
            public void onError(String error) {
              
            }
        });


代码下载地址:http://download.csdn.net/download/junjianzhang/9283273

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值