com.lzy.okgo.model.Response Java Examples

The following examples show how to use com.lzy.okgo.model.Response. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NoCachePolicy.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example #2
Source File: OkGoCallback.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 请求失败, 响应错误, 数据解析错误等, 都会回调该方法,  UI 线程
 */
@Override
public void onError(Response<String> response) {
    super.onError(response);

    DevLogger.dTag(TAG, "请求失败: " + url);

    if (response != null) {
        onErrorResponse(
                new OkGoResponse.Builder<T>()
                        .setCode(response.code() + "")
                        .setMessage(response.message())
                        .setOriginal(response.body())
                        .setException(response.getException())
                        .build()
        );
    } else {
        onErrorResponse(
                new OkGoResponse.Builder<T>()
                        .setCode(Integer.MAX_VALUE + "")
                        .setMessage("response is null")
                        .setException(new OkGoException("response is null"))
                        .build()
        );
    }
}
 
Example #3
Source File: PushDatamanger.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void pushTransactionRetJson(PackedTransaction body) {
    HttpUtils.postRequest(BaseUrl.HTTP_push_transaction, this, mGson.toJson(body), new JsonCallback<ResponseBean>() {
        @Override
        public void onSuccess(final Response<ResponseBean> response) {
            if (ShowDialog.dialog != null) {
                ShowDialog.dissmiss();
            }
            if (response.body().code == 0) {
                PushSuccessBean.DataBeanX dataBeanX = (PushSuccessBean.DataBeanX) JsonUtil.parseStringToBean(mGson.toJson(response.body().data), PushSuccessBean.DataBeanX.class);
                mCallback.getResult("transaction_id=" + dataBeanX.getTransaction_id());
            } else {
                ToastUtils.showLongToast(response.body().message);
                mCallback.getResult("ERROR:" + response.body().data);
            }
        }
    });
}
 
Example #4
Source File: NoneCacheRequestPolicy.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
@Override
    public void onError(final Response<T> error) {
        if (mCallback != null) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callbackOnError(error);
                    callbackOnFinish();
//                    mCallback.onError(error);
//                    mCallback.onFinish();
                }
            });
        }
//        runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//                mCallback.onError(error);
//                mCallback.onFinish();
//            }
//        });
    }
 
Example #5
Source File: EosDataManger.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void getRequreKey(GetRequiredKeys getRequiredKeys) {

        HttpUtils.postRequest(BaseUrl.HTTP_get_required_keys, this, mGson.toJson(getRequiredKeys), new JsonCallback<ResponseBean>() {
            @Override
            public void onSuccess(Response<ResponseBean> response) {
                if (response.body().code == 0) {
                    RequreKeyResult requreKeyResult = (RequreKeyResult) JsonUtil.parseStringToBean(mGson.toJson(response.body().data), RequreKeyResult.class);
                    EosPrivateKey eosPrivateKey = new EosPrivateKey(PublicAndPrivateKeyUtils.getPrivateKey(requreKeyResult.getRequired_keys().get(0), userpassword));
                    txnBeforeSign.sign(eosPrivateKey, new TypeChainId(mChainInfoBean.getChain_id()));
                    pushTransactionRetJson(new PackedTransaction(txnBeforeSign));
                } else {
                    if (ShowDialog.dialog != null) {
                        ShowDialog.dissmiss();
                    }
                    ToastUtils.showLongToast(response.body().message);
                }
            }
        });

    }
 
Example #6
Source File: RedPacketPresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void sendRedPacketData(String account, String amount, String packetCount, String type) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("uid", MyApplication.getInstance().getUserBean().getWallet_uid());
    hashMap.put("account", account);
    hashMap.put("amount", amount);
    hashMap.put("packetCount", packetCount);
    hashMap.put("type", type);//资产类型 0 oct 1 eos 2 其他
    HttpUtils.postRequest(BaseUrl.HTTP_send_red_packet, mContext, hashMap, new JsonCallback<ResponseBean<SendRedPacketBean.DataBean>>() {
        @Override
        public void onSuccess(Response<ResponseBean<SendRedPacketBean.DataBean>> response) {
            if (response.body().code == 0) {
                view.sendRedPacketDataHttp(response.body().data);
            } else {
                view.getDataHttpFail(response.body().message);
            }
        }
    });
}
 
Example #7
Source File: NoneCacheRequestPolicy.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            if (cacheEntity != null) {
                Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
                mCallback.onCacheSuccess(success);
                mCallback.onFinish();
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example #8
Source File: DefaultCachePolicy.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
@Override
    public void onError(final Response<T> error) {
        if (mCallback != null) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callbackOnError(error);
                    callbackOnFinish();
//                    mCallback.onError(error);
//                    mCallback.onFinish();
                }
            });
        }
//        runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//                mCallback.onError(error);
//                mCallback.onFinish();
//            }
//        });
    }
 
Example #9
Source File: DefaultCachePolicy.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onAnalysisResponse(final Call call, final okhttp3.Response response) {
    if (response.code() != 304) return false;

    if (cacheEntity == null) {
        final Response<T> error = Response.error(true, call, response, CacheException.NON_AND_304(request.getCacheKey()));
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mCallback.onError(error);
                mCallback.onFinish();
            }
        });
    } else {
        final Response<T> success = Response.success(true, cacheEntity.getData(), call, response);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mCallback.onCacheSuccess(success);
                mCallback.onFinish();
            }
        });
    }
    return true;
}
 
Example #10
Source File: PushDatamanger.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void getabi_json_to_bin() {
    JsonToBinRequest jsonToBinRequest = new JsonToBinRequest(contract, action, message.replaceAll("\\r|\\n", ""));
    HttpUtils.postRequest(BaseUrl.HTTP_get_abi_json_to_bin, this, mGson.toJson(jsonToBinRequest), new JsonCallback<ResponseBean>() {
        @Override
        public void onSuccess(Response<ResponseBean> response) {
            if (response.body().code == 0) {
                mJsonToBeanResultBean = (JsonToBeanResultBean) JsonUtil.parseStringToBean(mGson.toJson(response.body().data), JsonToBeanResultBean.class);
                txnBeforeSign = createTransaction(contract, action, mJsonToBeanResultBean.getBinargs(), permissions, mChainInfoBean);
                //扫描钱包列出所有可用账号的公钥
                List<String> pubKey = PublicAndPrivateKeyUtils.getActivePublicKey();

                getRequreKey(new GetRequiredKeys(txnBeforeSign, pubKey));
            } else {
                if (ShowDialog.dialog != null) {
                    ShowDialog.dissmiss();
                }
                ToastUtils.showLongToast(response.body().message);
                mCallback.getResult(new Gson().toJson(response.body().data));
            }
        }
    });
}
 
Example #11
Source File: ChangeMemoryPresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void getAccounteData(String account) {

        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("name", account);
        HttpUtils.postRequest(BaseUrl.HTTP_eos_get_account, mContext, hashMap, new JsonCallback<ResponseBean<AccountDetailsBean>>() {
            @Override
            public void onSuccess(Response<ResponseBean<AccountDetailsBean>> response) {
                if (response.body().code == 0) {
                    view.getAccountDetailsDataHttp(response.body().data);
                } else {
                    view.getDataHttpFail(response.body().message);
                }
            }
        });


    }
 
Example #12
Source File: PushDatamanger.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void getChainInfo() {
    HttpUtils.getRequets(BaseUrl.HTTP_get_chain_info, this, new HashMap<String, String>(), new JsonCallback<ResponseBean>() {
        @Override
        public void onSuccess(Response<ResponseBean> response) {
            if (response.body().code == 0) {
                mChainInfoBean = (EosChainInfo) JsonUtil.parseStringToBean(mGson.toJson(response.body().data), EosChainInfo.class);
                getabi_json_to_bin();
            } else {
                if (ShowDialog.dialog != null) {
                    ShowDialog.dissmiss();
                }
                ToastUtils.showLongToast(response.body().message);
                mCallback.getResult(new Gson().toJson(response.body().data));
            }
        }
    });
}
 
Example #13
Source File: MemoryPresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void getAccountInfoData(String accountname) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("name", accountname);
    HttpUtils.postRequest(BaseUrl.HTTP_get_chain_account_info, mContext, hashMap, new JsonCallback<ResponseBean<BlockChainAccountInfoBean.DataBean>>() {
        @Override
        public void onSuccess(Response<ResponseBean<BlockChainAccountInfoBean.DataBean>> response) {
            if (response.body().code == 0) {
                view.getBlockchainAccountInfoDataHttp(response.body().data);
            } else {
                view.getDataHttpFail(response.body().message);
            }
        }
    });


}
 
Example #14
Source File: CreateAccountPresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void postEosAccountData(String eosAccountName ,String owner_key, String active_key) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("uid", MyApplication.getInstance().getUserBean().getWallet_uid());
    hashMap.put("eosAccountName", eosAccountName);
    hashMap.put("ownerKey", owner_key);
    hashMap.put("activeKey", active_key);
    HttpUtils.postRequest(BaseUrl.HTTP_add_new_eos, mContext, hashMap, new JsonCallback<ResponseBean<String>>() {
        @Override
        public void onSuccess(Response<ResponseBean<String>> response) {
            if (response.body().code == 0) {
                view.postEosAccountDataHttp();
            } else {
                view.getDataHttpFail(response.body().message);
            }
        }
    });
}
 
Example #15
Source File: FirstCacheRequestPolicy.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            if (cacheEntity != null) {
                Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
                mCallback.onCacheSuccess(success);
            }
            requestNetworkAsync();
        }
    });
}
 
Example #16
Source File: RequestFailedCachePolicy.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example #17
Source File: NoCachePolicy.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
@Override
    public void onError(final Response<T> error) {
        if (mCallback != null) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callbackOnError(error);
                    callbackOnFinish();
//                    if (mCallback != null) {
//                        mCallback.onError(error);
//                        mCallback.onFinish();
//                    }
                }
            });
        }
    }
 
Example #18
Source File: TestActivity.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@OnClick(R.id.btn2)
public void btn2(View view) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Call<JSONObject> adapt = OkGo.<JSONObject>get(Urls.URL_JSONOBJECT).adapt();
                Response<JSONObject> response = adapt.execute();
                System.out.println("body " + response.body());
                Throwable exception = response.getException();
                if (exception != null) exception.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}
 
Example #19
Source File: OtherLoginTypePresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void bindQQ(String openid, String name, String avatar) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("uid", MyApplication.getInstance().getUserBean().getWallet_uid());
    hashMap.put("openid", openid);
    hashMap.put("name", name);
    hashMap.put("avatar", avatar);
    HttpUtils.postRequest(BaseUrl.HTTP_bindQQ, mContext, hashMap, new JsonCallback<ResponseBean<String>>() {
        @Override
        public void onSuccess(Response<ResponseBean<String>> response) {
            if (response.body().code == 0) {
                view.bindOtherLoginDataHttp();
            } else {
                view.getDataHttpFail(response.body().message);
            }
        }
    });
}
 
Example #20
Source File: AppUpdateActivity.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void initData() {

    HttpUtils.getRequets(BaseUrl.HTTP_get_app_info, AppUpdateActivity.this, new HashMap<String, String>(), new JsonCallback<ResponseBean<UpdateAppBean.DataBean>>() {
        @Override
        public void onSuccess(Response<ResponseBean<UpdateAppBean.DataBean>> response) {
            if (response.body().code == 0) {
                if (Integer.parseInt(response.body().data.getVersionCode()) > AppUtil.getAppVersionCode(AppUpdateActivity.this)) {
                    mIsNewVersion.setText(R.string.find_new_app);
                    mIsNewVersion.setTextColor(getResources().getColor(R.color.red_packet_color));
                } else {
                    mIsNewVersion.setText(R.string.no_new_app);
                    mIsNewVersion.setTextColor(getResources().getColor(R.color.txt_color));
                }
            }
        }
    });
}
 
Example #21
Source File: NoCachePolicy.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
@Override
    public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
        mCallback = callback;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                callbackOnStart(request);
//                if (mCallback != null) {
//                    mCallback.onStart(request);
//                }
                try {
                    prepareRawCall();
                } catch (Throwable throwable) {
                    Response<T> error = Response.error(false, rawCall, null, throwable);
                    callbackOnError(error);
//                    mCallback.onError(error);
                    return;
                }
                requestNetworkAsync();
            }
        });
    }
 
Example #22
Source File: DefaultCachePolicy.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example #23
Source File: MapAccountPresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setMianAccountData(String eosAccountName) {

        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", MyApplication.getInstance().getUserBean().getWallet_uid());
        hashMap.put("eosAccountName", eosAccountName);
        HttpUtils.postRequest(BaseUrl.HTTP_set_mian_account, mContext, hashMap, new JsonCallback<ResponseBean<String>>() {
            @Override
            public void onSuccess(Response<ResponseBean<String>> response) {
                if (response.body().code == 0) {
                    view.setMainAccountHttp();
                } else {
                    view.getDataHttpFail(response.body().message);
                }
            }
        });
    }
 
Example #24
Source File: RequestFailedCachePolicy.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
@Override
public void onError(final Response<T> error) {

    if (cacheEntity != null) {
        final Response<T> cacheSuccess = Response.success(true, cacheEntity.getData(), error.getRawCall(), error.getRawResponse());
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mCallback.onCacheSuccess(cacheSuccess);
                mCallback.onFinish();
            }
        });
    } else {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mCallback.onError(error);
                mCallback.onFinish();
            }
        });
    }
}
 
Example #25
Source File: DappDatamanger.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void getRequreKey(GetRequiredKeys getRequiredKeys) {

        HttpUtils.postRequest(BaseUrl.HTTP_get_required_keys, this, mGson.toJson(getRequiredKeys), new JsonCallback<ResponseBean>() {
            @Override
            public void onSuccess(Response<ResponseBean> response) {
                if (response.body().code == 0) {
                    RequreKeyResult requreKeyResult = (RequreKeyResult) JsonUtil.parseStringToBean(mGson.toJson(response.body().data), RequreKeyResult.class);
                    EosPrivateKey eosPrivateKey = new EosPrivateKey(PublicAndPrivateKeyUtils.getPrivateKey(requreKeyResult.getRequired_keys().get(0), userpassword));
                    txnBeforeSign.sign(eosPrivateKey, new TypeChainId(mChainInfoBean.getChain_id()));
                    pushTransactionRetJson(new PackedTransaction(txnBeforeSign));
                } else {
                    if (ShowDialog.dialog != null) {
                        ShowDialog.dissmiss();
                    }
                    ToastUtils.showLongToast(response.body().message);
                    mCallback.erroMsg(response.body().data.toString());
                }
            }
        });

    }
 
Example #26
Source File: AskansDatamanger.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void getRequreKey(GetRequiredKeys getRequiredKeys) {
    HttpUtils.postRequest(BaseUrl.HTTP_get_required_keys, this, mGson.toJson(getRequiredKeys), new JsonCallback<ResponseBean>() {
        @Override
        public void onSuccess(Response<ResponseBean> response) {
            if (response.body().code == 0) {
                RequreKeyResult requreKeyResult = (RequreKeyResult) JsonUtil.parseStringToBean(mGson.toJson(response.body().data), RequreKeyResult.class);
                EosPrivateKey eosPrivateKey = new EosPrivateKey(PublicAndPrivateKeyUtils.getPrivateKey(requreKeyResult.getRequired_keys().get(0), userpassword));
                txnBeforeSign.sign(eosPrivateKey, new TypeChainId(mChainInfoBean.getChain_id()));
                pushTransactionRetJson(new PackedTransaction(txnBeforeSign));
            } else {
                if (ShowDialog.dialog != null) {
                    ShowDialog.dissmiss();
                }
                ToastUtils.showLongToast(response.body().message);
            }
        }
    });
}
 
Example #27
Source File: FirstCacheRequestPolicy.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(final Response<T> success) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onSuccess(success);
            mCallback.onFinish();
        }
    });
}
 
Example #28
Source File: OtherLoginTypePresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void unbindQQ() {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("uid", MyApplication.getInstance().getUserBean().getWallet_uid());
    HttpUtils.postRequest(BaseUrl.HTTP_unbindQQ, mContext, hashMap, new JsonCallback<ResponseBean<String>>() {
        @Override
        public void onSuccess(Response<ResponseBean<String>> response) {
            if (response.body().code == 0) {
                view.unBindOtherLoginDataHttp();
            } else {
                view.getDataHttpFail(response.body().message);
            }
        }
    });
}
 
Example #29
Source File: NoCachePolicy.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@Override
public void onError(final Response<T> error) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onError(error);
            mCallback.onFinish();
        }
    });
}
 
Example #30
Source File: ContinueRedpacketPresenter.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void getRedPacketDetailsData(String redpacket_id) {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("id", redpacket_id);
    HttpUtils.postRequest(BaseUrl.getHTTP_get_red_packet_details_history, mContext, hashMap, new JsonCallback<ResponseBean<RedPacketDetailsBean.DataBean>>() {
        @Override
        public void onSuccess(Response<ResponseBean<RedPacketDetailsBean.DataBean>> response) {
            if (response.body().code == 0) {
                view.getRedPacketDetailsDataHttp(response.body().data);
            } else {
                view.getDataHttpFail(response.body().message);
            }
        }
    });
}