From 61eee8f445d67c47a0c88c6cb2bb01d1c4b2845c Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 1 Mar 2016 21:51:38 +0100 Subject: [PATCH] Add edit field in currency list --- .../io/bitsquare/locale/CurrencyUtil.java | 99 +------------------ .../charts/MarketsChartsViewModel.java | 1 + .../main/offer/offerbook/OfferBookView.java | 11 ++- .../offer/offerbook/OfferBookViewModel.java | 23 ++++- .../settings/preferences/PreferencesView.java | 1 + 5 files changed, 28 insertions(+), 107 deletions(-) diff --git a/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java b/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java index d43fed3227..0760d2ee54 100644 --- a/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java +++ b/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java @@ -62,7 +62,6 @@ public class CurrencyUtil { return list; } - private static final List allSortedCryptoCurrencies = createAllSortedCryptoCurrenciesList(); public static List getAllSortedCryptoCurrencies() { @@ -112,94 +111,6 @@ public class CurrencyUtil { return result; } - - - /* // We add all currencies supported by payment methods - // TODO not used anymore - private static List createAllSortedCurrenciesListDerivedFromPaymentMethods() { - Set set = new HashSet<>(); - - // Sepa: EUR at first place - set.addAll(getSortedSEPACurrencyCodes()); - - // PerfectMoney: - set.add(new FiatCurrency("USD")); - - // Alipay: - set.add(new FiatCurrency("CNY")); - - // OKPay: We want to maintain the order so we don't use a Set but add items if nto already in list - getAllOKPayCurrencies().stream().forEach(set::add); - - // Swish: it is already added by SEPA - - // for printing out all codes - *//* String res; - result.stream().forEach(e -> { - res += "list.add(new FiatCurrency(\""+e.code+"\"));\n"; - }); - log.debug(res);*//* - - - List list = getAllManuallySortedFiatCurrencies(); - - // check if the list derived form the payment methods is containing exactly the same as our manually sorted one - - List list1 = set.stream().map(e -> e.code).collect(Collectors.toList()); - list1.sort(String::compareTo); - List list2 = list.stream().map(e -> e.code).collect(Collectors.toList()); - list2.sort(String::compareTo); - - if (list1.size() != list2.size()) { - log.error("manually defined currencies are not matching currencies derived form our payment methods"); - log.error("list1 " + list1.toString()); - log.error("list2 " + list2.toString()); - } - - if (!list1.toString().equals(list2.toString())) { - log.error("List derived form the payment methods is not matching exactly the same as our manually sorted one"); - log.error("list1 " + list1.toString()); - log.error("list2 " + list2.toString()); - } - - // Blockchain - getSortedCryptoCurrencies().stream().forEach(list::add); - - return list; - }*/ - - - /* private static List getAllManuallySortedFiatCurrencies() { - List list = new ArrayList<>(); - list.add(new FiatCurrency("EUR")); - list.add(new FiatCurrency("USD")); - list.add(new FiatCurrency("GBP")); - list.add(new FiatCurrency("CNY")); - list.add(new FiatCurrency("HKD")); - list.add(new FiatCurrency("CHF")); - list.add(new FiatCurrency("JPY")); - list.add(new FiatCurrency("CAD")); - list.add(new FiatCurrency("AUD")); - list.add(new FiatCurrency("NZD")); - list.add(new FiatCurrency("ZAR")); - list.add(new FiatCurrency("RUB")); - - list.add(new FiatCurrency("SEK")); - list.add(new FiatCurrency("NOK")); - list.add(new FiatCurrency("DKK")); - list.add(new FiatCurrency("ISK")); - - list.add(new FiatCurrency("PLN")); - list.add(new FiatCurrency("CZK")); - list.add(new FiatCurrency("TRY")); - - list.add(new FiatCurrency("BGN")); - list.add(new FiatCurrency("HRK")); - list.add(new FiatCurrency("HUF")); - list.add(new FiatCurrency("RON")); - - return list; - }*/ /** * @return Sorted list of SEPA currencies with EUR as first item @@ -255,15 +166,7 @@ public class CurrencyUtil { } public static FiatCurrency getCurrencyByCountryCode(String countryCode) { - // java 1.8.8_0_20 reports wrong currency (Lita instead of EUR) - if (!countryCode.equals("LT")) - return new FiatCurrency(Currency.getInstance(new Locale(LanguageUtil.getDefaultLanguage(), countryCode)).getCurrencyCode()); - else { - if (!Currency.getInstance(new Locale(LanguageUtil.getDefaultLanguage(), countryCode)).getCurrencyCode().equals("EUR")) - log.error("wrong currency reported for LT"); - - return new FiatCurrency("EUR"); - } + return new FiatCurrency(Currency.getInstance(new Locale(LanguageUtil.getDefaultLanguage(), countryCode)).getCurrencyCode()); } diff --git a/gui/src/main/java/io/bitsquare/gui/main/markets/charts/MarketsChartsViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/markets/charts/MarketsChartsViewModel.java index 9506dd31f9..cfff2dd158 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/markets/charts/MarketsChartsViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/markets/charts/MarketsChartsViewModel.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.stream.Collectors; class MarketsChartsViewModel extends ActivatableViewModel { + final static String EDIT_FLAG = "EDIT_FLAG"; private final OfferBook offerBook; private final Preferences preferences; diff --git a/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookView.java b/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookView.java index 9ab84bee72..0b7ef24ddd 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookView.java @@ -93,10 +93,13 @@ public class OfferBookView extends ActivatableViewAndModel() { @Override public String toString(TradeCurrency tradeCurrency) { - if (!tradeCurrency.getCode().equals(OfferBookViewModel.SHOW_ALL_FLAG)) - return tradeCurrency.getNameAndCode(); + String code = tradeCurrency.getCode(); + if (code.equals(OfferBookViewModel.SHOW_ALL_FLAG)) + return ">> Show all"; + else if (code.equals(OfferBookViewModel.EDIT_FLAG)) + return ">> Edit currency list"; else - return "Show all"; + return tradeCurrency.getNameAndCode(); } @Override @@ -111,7 +114,7 @@ public class OfferBookView extends ActivatableViewAndModel> Show all"); } @Override diff --git a/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookViewModel.java index 34c18592b7..69c5fc2909 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/offer/offerbook/OfferBookViewModel.java @@ -23,7 +23,11 @@ import io.bitsquare.app.Version; import io.bitsquare.btc.pricefeed.PriceFeed; import io.bitsquare.common.handlers.ErrorMessageHandler; import io.bitsquare.common.handlers.ResultHandler; +import io.bitsquare.gui.Navigation; import io.bitsquare.gui.common.model.ActivatableViewModel; +import io.bitsquare.gui.main.MainView; +import io.bitsquare.gui.main.settings.SettingsView; +import io.bitsquare.gui.main.settings.preferences.PreferencesView; import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.locale.*; import io.bitsquare.p2p.NodeAddress; @@ -49,7 +53,8 @@ import java.util.List; import java.util.Optional; class OfferBookViewModel extends ActivatableViewModel { - final static String SHOW_ALL_FLAG = "XXX"; + final static String SHOW_ALL_FLAG = "SHOW_ALL_FLAG"; + final static String EDIT_FLAG = "EDIT_FLAG"; private final OpenOfferManager openOfferManager; private final User user; @@ -57,6 +62,7 @@ class OfferBookViewModel extends ActivatableViewModel { private final Preferences preferences; private final P2PService p2PService; private final PriceFeed priceFeed; + private Navigation navigation; final BSFormatter formatter; private final FilteredList filteredItems; @@ -88,7 +94,7 @@ class OfferBookViewModel extends ActivatableViewModel { @Inject public OfferBookViewModel(User user, OpenOfferManager openOfferManager, OfferBook offerBook, Preferences preferences, P2PService p2PService, PriceFeed priceFeed, - BSFormatter formatter) { + Navigation navigation, BSFormatter formatter) { super(); this.openOfferManager = openOfferManager; @@ -97,6 +103,7 @@ class OfferBookViewModel extends ActivatableViewModel { this.preferences = preferences; this.p2PService = p2PService; this.priceFeed = priceFeed; + this.navigation = navigation; this.formatter = formatter; offerBookListItems = offerBook.getOfferBookListItems(); @@ -133,9 +140,9 @@ class OfferBookViewModel extends ActivatableViewModel { private void fillAllTradeCurrencies() { allTradeCurrencies.clear(); // Used for ignoring filter (show all) - TradeCurrency dummy = new FiatCurrency(SHOW_ALL_FLAG); - allTradeCurrencies.add(dummy); + allTradeCurrencies.add(new CryptoCurrency(SHOW_ALL_FLAG, SHOW_ALL_FLAG)); allTradeCurrencies.addAll(preferences.getTradeCurrenciesAsObservable()); + allTradeCurrencies.add(new CryptoCurrency(EDIT_FLAG, EDIT_FLAG)); } private void setMarketPriceFeedCurrency() { @@ -168,7 +175,9 @@ class OfferBookViewModel extends ActivatableViewModel { public void onSetTradeCurrency(TradeCurrency tradeCurrency) { String code = tradeCurrency.getCode(); showAllTradeCurrenciesProperty.set(isShowAllEntry(code)); - if (!showAllTradeCurrenciesProperty.get()) { + if (isEditEntry(code)) + navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class); + else if (!showAllTradeCurrenciesProperty.get()) { this.selectedTradeCurrency = tradeCurrency; tradeCurrencyCode.set(code); } @@ -366,4 +375,8 @@ class OfferBookViewModel extends ActivatableViewModel { private boolean isShowAllEntry(String id) { return id.equals(SHOW_ALL_FLAG); } + + private boolean isEditEntry(String id) { + return id.equals(EDIT_FLAG); + } } diff --git a/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java b/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java index 327e84c509..f2b6420dd5 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/settings/preferences/PreferencesView.java @@ -313,6 +313,7 @@ public class PreferencesView extends ActivatableViewAndModel { TradeCurrency selectedItem = preferredTradeCurrencyComboBox.getSelectionModel().getSelectedItem(); if (selectedItem != null)