private void getInfoFromServer() { DescriptionCallBack callBack = new DescriptionCallBack(this, getActivity()); Call<DescriptionData> call = LykkeApplication_.getInstance() .getRestApi() .getDescription( Constants.PART_AUTHORIZATION + userPref.authToken().get(), Constants.USER_AGENT, assetPair.getId()); call.enqueue(callBack); Call<OneAssetPairData> callAssetPair = LykkeApplication_.getInstance() .getRestApi() .getAssetPair(Constants.USER_AGENT, assetPair.getId()); callAssetPair.enqueue( new Callback<OneAssetPairData>() { @Override public void onResponse(Call<OneAssetPairData> call, Response<OneAssetPairData> response) { assetPair = response.body().getResult().getAssetPairs(); initViews(); } @Override public void onFailure(Call<OneAssetPairData> call, Throwable t) {} }); }
private void getRates() { if (isShouldContinue) { AssetPairRateCallBack callBack = new AssetPairRateCallBack(this, getActivity()); Call<RateData> call = LykkeApplication_.getInstance() .getRestApi() .getAssetPairsRate( Constants.PART_AUTHORIZATION + userPref.authToken().get(), Constants.USER_AGENT, assetPair.getId()); call.enqueue(callBack); } }
private void initViews() { if (assetPair.getInverted()) { accurancy = assetPair.getInvertedAccuracy(); mainName = assetPair.getQuotingAssetId(); subName = assetPair.getBaseAssetId(); } else { accurancy = assetPair.getAccuracy(); mainName = assetPair.getBaseAssetId(); subName = assetPair.getQuotingAssetId(); } actionBar.setTitle(mainName + "/" + subName); btnBuy.setText( String.format(getString(R.string.buy_rate), mainName, subName) + " " + LykkeUtils.getStriped(accurancy, price)); btnSell.setText( String.format(getString(R.string.sell_at_price), mainName, subName) + " " + LykkeUtils.getStriped(accurancy, bid)); }
@AfterViews public void afterViews() { assetPair = (AssetPair) getArguments().getSerializable(Constants.EXTRA_ASSET_PAIR); price = BigDecimal.valueOf(getArguments().getDouble(Constants.EXTRA_RATE_PRICE)); if (assetPair != null) { if (assetPair.getInverted()) { accurancy = assetPair.getInvertedAccuracy(); if (price.compareTo(BigDecimal.ZERO) != 0) { price = BigDecimal.ONE.divide(price, accurancy, RoundingMode.HALF_EVEN); } mainName = assetPair.getQuotingAssetId(); subName = assetPair.getBaseAssetId(); } else { accurancy = assetPair.getAccuracy(); mainName = assetPair.getBaseAssetId(); subName = assetPair.getQuotingAssetId(); } } actionBar.setTitle(mainName + "/" + subName); if (getArguments().getSerializable(Constants.EXTRA_DESCRIPTION) != null) { if (getArguments().getSerializable(Constants.EXTRA_RATE_PRICE) != null) { price = (BigDecimal) getArguments().getSerializable(Constants.EXTRA_RATE_PRICE); btnBuy.setText( String.format(getString(R.string.buy_rate), mainName, subName) + " " + LykkeUtils.getStriped(accurancy, price)); btnSell.setText( String.format(getString(R.string.sell_at_price), mainName, subName) + " " + LykkeUtils.getStriped(accurancy, price)); } onSuccess(getArguments().getSerializable(Constants.EXTRA_DESCRIPTION)); } else { setUpVisibility(View.VISIBLE, View.GONE); btnBuy.setVisibility(View.GONE); btnSell.setVisibility(View.GONE); getInfoFromServer(); } }
@Override public void onSuccess(Object result) { try { if (getActivity() != null) { if (result instanceof DescriptionResult) { resultData = (DescriptionResult) result; setUpVisibility(View.GONE, View.VISIBLE); btnBuy.setVisibility(View.VISIBLE); btnSell.setVisibility(View.VISIBLE); if (((DescriptionResult) result).getAssetClass() == null) { linearAssetName.setVisibility(View.GONE); viewAssetClass.setVisibility(View.GONE); } else { tvAssetClass.setText(((DescriptionResult) result).getAssetClass()); } if (((DescriptionResult) result).getDescription() == null) { linearDescription.setVisibility(View.GONE); viewDescription.setVisibility(View.GONE); } else { tvDescription.setText(((DescriptionResult) result).getDescription()); } if (((DescriptionResult) result).getIssuerName() == null) { linearIssuerName.setVisibility(View.GONE); viewIssuerName.setVisibility(View.GONE); } else { tvIssuerName.setText(((DescriptionResult) result).getIssuerName()); } if (((DescriptionResult) result).getNumberOfCoins() == null) { linearNumberOfCoins.setVisibility(View.GONE); viewNumberOfCoins.setVisibility(View.GONE); } else { tvNumberOfCoins.setText(((DescriptionResult) result).getNumberOfCoins()); } if (((DescriptionResult) result).getMarketCapitalization() == null) { linearMarketCapitalization.setVisibility(View.GONE); viewMarketCapitalization.setVisibility(View.GONE); } else { tvMarketCapitalization.setText(((DescriptionResult) result).getMarketCapitalization()); } if (((DescriptionResult) result).getAssetDescriptionUrl() == null) { linearDescriptionUrl.setVisibility(View.GONE); viewDescriptionUrl.setVisibility(View.GONE); } else { Spannable s = (Spannable) Html.fromHtml(((DescriptionResult) result).getAssetDescriptionUrl()); for (URLSpan u : s.getSpans(0, s.length(), URLSpan.class)) { s.setSpan( new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, s.getSpanStart(u), s.getSpanEnd(u), 0); } tvDescriptionUrl.setMovementMethod(LinkMovementMethod.getInstance()); tvDescriptionUrl.setLinksClickable(true); tvDescriptionUrl.setText(s); } Resources r = getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, r.getDisplayMetrics()); float pxMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, r.getDisplayMetrics()); linearPop.removeAllViews(); for (int i = 0; i < Integer.parseInt(((DescriptionResult) result).getPopIndex()); i++) { ImageView imageView = new ImageView(getActivity()); imageView.setImageResource(R.drawable.star); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(Math.round(px), Math.round(px)); lp.setMargins(Math.round(pxMargin), 0, Math.round(pxMargin), 0); imageView.setLayoutParams(lp); linearPop.addView(imageView); } if (Integer.parseInt(((DescriptionResult) result).getPopIndex()) == 0) { linearPopularity.setVisibility(View.GONE); } handler.post(run); } else if (result instanceof RateResult) { if (((RateResult) result).getRate() != null && ((RateResult) result).getRate().getAsk() != null && getActivity() != null) { price = BigDecimal.valueOf(((RateResult) result).getRate().getAsk()); if (assetPair.getInverted()) { price = BigDecimal.ONE.divide(price, accurancy, RoundingMode.HALF_EVEN); } btnBuy.setText( String.format(getString(R.string.buy_rate), mainName, subName) + " " + LykkeUtils.getStriped(accurancy, price)); } if (((RateResult) result).getRate() != null && ((RateResult) result).getRate().getBid() != null && getActivity() != null) { bid = BigDecimal.valueOf(((RateResult) result).getRate().getBid()); if (assetPair.getInverted()) { bid = BigDecimal.ONE.divide(bid, accurancy, RoundingMode.HALF_EVEN); } btnSell.setText( String.format(getString(R.string.sell_at_price), mainName, subName) + " " + LykkeUtils.getStriped(accurancy, bid)); } } } } catch (NullPointerException ex) { } }