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";
}
}
网友评论