Add sticky market price checkbox to settings: If sticky market price is selected market price does not change with currency selection, otherwise it is context sensitive.

This commit is contained in:
Manfred Karrer 2016-04-13 15:54:26 +02:00
parent 1c51efa704
commit b4fdb2e059
10 changed files with 113 additions and 41 deletions

View File

@ -114,7 +114,7 @@ public class CurrencyUtil {
// result.add(new CryptoCurrency("BCN", "Bytecoin"));
return result;
}
/**
* @return Sorted list of SEPA currencies with EUR as first item
@ -156,6 +156,10 @@ public class CurrencyUtil {
return !(isCryptoCurrency(currencyCode)) && Currency.getInstance(currencyCode) != null;
}
public static Optional<FiatCurrency> getFiatCurrency(String currencyCode) {
return allSortedFiatCurrencies.stream().filter(e -> e.getCode().equals(currencyCode)).findAny();
}
@SuppressWarnings("WeakerAccess")
public static boolean isCryptoCurrency(String currencyCode) {
return getAllSortedCryptoCurrencies().stream().filter(e -> e.getCode().equals(currencyCode)).findAny().isPresent();

View File

@ -108,6 +108,7 @@ public final class Preferences implements Persistable {
private long nonTradeTxFeePerKB = FeePolicy.getNonTradeFeePerKb().value;
private double maxPriceDistanceInPercent;
private boolean useInvertedMarketPrice;
private boolean useStickyMarketPrice = false;
// Observable wrappers
transient private final StringProperty btcDenominationProperty = new SimpleStringProperty(btcDenomination);
@ -158,6 +159,7 @@ public final class Preferences implements Persistable {
preferredTradeCurrency = persisted.getPreferredTradeCurrency();
defaultTradeCurrency = preferredTradeCurrency;
useTorForBitcoinJ = persisted.getUseTorForBitcoinJ();
useStickyMarketPrice = persisted.getUseStickyMarketPrice();
showOwnOffersInOfferBook = persisted.getShowOwnOffersInOfferBook();
maxPriceDistanceInPercent = persisted.getMaxPriceDistanceInPercent();
// Backward compatible to version 0.3.6. Can be removed after a while
@ -358,7 +360,11 @@ public final class Preferences implements Persistable {
setUseInvertedMarketPrice(!getUseInvertedMarketPrice());
return getUseInvertedMarketPrice();
}
public void setUseStickyMarketPrice(boolean useStickyMarketPrice) {
this.useStickyMarketPrice = useStickyMarketPrice;
storage.queueUpForSave();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter
@ -476,6 +482,10 @@ public final class Preferences implements Persistable {
return maxPriceDistanceInPercent;
}
public boolean getUseStickyMarketPrice() {
return useStickyMarketPrice;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private

View File

@ -137,10 +137,10 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
priceComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
model.setPriceFeedComboBoxItem(newValue);
});
selectedPriceFeedItemListender = (observable, oldValue, newValue) -> {
priceComboBox.getSelectionModel().select(newValue);
if (newValue != null)
priceComboBox.getSelectionModel().select(newValue);
};
model.selectedPriceFeedComboBoxItemProperty.addListener(selectedPriceFeedItemListender);

View File

@ -711,15 +711,34 @@ public class MainViewModel implements ViewModel {
(useInvertedMarketPrice ? " BTC/" + marketPriceCurrency : " " + marketPriceCurrency + "/BTC"));
marketPriceBinding.subscribe((observable, oldValue, newValue) -> {
if (selectedPriceFeedComboBoxItemProperty.get() == null) {
findPriceFeedComboBoxItem(preferences.getPreferredTradeCurrency().getCode())
.ifPresent(item -> {
item.setDisplayString(newValue);
selectedPriceFeedComboBoxItemProperty.set(item);
if (newValue != null && !newValue.equals(oldValue)) {
String code = preferences.getUseStickyMarketPrice() ?
preferences.getPreferredTradeCurrency().getCode() :
priceFeed.currencyCodeProperty().get();
Optional<PriceFeedComboBoxItem> itemOptional = findPriceFeedComboBoxItem(code);
if (itemOptional.isPresent()) {
if (selectedPriceFeedComboBoxItemProperty.get() == null || !preferences.getUseStickyMarketPrice()) {
itemOptional.get().setDisplayString(newValue);
selectedPriceFeedComboBoxItemProperty.set(itemOptional.get());
}
} else {
if (CurrencyUtil.isCryptoCurrency(code)) {
CurrencyUtil.getCryptoCurrency(code).ifPresent(cryptoCurrency -> {
preferences.addCryptoCurrency(cryptoCurrency);
fillPriceFeedComboBoxItems();
});
} else {
CurrencyUtil.getFiatCurrency(code).ifPresent(fiatCurrency -> {
preferences.addFiatCurrency(fiatCurrency);
fillPriceFeedComboBoxItems();
});
}
}
if (selectedPriceFeedComboBoxItemProperty.get() != null)
selectedPriceFeedComboBoxItemProperty.get().setDisplayString(newValue);
}
if (selectedPriceFeedComboBoxItemProperty.get() != null)
selectedPriceFeedComboBoxItemProperty.get().setDisplayString(newValue);
});
priceFeedAllLoadedSubscription = EasyBind.subscribe(priceFeed.currenciesUpdateFlagProperty(), newPriceUpdate -> setMarketPriceInItems());
@ -755,7 +774,14 @@ public class MainViewModel implements ViewModel {
}
public void setPriceFeedComboBoxItem(PriceFeedComboBoxItem item) {
if (item != null) {
if (!preferences.getUseStickyMarketPrice()) {
Optional<PriceFeedComboBoxItem> itemOptional = findPriceFeedComboBoxItem(priceFeed.currencyCodeProperty().get());
if (itemOptional.isPresent())
selectedPriceFeedComboBoxItemProperty.set(itemOptional.get());
else
findPriceFeedComboBoxItem(preferences.getPreferredTradeCurrency().getCode())
.ifPresent(item2 -> selectedPriceFeedComboBoxItemProperty.set(item2));
} else if (item != null) {
selectedPriceFeedComboBoxItemProperty.set(item);
priceFeed.setCurrencyCode(item.currencyCode);
} else {

View File

@ -74,7 +74,9 @@ class MarketsChartsViewModel extends ActivatableViewModel {
offerBookListItems.addListener(listChangeListener);
offerBook.fillOfferBookListItems();
updateChartData(offerBookListItems);
//priceFeed.setCurrencyCode(tradeCurrency.get().getCode());
if (!preferences.getUseStickyMarketPrice())
priceFeed.setCurrencyCode(tradeCurrency.get().getCode());
}
@Override
@ -136,7 +138,9 @@ class MarketsChartsViewModel extends ActivatableViewModel {
public void onSetTradeCurrency(TradeCurrency tradeCurrency) {
this.tradeCurrency.set(tradeCurrency);
updateChartData(offerBookListItems);
//priceFeed.setCurrencyCode(tradeCurrency.getCode());
if (!preferences.getUseStickyMarketPrice())
priceFeed.setCurrencyCode(tradeCurrency.getCode());
}
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -31,6 +31,7 @@ import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.common.model.ActivatableDataModel;
import io.bitsquare.gui.main.overlays.notifications.Notification;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.locale.CurrencyUtil;
import io.bitsquare.locale.TradeCurrency;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.payment.*;
@ -176,8 +177,8 @@ class CreateOfferDataModel extends ActivatableDataModel {
paymentAccounts.setAll(user.getPaymentAccounts());
/*if (isTabSelected)
priceFeed.setCurrencyCode(tradeCurrencyCode.get());*/
if (!preferences.getUseStickyMarketPrice() && isTabSelected)
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
updateBalance();
}
@ -232,7 +233,8 @@ class CreateOfferDataModel extends ActivatableDataModel {
tradeCurrencyCode.set(this.tradeCurrency.getCode());
//priceFeed.setCurrencyCode(tradeCurrencyCode.get());
if (!preferences.getUseStickyMarketPrice())
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
calculateVolume();
calculateTotalToPay();
@ -241,8 +243,8 @@ class CreateOfferDataModel extends ActivatableDataModel {
void onTabSelected(boolean isSelected) {
this.isTabSelected = isSelected;
/*if (isTabSelected)
priceFeed.setCurrencyCode(tradeCurrencyCode.get());*/
if (!preferences.getUseStickyMarketPrice() && isTabSelected)
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -306,13 +308,27 @@ class CreateOfferDataModel extends ActivatableDataModel {
public void onCurrencySelected(TradeCurrency tradeCurrency) {
if (tradeCurrency != null) {
this.tradeCurrency = tradeCurrency;
String code = tradeCurrency.getCode();
final String code = tradeCurrency.getCode();
tradeCurrencyCode.set(code);
if (paymentAccount != null)
paymentAccount.setSelectedTradeCurrency(tradeCurrency);
//priceFeed.setCurrencyCode(code);
if (!preferences.getUseStickyMarketPrice())
priceFeed.setCurrencyCode(code);
Optional<TradeCurrency> tradeCurrencyOptional = preferences.getTradeCurrenciesAsObservable().stream().filter(e -> e.getCode().equals(code)).findAny();
if (!tradeCurrencyOptional.isPresent()) {
if (CurrencyUtil.isCryptoCurrency(code)) {
CurrencyUtil.getCryptoCurrency(code).ifPresent(cryptoCurrency -> {
preferences.addCryptoCurrency(cryptoCurrency);
});
} else {
CurrencyUtil.getFiatCurrency(code).ifPresent(fiatCurrency -> {
preferences.addFiatCurrency(fiatCurrency);
});
}
}
}
}

View File

@ -165,6 +165,9 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
@Override
protected void activate() {
currencyComboBox.setPrefWidth(250);
paymentAccountsComboBox.setPrefWidth(250);
addBindings();
addListeners();
addSubscriptions();

View File

@ -159,12 +159,12 @@ class OfferBookViewModel extends ActivatableViewModel {
}
private void setMarketPriceFeedCurrency() {
/*if (isTabSelected) {
if (!preferences.getUseStickyMarketPrice() && isTabSelected) {
if (showAllTradeCurrenciesProperty.get())
priceFeed.setCurrencyCode(CurrencyUtil.getDefaultTradeCurrency().getCode());
else
priceFeed.setCurrencyCode(tradeCurrencyCode.get());
}*/
}
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -186,19 +186,21 @@ class OfferBookViewModel extends ActivatableViewModel {
///////////////////////////////////////////////////////////////////////////////////////////
public void onSetTradeCurrency(TradeCurrency tradeCurrency) {
String code = tradeCurrency.getCode();
boolean showAllEntry = isShowAllEntry(code);
showAllTradeCurrenciesProperty.set(showAllEntry);
if (isEditEntry(code))
navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class);
else if (!showAllEntry) {
this.selectedTradeCurrency = tradeCurrency;
tradeCurrencyCode.set(code);
if (tradeCurrency != null) {
String code = tradeCurrency.getCode();
boolean showAllEntry = isShowAllEntry(code);
showAllTradeCurrenciesProperty.set(showAllEntry);
if (isEditEntry(code))
navigation.navigateTo(MainView.class, SettingsView.class, PreferencesView.class);
else if (!showAllEntry) {
this.selectedTradeCurrency = tradeCurrency;
tradeCurrencyCode.set(code);
}
setMarketPriceFeedCurrency();
filterList();
}
setMarketPriceFeedCurrency();
filterList();
}
public void onSetPaymentMethod(PaymentMethod paymentMethod) {

View File

@ -136,7 +136,7 @@ class TakeOfferDataModel extends ActivatableDataModel {
// if (isWalletFunded.get())
// feeFromFundingTxProperty.set(FeePolicy.getMinRequiredFeeForFundingTx());
/*if (isTabSelected)*/
if (!preferences.getUseStickyMarketPrice() && isTabSelected)
priceFeed.setCurrencyCode(offer.getCurrencyCode());
tradeManager.checkOfferAvailability(offer, () -> {
@ -207,13 +207,15 @@ class TakeOfferDataModel extends ActivatableDataModel {
};
offer.resetState();
//priceFeed.setCurrencyCode(offer.getCurrencyCode());
if (!preferences.getUseStickyMarketPrice())
priceFeed.setCurrencyCode(offer.getCurrencyCode());
}
void onTabSelected(boolean isSelected) {
this.isTabSelected = isSelected;
/*if (isTabSelected)
priceFeed.setCurrencyCode(offer.getCurrencyCode());*/
if (!preferences.getUseStickyMarketPrice() && isTabSelected)
priceFeed.setCurrencyCode(offer.getCurrencyCode());
}

View File

@ -58,7 +58,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Activatab
// private ComboBox<String> userLanguageComboBox;
private ComboBox<TradeCurrency> preferredTradeCurrencyComboBox;
private CheckBox useAnimationsCheckBox, autoSelectArbitratorsCheckBox, showOwnOffersInOfferBook;
private CheckBox useAnimationsCheckBox, autoSelectArbitratorsCheckBox, showOwnOffersInOfferBook, useStickyMarketPriceCheckBox;
private int gridRow = 0;
private InputTextField transactionFeeInputTextField;
private ChangeListener<Boolean> transactionFeeFocusedListener;
@ -329,11 +329,12 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Activatab
}
private void initializeDisplayOptions() {
TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 3, "Display options", Layout.GROUP_DISTANCE);
TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 4, "Display options", Layout.GROUP_DISTANCE);
GridPane.setColumnSpan(titledGroupBg, 4);
showOwnOffersInOfferBook = addLabelCheckBox(root, gridRow, "Show my own offers in offer book:", "", Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
useAnimationsCheckBox = addLabelCheckBox(root, ++gridRow, "Use animations:", "").second;
useStickyMarketPriceCheckBox = addLabelCheckBox(root, ++gridRow, "Use sticky market price:", "").second;
resetDontShowAgainButton = addLabelButton(root, ++gridRow, "Reset all don't show again flags:", "Reset", 0).second;
}
@ -445,6 +446,9 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Activatab
useAnimationsCheckBox.setSelected(preferences.getUseAnimations());
useAnimationsCheckBox.setOnAction(e -> preferences.setUseAnimations(useAnimationsCheckBox.isSelected()));
useStickyMarketPriceCheckBox.setSelected(preferences.getUseStickyMarketPrice());
useStickyMarketPriceCheckBox.setOnAction(e -> preferences.setUseStickyMarketPrice(useStickyMarketPriceCheckBox.isSelected()));
resetDontShowAgainButton.setOnAction(e -> preferences.resetDontShowAgainForType());
autoSelectArbitratorsCheckBox.setSelected(preferences.getAutoSelectArbitrators());
@ -471,6 +475,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Activatab
private void deactivateDisplayPreferences() {
useAnimationsCheckBox.setOnAction(null);
useStickyMarketPriceCheckBox.setOnAction(null);
showOwnOffersInOfferBook.setOnAction(null);
autoSelectArbitratorsCheckBox.setOnAction(null);
resetDontShowAgainButton.setOnAction(null);