Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage startup popups #2701

Merged
merged 4 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions desktop/src/main/java/bisq/desktop/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@
import bisq.desktop.main.offer.BuyOfferView;
import bisq.desktop.main.offer.SellOfferView;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.DaoLaunchWindow;
import bisq.desktop.main.portfolio.PortfolioView;
import bisq.desktop.main.settings.SettingsView;
import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.Transitions;

import bisq.core.exceptions.BisqException;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res;
import bisq.core.user.DontShowAgainLookup;
import bisq.core.util.BSFormatter;

import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.app.Version;
import bisq.common.util.Tuple2;
import bisq.common.util.Utilities;
Expand Down Expand Up @@ -81,7 +77,6 @@
import javafx.scene.layout.VBox;
import javafx.scene.text.TextAlignment;

import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -388,22 +383,6 @@ protected Tooltip computeValue() {

transitions.fadeOutAndRemove(splashScreen, 1500, actionEvent -> {
disposeSplashScreen();

if (DevEnv.isDaoActivated()) {
String daoLaunchPopupKey = "daoLaunchPopup";

if (DontShowAgainLookup.showAgain(daoLaunchPopupKey)) {
new DaoLaunchWindow()
.headLine(Res.get("popup.dao.launch.headline"))
.closeButtonText(Res.get("shared.dismiss"))
.actionButtonText(Res.get("shared.learnMore"))
.onAction(() -> GUIUtil.openWebPage("https://docs.bisq.network/dao.html"))
.buttonAlignment(HPos.CENTER)
.show();

DontShowAgainLookup.dontShowAgain(daoLaunchPopupKey, true);
}
}
});
}
});
Expand Down
48 changes: 45 additions & 3 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import bisq.desktop.common.model.ViewModel;
import bisq.desktop.components.BalanceWithConfirmationTextField;
import bisq.desktop.components.TxIdTextField;
import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.main.overlays.notifications.NotificationCenter;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.DaoLaunchWindow;
import bisq.desktop.main.overlays.windows.DisplayAlertMessageWindow;
import bisq.desktop.main.overlays.windows.TacWindow;
import bisq.desktop.main.overlays.windows.TorNetworkSettingsWindow;
Expand Down Expand Up @@ -64,6 +66,8 @@

import com.google.inject.Inject;

import javafx.geometry.HPos;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.monadic.MonadicBinding;

Expand All @@ -79,7 +83,10 @@

import javafx.collections.ObservableList;

import java.util.Comparator;
import java.util.Date;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;

import lombok.Getter;
Expand Down Expand Up @@ -120,6 +127,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
private Timer checkNumberOfP2pNetworkPeersTimer;
@SuppressWarnings("FieldCanBeLocal")
private MonadicBinding<Boolean> tradesAndUIReady;
private Queue<Overlay> popupQueue = new PriorityQueue<>(Comparator.comparing(Overlay::getDisplayOrderPriority));


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -255,6 +263,9 @@ void onSplashScreenRemoved() {
// Delay that as we want to know what is the current path of the navigation which is set
// in MainView showAppScreen handler
notificationCenter.onAllServicesAndViewsInitialized();

maybeAddDaoLaunchWindowToQueue();
maybeShowPopupsFromQueue();
}

void onOpenDownloadWindow() {
Expand Down Expand Up @@ -342,9 +353,10 @@ private void setupHandlers() {
.show());
bisqSetup.setDisplayLocalhostHandler(key -> {
if (!DevEnv.isDevMode()) {
new Popup<>().backgroundInfo(Res.get("popup.bitcoinLocalhostNode.msg"))
.dontShowAgainId(key)
.show();
Overlay popup = new Popup<>().backgroundInfo(Res.get("popup.bitcoinLocalhostNode.msg"))
.dontShowAgainId(key);
popup.setDisplayOrderPriority(5);
popupQueue.add(popup);
}
});

Expand Down Expand Up @@ -603,4 +615,34 @@ public ObservableList<PriceFeedComboBoxItem> getPriceFeedComboBoxItems() {
public BooleanProperty getShowDaoUpdatesNotification() {
return daoPresentation.getShowDaoUpdatesNotification();
}

private void maybeAddDaoLaunchWindowToQueue() {
if (DevEnv.isDaoActivated()) {
String daoLaunchPopupKey = "daoLaunchPopup";
if (DontShowAgainLookup.showAgain(daoLaunchPopupKey)) {
DaoLaunchWindow daoLaunchWindow = new DaoLaunchWindow()
.headLine(Res.get("popup.dao.launch.headline"))
.closeButtonText(Res.get("shared.dismiss"))
.actionButtonText(Res.get("shared.learnMore"))
.onAction(() -> GUIUtil.openWebPage("https://docs.bisq.network/dao.html"))
.buttonAlignment(HPos.CENTER);
daoLaunchWindow.setDisplayOrderPriority(1);
popupQueue.add(daoLaunchWindow);

DontShowAgainLookup.dontShowAgain(daoLaunchPopupKey, true);
}
}
}

private void maybeShowPopupsFromQueue() {
if (!popupQueue.isEmpty()) {
Overlay overlay = popupQueue.poll();
overlay.getIsHiddenProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
UserThread.runAfter(this::maybeShowPopupsFromQueue, 2);
}
});
overlay.show();
}
}
}
15 changes: 14 additions & 1 deletion desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
import javafx.geometry.Insets;
import javafx.geometry.Pos;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;

import javafx.collections.ObservableList;
Expand All @@ -84,6 +86,8 @@
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down Expand Up @@ -134,7 +138,6 @@ protected enum Type {
}

protected final static double DEFAULT_WIDTH = 668;

protected Stage stage;
protected GridPane gridPane;
protected Pane owner;
Expand All @@ -147,6 +150,15 @@ protected enum Type {
private boolean showBusyAnimation;
protected boolean hideCloseButton;
protected boolean isDisplayed;

@Getter
protected BooleanProperty isHiddenProperty = new SimpleBooleanProperty();

// Used when a priority queue is used for displaying order of popups. Higher numbers mean lower priority
@Setter
@Getter
protected Integer displayOrderPriority = Integer.MAX_VALUE;

protected boolean useAnimation = true;

protected Label headlineIcon, headLineLabel, messageLabel;
Expand Down Expand Up @@ -207,6 +219,7 @@ public void hide() {
animateHide();
}
isDisplayed = false;
isHiddenProperty.set(true);
}

protected void animateHide() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

@Slf4j
public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
private static final double DURATION = 400;

private ImageView sectionScreenshot;
private ToggleGroup sectionButtonsGroup;
private ArrayList<Section> sections = new ArrayList<>();
Expand All @@ -72,22 +74,22 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
private Timeline slideTimeline;
private Section selectedSection;


///////////////////////////////////////////////////////////////////////////////////////////
// Public API
///////////////////////////////////////////////////////////////////////////////////////////


@Override
public void show() {
width = 1003;
super.show();
}


///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////


@Override
protected void createGridPane() {
super.createGridPane();
Expand All @@ -110,7 +112,6 @@ protected void addHeadLine() {

@Override
protected void addMessage() {

sections.add(new Section(Res.get("popup.dao.launch.governance.title"), Res.get("popup.dao.launch.governance"),
"dao-screenshot-governance"));
sections.add(new Section(Res.get("popup.dao.launch.trading.title"), Res.get("popup.dao.launch.trading"),
Expand All @@ -131,12 +132,7 @@ protected void addMessage() {
protected void onShow() {
display();

Timeline timeline = new Timeline(new KeyFrame(
Duration.millis(500),
ae -> slideTimeline.playFromStart()
));

timeline.play();
slideTimeline.playFrom(Duration.millis(2 * DURATION));
}

@Override
Expand Down Expand Up @@ -183,7 +179,6 @@ private void startAutoSectionChange() {
}

private void createSlideControls() {

sectionButtonsGroup = new ToggleGroup();

HBox slideButtons = new HBox();
Expand Down Expand Up @@ -257,8 +252,6 @@ private void goToNextSection() {
private void createSlideAnimation() {
slideTimeline = new Timeline();

double duration = 400;

Interpolator interpolator = Interpolator.EASE_OUT;
ObservableList<KeyFrame> keyFrames = slideTimeline.getKeyFrames();

Expand All @@ -267,7 +260,7 @@ private void createSlideAnimation() {
keyFrames.add(new KeyFrame(Duration.millis(0),
new KeyValue(sectionScreenshot.opacityProperty(), 1, interpolator),
new KeyValue(sectionScreenshot.translateXProperty(), 0, interpolator)));
keyFrames.add(new KeyFrame(Duration.millis(duration),
keyFrames.add(new KeyFrame(Duration.millis(DURATION),
event -> {
sectionDescriptionLabel.setText(selectedSection.description);
sectionScreenshot.setId(selectedSection.imageId);
Expand All @@ -277,24 +270,20 @@ private void createSlideAnimation() {

double startX = imageWidth;

keyFrames.add(new KeyFrame(Duration.millis(duration),
keyFrames.add(new KeyFrame(Duration.millis(DURATION),
new KeyValue(sectionScreenshot.opacityProperty(), 0, interpolator),
new KeyValue(sectionScreenshot.translateXProperty(), startX, interpolator)));
duration += 400;
keyFrames.add(new KeyFrame(Duration.millis(duration),
keyFrames.add(new KeyFrame(Duration.millis(DURATION * 2),
new KeyValue(sectionScreenshot.opacityProperty(), 1, interpolator),
new KeyValue(sectionScreenshot.translateXProperty(), 0, interpolator)));

}

protected double getDuration(double duration) {
return useAnimation && GlobalSettings.getUseAnimations() ? duration : 1;
}

private class SectionButton extends AutoTooltipToggleButton {

int index;

SectionButton(String title, int index) {
super(title);
this.index = index;
Expand All @@ -306,7 +295,6 @@ private class SectionButton extends AutoTooltipToggleButton {

this.setOnAction(event -> autoPlayTimeline.stop());
}

}

private class Section {
Expand Down