From a286e3e9b3e3e821c3fdd237f0212c500ac66d47 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 3 Feb 2016 20:23:25 +0100 Subject: [PATCH] Add update notification to alert system --- .../main/java/io/bitsquare/alert/Alert.java | 4 +- .../main/java/io/bitsquare/gui/bitsquare.css | 46 +++++++++++++++++++ .../transactions/TransactionsListItem.java | 9 +++- .../gui/popups/DisplayAlertMessagePopup.java | 24 ++++++---- .../gui/popups/SendAlertMessagePopup.java | 16 +++++-- .../io/bitsquare/gui/util/FormBuilder.java | 31 +++++++++++++ .../io/bitsquare/p2p/peers/PeerManager.java | 2 +- 7 files changed, 116 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/io/bitsquare/alert/Alert.java b/core/src/main/java/io/bitsquare/alert/Alert.java index b0a89f2122..1ae3e91cce 100644 --- a/core/src/main/java/io/bitsquare/alert/Alert.java +++ b/core/src/main/java/io/bitsquare/alert/Alert.java @@ -30,11 +30,13 @@ public final class Alert implements PubKeyProtectedExpirablePayload { private static final long TTL = TimeUnit.DAYS.toMillis(10); public final String message; + public final boolean isUpdateInfo; private String signatureAsBase64; private PublicKey storagePublicKey; - public Alert(String message) { + public Alert(String message, boolean isUpdateInfo) { this.message = message; + this.isUpdateInfo = isUpdateInfo; } public void setSigAndStoragePubKey(String signatureAsBase64, PublicKey storagePublicKey) { diff --git a/gui/src/main/java/io/bitsquare/gui/bitsquare.css b/gui/src/main/java/io/bitsquare/gui/bitsquare.css index 6d844fe3e5..907f961a3a 100644 --- a/gui/src/main/java/io/bitsquare/gui/bitsquare.css +++ b/gui/src/main/java/io/bitsquare/gui/bitsquare.css @@ -203,6 +203,44 @@ textfield */ -fx-progress-color: dimgrey; } +.hyperlink { + -fx-border-style: none; + -fx-border-width: 0px; +} + +.hyperlink .text { + -fx-fill: white; + -fx-border-style: none; + -fx-border-width: 0px; +} + +.hyperlink .text { + -fx-fill: -fx-accent; + -fx-border-style: none; + -fx-border-width: 0px; +} + +.hyperlink .text:hover, +.hyperlink .tooltip .text, +.hyperlink .text:hover { + -fx-fill: black; + -fx-border-style: none; + -fx-border-width: 0px; +} + +.hyperlink:hover, +.hyperlink:visited, +.hyperlink:hover:visited { + -fx-underline: false; + -fx-border-style: none; + -fx-border-width: 0px; +} + +.hyperlink:focused { + -fx-border-style: none; + -fx-border-width: 0px; +} + /******************************************************************************* * * * Table * @@ -263,22 +301,30 @@ textfield */ .table-view .table-row-cell:selected .hyperlink .text { -fx-fill: white; + -fx-border-style: none; + -fx-border-width: 0px; } .table-view .table-row-cell .hyperlink .text { -fx-fill: -fx-accent; + -fx-border-style: none; + -fx-border-width: 0px; } .table-view .table-row-cell .hyperlink .text:hover, .table-view .table-row-cell:selected .hyperlink .tooltip .text, .table-view .table-row-cell:selected .hyperlink .text:hover { -fx-fill: black; + -fx-border-style: none; + -fx-border-width: 0px; } .table-view .table-row-cell .hyperlink:hover, .table-view .table-row-cell .hyperlink:visited, .table-view .table-row-cell .hyperlink:hover:visited { -fx-underline: false; + -fx-border-style: none; + -fx-border-width: 0px; } .table-view .table-row-cell .hyperlink:focused { diff --git a/gui/src/main/java/io/bitsquare/gui/main/funds/transactions/TransactionsListItem.java b/gui/src/main/java/io/bitsquare/gui/main/funds/transactions/TransactionsListItem.java index b654bad6c3..9bed80fb6f 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/funds/transactions/TransactionsListItem.java +++ b/gui/src/main/java/io/bitsquare/gui/main/funds/transactions/TransactionsListItem.java @@ -132,7 +132,14 @@ public class TransactionsListItem { } } } else { - details = received ? "Funded to wallet" : "Withdrawn from wallet"; + /* Optional addressEntryOptional = walletService.getAddressEntryList().stream() + .filter(e -> e.getAddressString() != null && e.getAddressString().equals(addressString)) + .findAny(); + if (addressEntryOptional.isPresent() && + addressEntryOptional.get().getContext() == AddressEntry.Context.ARBITRATOR) + details = received ? "Received funds" : "Withdrawn from wallet"; + else*/ + details = received ? "Received funds" : "Withdrawn from wallet"; } date.set(formatter.formatDateTime(transaction.getUpdateTime())); diff --git a/gui/src/main/java/io/bitsquare/gui/popups/DisplayAlertMessagePopup.java b/gui/src/main/java/io/bitsquare/gui/popups/DisplayAlertMessagePopup.java index 9c4d502669..0673181351 100644 --- a/gui/src/main/java/io/bitsquare/gui/popups/DisplayAlertMessagePopup.java +++ b/gui/src/main/java/io/bitsquare/gui/popups/DisplayAlertMessagePopup.java @@ -18,6 +18,8 @@ package io.bitsquare.gui.popups; import io.bitsquare.alert.Alert; +import io.bitsquare.common.util.Utilities; +import io.bitsquare.gui.components.HyperlinkWithIcon; import javafx.geometry.Insets; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -28,6 +30,7 @@ import org.slf4j.LoggerFactory; import java.util.Optional; import static com.google.common.base.Preconditions.checkNotNull; +import static io.bitsquare.gui.util.FormBuilder.addLabelHyperlinkWithIcon; import static io.bitsquare.gui.util.FormBuilder.addMultilineLabel; public class DisplayAlertMessagePopup extends Popup { @@ -44,17 +47,13 @@ public class DisplayAlertMessagePopup extends Popup { } public DisplayAlertMessagePopup show() { - if (headLine == null) - headLine = "Global alert message!"; - width = 700; + // need to set headLine, otherwise the fields will not be created in addHeadLine + headLine = "Important information!"; createGridPane(); addHeadLine(); addContent(); createPopup(); - - headLineLabel.setStyle("-fx-text-fill: -bs-error-red; -fx-font-weight: bold; -fx-font-size: 18;"); - return this; } @@ -75,8 +74,17 @@ public class DisplayAlertMessagePopup extends Popup { private void addContent() { checkNotNull(alert, "alertMessage must not be null"); msgLabel = addMultilineLabel(gridPane, ++rowIndex, alert.message, 10); - msgLabel.setStyle("-fx-text-fill: -bs-error-red;"); - + if (alert.isUpdateInfo) { + headLine = "Important update information!"; + headLineLabel.setStyle("-fx-text-fill: -fx-accent; -fx-font-weight: bold; -fx-font-size: 22;"); + String url = "https://github.com/bitsquare/bitsquare/releases"; + HyperlinkWithIcon download = addLabelHyperlinkWithIcon(gridPane, ++rowIndex, "Download:", url).second; + download.setMaxWidth(350); + download.setOnAction(e -> Utilities.openWebPage(url)); + } else { + headLine = "Important information!"; + headLineLabel.setStyle("-fx-text-fill: -bs-error-red; -fx-font-weight: bold; -fx-font-size: 22;"); + } closeButton = new Button("Cancel"); closeButton.setOnAction(e -> { hide(); diff --git a/gui/src/main/java/io/bitsquare/gui/popups/SendAlertMessagePopup.java b/gui/src/main/java/io/bitsquare/gui/popups/SendAlertMessagePopup.java index fd3a5cab77..a8e268021b 100644 --- a/gui/src/main/java/io/bitsquare/gui/popups/SendAlertMessagePopup.java +++ b/gui/src/main/java/io/bitsquare/gui/popups/SendAlertMessagePopup.java @@ -22,6 +22,7 @@ import io.bitsquare.app.BitsquareApp; import io.bitsquare.gui.components.InputTextField; import javafx.geometry.Insets; import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import org.slf4j.Logger; @@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory; import java.util.Optional; +import static io.bitsquare.gui.util.FormBuilder.addLabelCheckBox; import static io.bitsquare.gui.util.FormBuilder.addLabelInputTextField; public class SendAlertMessagePopup extends Popup { @@ -59,9 +61,9 @@ public class SendAlertMessagePopup extends Popup { public SendAlertMessagePopup show() { if (headLine == null) - headLine = "Send alert message"; + headLine = "Send global notification"; - width = 700; + width = 600; createGridPane(); addHeadLine(); addContent(); @@ -91,23 +93,27 @@ public class SendAlertMessagePopup extends Popup { private void addContent() { InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Alert private key:", 10).second; InputTextField alertMessageInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Alert message:").second; + CheckBox isUpdateCheckBox = addLabelCheckBox(gridPane, ++rowIndex, "Is update notification:", "").second; + isUpdateCheckBox.setSelected(true); if (BitsquareApp.DEV_MODE) { keyInputTextField.setText("2e41038992f89eef2e4634ff3586e342c68ad9a5a7ffafee866781687f77a9b1"); alertMessageInputTextField.setText("m1"); } - openTicketButton = new Button("Send alert message"); + openTicketButton = new Button("Send notification"); openTicketButton.setOnAction(e -> { if (alertMessageInputTextField.getText().length() > 0 && keyInputTextField.getText().length() > 0) { - if (sendAlertMessageHandler.handle(new Alert(alertMessageInputTextField.getText()), keyInputTextField.getText())) + if (sendAlertMessageHandler.handle( + new Alert(alertMessageInputTextField.getText(), isUpdateCheckBox.isSelected()), + keyInputTextField.getText())) hide(); else new Popup().warning("The key you entered was not correct.").width(300).onClose(() -> blurAgain()).show(); } }); - Button removeAlertMessageButton = new Button("Remove alert message"); + Button removeAlertMessageButton = new Button("Remove notification"); removeAlertMessageButton.setOnAction(e -> { if (keyInputTextField.getText().length() > 0) { if (removeAlertMessageHandler.handle(keyInputTextField.getText())) diff --git a/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java b/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java index 59472b72ad..b72a677228 100644 --- a/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java +++ b/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java @@ -17,6 +17,7 @@ package io.bitsquare.gui.util; +import de.jensd.fx.fontawesome.AwesomeIcon; import io.bitsquare.common.util.Tuple2; import io.bitsquare.common.util.Tuple3; import io.bitsquare.gui.components.*; @@ -154,6 +155,32 @@ public class FormBuilder { return new Tuple2<>(label, textField); } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Label + HyperlinkWithIcon + /////////////////////////////////////////////////////////////////////////////////////////// + + public static Tuple2 addLabelHyperlinkWithIcon(GridPane gridPane, int rowIndex, String title) { + return addLabelHyperlinkWithIcon(gridPane, rowIndex, title, "", 0); + } + + public static Tuple2 addLabelHyperlinkWithIcon(GridPane gridPane, int rowIndex, String title, String value) { + return addLabelHyperlinkWithIcon(gridPane, rowIndex, title, value, 0); + } + + public static Tuple2 addLabelHyperlinkWithIcon(GridPane gridPane, int rowIndex, String title, String value, double top) { + Label label = addLabel(gridPane, rowIndex, title, top); + + HyperlinkWithIcon textField = new HyperlinkWithIcon(value, AwesomeIcon.EXTERNAL_LINK); + GridPane.setRowIndex(textField, rowIndex); + GridPane.setColumnIndex(textField, 1); + GridPane.setMargin(textField, new Insets(top, 0, 0, 0)); + gridPane.getChildren().add(textField); + + return new Tuple2<>(label, textField); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Label + TextArea /////////////////////////////////////////////////////////////////////////////////////////// @@ -357,6 +384,10 @@ public class FormBuilder { // Label + CheckBox /////////////////////////////////////////////////////////////////////////////////////////// + public static Tuple2 addLabelCheckBox(GridPane gridPane, int rowIndex, String title) { + return addLabelCheckBox(gridPane, rowIndex, title, "", 0); + } + public static Tuple2 addLabelCheckBox(GridPane gridPane, int rowIndex, String title, String checkBoxTitle) { return addLabelCheckBox(gridPane, rowIndex, title, checkBoxTitle, 0); } diff --git a/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java b/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java index 587da3dde6..bed40bb502 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java @@ -68,7 +68,7 @@ public class PeerManager implements ConnectionListener, MessageListener { this.seedNodeAddresses = new HashSet<>(seedNodeAddresses); networkNode.addConnectionListener(this); dbStorage = new Storage<>(storageDir); - HashSet persistedPeers = dbStorage.initAndGetPersisted("persistedPeers"); + HashSet persistedPeers = dbStorage.initAndGetPersisted("PersistedPeers"); if (persistedPeers != null) { log.info("We have persisted reported peers. persistedPeers.size()=" + persistedPeers.size()); this.persistedPeers.addAll(persistedPeers);