取消 和 成交

case "offercancel":

mTvType.setText(getResources().getString(R.string.tv_offercancel));

mLayoutEntrustAmount.setVisibility(View.VISIBLE);

if (mTransactions.getGets() !=null &&mTransactions.getPays() !=null) {

String getsValue =mTransactions.getGets().getValue();

String paysValue =mTransactions.getPays().getValue();

String getsToken =mTransactions.getGets().getCurrency() +"_" +mTransactions.getGets().getIssuer();

String paysToken =mTransactions.getPays().getCurrency() +"_" +mTransactions.getPays().getIssuer();

mTvEntrustContent.setText(formatHtml(CaclUtil.formatAmount(paysValue,SCALE), paysToken, CaclUtil.formatAmount(getsValue,SCALE), getsToken));

// 委托价格

        if (mTransactions.getEffects() !=null &&mTransactions.getEffects().getJSONObject(0) !=null) {

String price =mTransactions.getEffects().getJSONObject(0).getString("price");

if (!TextUtils.isEmpty(price) && price.contains(" ")) {

String[] priceArr = price.split(" ");

if (priceArr.length ==2) {

mLayoutValue.setVisibility(View.VISIBLE);

mTvValue.setText(priceArr[0]);

mTvValueToken.setText(priceArr[1]);

}

}

}

}else {

mTvPayAmountNone.setText("---");

mTvPayAmountNone.setVisibility(View.VISIBLE);

}

mTvAmount.setTextColor(getResources().getColor(R.color.common_green));

mFrom = currentAddr;

mTvFrom.setText(mFrom);

break;



case "offereffect":

mTvType.setText(getResources().getString(R.string.tv_offereffect));

mFrom =mTransactions.getCounterparty();

mTvFrom.setText(mFrom);

getsCur =mTransactions.getGets().getCurrency() +"_" +mTransactions.getGets().getIssuer();

paysCur =mTransactions.getPays().getCurrency() +"_" +mTransactions.getPays().getIssuer();

String getsAmount1 ="0";

String paysAmount1 ="0";

if (mTransactions.getEffects() !=null) {

mEffects =mTransactions.getEffects();

int index =0;

for (int i =mEffects.size() -1; i >=0; i--) {

Log.i("1111222","jinlai");

JSONObject effect =mEffects.getJSONObject(i);

String effectType = effect.getString("effect");

if (!TextUtils.equals(effectType,"offer_cancelled") && !TextUtils.equals(effectType,"offer_created")) {

// 本机帐号记录前置

                JSONObject counterparty = effect.getJSONObject("counterparty");

if (counterparty !=null) {

String addr = counterparty.getString("account");

if (TextUtils.equals(addr, currentAddr)) {

while (index index) {

JSONObject jsonObject =mEffects.getJSONObject(index);

mEffects.set(index, effect);

mEffects.set(i, jsonObject);

effect =mEffects.getJSONObject(i);

index++;

break;

}

}

}

pays = effect.getJSONObject("paid");

gets = effect.getJSONObject("got");

if (pays !=null && gets !=null) {

String currency = pays.getString("currency") +"_" + pays.getString("issuer");

String paysCount = pays.getString("value");

if (TextUtils.equals(currency, paysCur)) {

paysAmount1 = CaclUtil.add(paysAmount1, paysCount);

Log.i("pay", paysAmount1);

}

currency = gets.getString("currency") +"_" + gets.getString("issuer");

String getsCount = gets.getString("value");

if (TextUtils.equals(currency, getsCur)) {

getsAmount1 = CaclUtil.add(getsAmount1, getsCount);

Log.i("pay11", getsAmount1);

}

}else {

mEffects.remove(i);

}

}

}

if (mEffects !=null &&mEffects.size() >0) {

mRecyclerView.setVisibility(View.VISIBLE);

}

// 成交

        if (!TextUtils.isEmpty(getsAmount1) && CaclUtil.compare(getsAmount1,"0") !=0 && !TextUtils.isEmpty(paysAmount1) && CaclUtil.compare(paysAmount1,"0") !=0) {

mLayoutTurnoverAmount.setVisibility(View.VISIBLE);

mTvTurnoverContent.setText(formatHtml(CaclUtil.formatAmount(paysAmount1,SCALE), paysCur, CaclUtil.formatAmount(getsAmount1,SCALE), getsCur));

// 成交价格

            String price;

String token;

if (TextUtils.equals(KEY_CNY, getsCur)) {

price = amountRatio(getsAmount1, paysAmount1);

token = WConstant.CURRENCY_CNT;

}else if (TextUtils.equals(KEY_CNY, paysCur)) {

price = amountRatio(paysAmount1, getsAmount1);

token = WConstant.CURRENCY_CNT;

}else if (TextUtils.equals(KEY_SWT, getsCur)) {

price = amountRatio(getsAmount1, paysAmount1);

token = WConstant.CURRENCY_SWTC;

}else {

price = amountRatio(paysAmount1, getsAmount1);

token = paysCur.split("_")[0];

}

if (!TextUtils.equals("0", price)) {

mLayoutTurnoverValue.setVisibility(View.VISIBLE);

mTvTurnoverValue.setText(CaclUtil.formatAmount(price,6));

mTvTurnoverValueToken.setText(token);

}

}

// 委托

        String getsValue =mTransactions.getGets().getValue();

String paysValue =mTransactions.getPays().getValue();

mLayoutEntrustAmount.setVisibility(View.VISIBLE);

mTvEntrustContent.setText(formatHtml(CaclUtil.formatAmount(paysValue,SCALE), paysCur, CaclUtil.formatAmount(getsValue,SCALE), getsCur));

// 委托价格

        String price;

String token;

if (TextUtils.equals(KEY_CNY, getsCur)) {

price = amountRatio(getsValue, paysValue);

token = WConstant.CURRENCY_CNT;

}else if (TextUtils.equals(KEY_CNY, paysCur)) {

price = amountRatio(paysValue, getsValue);

token = WConstant.CURRENCY_CNT;

}else if (TextUtils.equals(KEY_SWT, getsCur)) {

price = amountRatio(getsValue, paysValue);

token = WConstant.CURRENCY_SWTC;

}else {

price = amountRatio(paysValue, getsValue);

token = paysCur.split("_")[0];

}

if (!TextUtils.equals("0", price)) {

mLayoutValue.setVisibility(View.VISIBLE);

mTvValue.setText(CaclUtil.formatAmount(price,6));

mTvValueToken.setText(token);

}

}

break;


public String amountRatio(String pays, String gets) {

if (!TextUtils.isEmpty(pays) && !TextUtils.isEmpty(gets) && !TextUtils.equals("0", pays) && !TextUtils.equals("0", gets)) {

BigDecimal bi1 =new BigDecimal(pays);

BigDecimal bi2 =new BigDecimal(gets);

BigDecimal bi3 = bi1.divide(bi2,6, BigDecimal.ROUND_HALF_UP);

return bi3.stripTrailingZeros().toPlainString();

}else {

return "0";

}

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • private static final StringKEY_CNY = WConstant.CURRENCY_C...
    帅气的昵称lc阅读 1,855评论 0 0
  • 第一行代码-第二版的酷欧天气 首先创建数据库类继承LitePal,用来存储城市数据Province.java p...
    A_Coder阅读 6,372评论 0 0
  • 先Activity的抽象类 BaseActivity [java]view plaincopy /** *Acti...
    Zaker2Magic阅读 4,622评论 0 0
  • 详情页面 packagecom.example.shoppingcar; importandroid.conten...
    ForCrazyLove阅读 3,749评论 0 2
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,188评论 0 10

友情链接更多精彩内容