Merge pull request #2701 from ManfredKarrer/manage-startup-popups

Manage startup popups
This commit is contained in:
Christoph Atteneder 2019-04-12 09:52:13 +02:00 committed by GitHub
commit 23ec405868
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 45 deletions

View file

@ -35,21 +35,17 @@ import bisq.desktop.main.market.MarketView;
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;
@ -81,7 +77,6 @@ import javafx.scene.layout.StackPane;
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;
@ -388,22 +383,6 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
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);
}
}
});
}
});

View file

@ -21,8 +21,10 @@ import bisq.desktop.app.BisqApp;
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;
@ -64,6 +66,8 @@ import bisq.common.storage.CorruptedDatabaseFilesHandler;
import com.google.inject.Inject;
import javafx.geometry.HPos;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.monadic.MonadicBinding;
@ -79,7 +83,10 @@ import javafx.beans.property.StringProperty;
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;
@ -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));
///////////////////////////////////////////////////////////////////////////////////////////
@ -255,6 +263,9 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
// 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() {
@ -342,9 +353,10 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
.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);
}
});
@ -603,4 +615,34 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
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();
}
}
}

View file

@ -69,6 +69,8 @@ import javafx.geometry.HPos;
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;
@ -84,6 +86,8 @@ import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@ -134,7 +138,6 @@ public abstract class Overlay<T extends Overlay> {
}
protected final static double DEFAULT_WIDTH = 668;
protected Stage stage;
protected GridPane gridPane;
protected Pane owner;
@ -147,6 +150,15 @@ public abstract class Overlay<T extends Overlay> {
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;
@ -207,6 +219,7 @@ public abstract class Overlay<T extends Overlay> {
animateHide();
}
isDisplayed = false;
isHiddenProperty.set(true);
}
protected void animateHide() {

View file

@ -63,6 +63,8 @@ import static bisq.desktop.util.FormBuilder.getIconButton;
@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<>();
@ -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();
@ -110,7 +112,6 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
@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"),
@ -131,12 +132,7 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
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
@ -183,7 +179,6 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
}
private void createSlideControls() {
sectionButtonsGroup = new ToggleGroup();
HBox slideButtons = new HBox();
@ -257,8 +252,6 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
private void createSlideAnimation() {
slideTimeline = new Timeline();
double duration = 400;
Interpolator interpolator = Interpolator.EASE_OUT;
ObservableList<KeyFrame> keyFrames = slideTimeline.getKeyFrames();
@ -267,7 +260,7 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
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);
@ -277,14 +270,12 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
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) {
@ -292,9 +283,7 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
}
private class SectionButton extends AutoTooltipToggleButton {
int index;
SectionButton(String title, int index) {
super(title);
this.index = index;
@ -306,7 +295,6 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
this.setOnAction(event -> autoPlayTimeline.stop());
}
}
private class Section {