MainController: Replace EasyBind with two static methods.

This removes the dependency on EasyBind.
This commit is contained in:
Sean Gilligan 2019-04-21 15:20:09 -07:00 committed by Andreas Schildbach
parent 537b244bfa
commit c2253d2e97
2 changed files with 13 additions and 3 deletions

View File

@ -8,7 +8,6 @@ plugins {
dependencies {
implementation project(':bitcoinj-core')
implementation 'com.google.guava:guava:27.1-android'
implementation 'org.fxmisc.easybind:easybind:1.0.3'
implementation 'de.jensd:fontawesomefx:8.0.0'
implementation 'com.google.zxing:core:3.3.3'
implementation 'org.slf4j:slf4j-jdk14:1.7.25'

View File

@ -16,6 +16,9 @@
package wallettemplate;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.MonetaryFormat;
@ -27,7 +30,6 @@ import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.util.Duration;
import org.fxmisc.easybind.EasyBind;
import wallettemplate.controls.ClickableBitcoinAddress;
import wallettemplate.controls.NotificationBarPane;
import wallettemplate.utils.BitcoinUIModel;
@ -48,6 +50,7 @@ public class MainController {
private BitcoinUIModel model = new BitcoinUIModel();
private NotificationBarPane.Item syncItem;
private static final MonetaryFormat MONETARY_FORMAT = MonetaryFormat.BTC.noCode();
// Called by FXMLLoader.
public void initialize() {
@ -57,7 +60,7 @@ public class MainController {
public void onBitcoinSetup() {
model.setWallet(bitcoin.wallet());
addressControl.addressProperty().bind(model.addressProperty());
balance.textProperty().bind(EasyBind.map(model.balanceProperty(), coin -> MonetaryFormat.BTC.noCode().format(coin).toString()));
balance.textProperty().bind(createBalanceStringBinding(model.balanceProperty()));
// Don't let the user click send money when the wallet is empty.
sendMoneyOutBtn.disableProperty().bind(model.balanceProperty().isEqualTo(Coin.ZERO));
@ -75,6 +78,14 @@ public class MainController {
});
}
private static String formatCoin(Coin coin) {
return MONETARY_FORMAT.format(coin).toString();
}
private static Binding<String> createBalanceStringBinding(ObservableValue<Coin> coinProperty) {
return Bindings.createStringBinding(() -> formatCoin(coinProperty.getValue()), coinProperty);
}
private void showBitcoinSyncMessage() {
syncItem = Main.instance.notificationBar.pushItem("Synchronising with the Bitcoin network", model.syncProgressProperty());
}