Add user defined currencies to offers and trades list in market screen

This commit is contained in:
Manfred Karrer 2017-11-10 14:08:29 -05:00
parent a4ac3115e1
commit 5e95e162bf
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
4 changed files with 32 additions and 7 deletions

View file

@ -49,9 +49,11 @@ shared.sell=sell
shared.buying=buying
shared.selling=selling
shared.P2P=P2P
shared.offer=offer
shared.offers=offers
shared.Offer=Offer
shared.openOffers=open offers
shared.trade=trade
shared.trades=trades
shared.openTrades=open trades
shared.dateTime=Date/Time

View file

@ -110,7 +110,9 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
currencyComboBox = new ComboBox<>();
currencyComboBox.setPromptText(Res.get("list.currency.select"));
currencyComboBox.setConverter(GUIUtil.getCurrencyListItemConverter(Res.get("shared.offers"), model.preferences));
currencyComboBox.setConverter(GUIUtil.getCurrencyListItemConverter(Res.get("shared.offer"),
Res.get("shared.offers"),
model.preferences));
Label currencyLabel = new Label(Res.getWithCol("shared.currency"));
HBox currencyHBox = new HBox();

View file

@ -413,7 +413,9 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
currencyComboBox = new ComboBox<>();
currencyComboBox.setPromptText(Res.get("list.currency.select"));
currencyComboBox.setConverter(GUIUtil.getCurrencyListItemConverter(Res.get("shared.trades"), model.preferences));
currencyComboBox.setConverter(GUIUtil.getCurrencyListItemConverter(Res.get("shared.trade"),
Res.get("shared.trades"),
model.preferences));
Pane spacer = new Pane();
HBox.setHgrow(spacer, Priority.ALWAYS);

View file

@ -200,7 +200,7 @@ public class GUIUtil {
}
}
public static StringConverter<CurrencyListItem> getCurrencyListItemConverter(String postFix, Preferences preferences) {
public static StringConverter<CurrencyListItem> getCurrencyListItemConverter(String postFixSingle, String postFixMulti, Preferences preferences) {
return new StringConverter<CurrencyListItem>() {
@Override
public String toString(CurrencyListItem item) {
@ -213,8 +213,10 @@ public class GUIUtil {
return "" + Res.get("list.currency.editList");
default:
String displayString = CurrencyUtil.getNameByCode(code) + " (" + code + ")";
if (preferences.isSortMarketCurrenciesNumerically())
displayString += " - " + item.numTrades + " " + postFix;
if (preferences.isSortMarketCurrenciesNumerically()) {
final int numTrades = item.numTrades;
displayString += " - " + numTrades + " " + (numTrades == 1 ? postFixSingle : postFixMulti);
}
return tradeCurrency.getDisplayPrefix() + displayString;
}
}
@ -247,9 +249,15 @@ public class GUIUtil {
};
}
public static void fillCurrencyListItems(List<TradeCurrency> tradeCurrencyList, ObservableList<CurrencyListItem> currencyListItems, @Nullable CurrencyListItem showAllCurrencyListItem, Preferences preferences) {
Set<TradeCurrency> tradeCurrencySet = new HashSet<>();
// TODO could be done more elegantly...
public static void fillCurrencyListItems(List<TradeCurrency> tradeCurrencyList,
ObservableList<CurrencyListItem> currencyListItems,
@Nullable CurrencyListItem showAllCurrencyListItem,
Preferences preferences) {
Map<String, Integer> tradesPerCurrencyMap = new HashMap<>();
Set<TradeCurrency> tradeCurrencySet = new HashSet<>();
// We get the list of all offers or trades. We want to find out how many items at each currency we have.
tradeCurrencyList.stream().forEach(tradeCurrency -> {
tradeCurrencySet.add(tradeCurrency);
String code = tradeCurrency.getCode();
@ -259,6 +267,17 @@ public class GUIUtil {
tradesPerCurrencyMap.put(code, 1);
});
Set<TradeCurrency> userSet = new HashSet<>(preferences.getFiatCurrencies());
userSet.addAll(preferences.getCryptoCurrencies());
// Now all those items which are not in the offers or trades list but comes from the user preferred currency list
// will get set to 0
userSet.stream().forEach(tradeCurrency -> {
tradeCurrencySet.add(tradeCurrency);
String code = tradeCurrency.getCode();
if (!tradesPerCurrencyMap.containsKey(code))
tradesPerCurrencyMap.put(code, 0);
});
List<CurrencyListItem> list = tradeCurrencySet.stream()
.filter(e -> CurrencyUtil.isFiatCurrency(e.getCode()))
.map(e -> new CurrencyListItem(e, tradesPerCurrencyMap.get(e.getCode())))