Skip to content

Commit

Permalink
Store preference for Dark Mode as int32 css_theme
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz committed Aug 29, 2019
1 parent 8d8e8dc commit 61976b0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ message PreferencesPayload {
int32 ignore_dust_threshold = 51;
double buyer_security_deposit_as_percent_for_crypto = 52;
int32 block_notify_port = 53;
bool use_dark_mode = 54;
int32 css_theme = 54;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 8 additions & 7 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
import javax.inject.Singleton;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleLongProperty;

import javafx.collections.FXCollections;
Expand Down Expand Up @@ -122,7 +124,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
@Getter
private final BooleanProperty useAnimationsProperty = new SimpleBooleanProperty(prefPayload.isUseAnimations());
@Getter
private final BooleanProperty useDarkModeProperty = new SimpleBooleanProperty(prefPayload.isUseDarkMode());
private final IntegerProperty cssThemeProperty = new SimpleIntegerProperty(prefPayload.getCssTheme());
@Getter
private final BooleanProperty useCustomWithdrawalTxFeeProperty = new SimpleBooleanProperty(prefPayload.isUseCustomWithdrawalTxFee());
@Getter
Expand Down Expand Up @@ -175,9 +177,8 @@ public Preferences(Storage<PreferencesPayload> storage,
persist();
});

useDarkModeProperty.addListener((ov) -> {
prefPayload.setUseDarkMode(useDarkModeProperty.get());
GlobalSettings.setUseDarkMode(prefPayload.isUseDarkMode());
cssThemeProperty.addListener((ov) -> {
prefPayload.setCssTheme(cssThemeProperty.get());
persist();
});

Expand Down Expand Up @@ -340,8 +341,8 @@ public void setUseAnimations(boolean useAnimations) {
this.useAnimationsProperty.set(useAnimations);
}

public void setUseDarkMode(boolean useDarkMode) {
this.useDarkModeProperty.set(useDarkMode);
public void setCssTheme(boolean useDarkMode) {
this.cssThemeProperty.set(useDarkMode == true ? 1 : 0);
}

public void addFiatCurrency(FiatCurrency tradeCurrency) {
Expand Down Expand Up @@ -834,7 +835,7 @@ private interface ExcludesDelegateMethods {

void setUseAnimations(boolean useAnimations);

void setUseDarkMode(boolean useDarkMode);
void setCssTheme(int cssTheme);

void setUserLanguage(@NotNull String userLanguageCode);

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/bisq/core/user/PreferencesPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public final class PreferencesPayload implements PersistableEnvelope {
private long buyerSecurityDepositAsLong;

private boolean useAnimations;
private boolean useDarkMode;
private int cssTheme;
@Nullable
private PaymentAccount selectedPaymentAccountForCreateOffer;
private boolean payFeeInBtc = true;
Expand Down Expand Up @@ -171,7 +171,7 @@ public Message toProtoMessage() {
.setDirectoryChooserPath(directoryChooserPath)
.setBuyerSecurityDepositAsLong(buyerSecurityDepositAsLong)
.setUseAnimations(useAnimations)
.setUseDarkMode(useDarkMode)
.setCssTheme(cssTheme)
.setPayFeeInBtc(payFeeInBtc)
.setBridgeOptionOrdinal(bridgeOptionOrdinal)
.setTorTransportOrdinal(torTransportOrdinal)
Expand Down Expand Up @@ -249,7 +249,7 @@ public static PersistableEnvelope fromProto(protobuf.PreferencesPayload proto, C
proto.getDirectoryChooserPath(),
proto.getBuyerSecurityDepositAsLong(),
proto.getUseAnimations(),
proto.getUseDarkMode(),
proto.getCssTheme(),
paymentAccount,
proto.getPayFeeInBtc(),
proto.getBridgeAddressesList().isEmpty() ? null : new ArrayList<>(proto.getBridgeAddressesList()),
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/main/java/bisq/desktop/app/BisqApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ private Scene createAndConfigScene(MainView mainView, Injector injector) {
addSceneKeyEventHandler(scene, injector);

loadSceneStyles(scene, injector);
injector.getInstance(Preferences.class).getUseDarkModeProperty().addListener((ov) -> {
injector.getInstance(Preferences.class).getCssThemeProperty().addListener((ov) -> {
loadSceneStyles(scene, injector);
});
return scene;
}

private void loadSceneStyles(Scene scene, Injector injector) {
Boolean useDarkMode = injector.getInstance(Preferences.class).isUseDarkMode();
Boolean useDarkMode = (injector.getInstance(Preferences.class).getCssTheme() == 1);
String colorSheet = "/bisq/desktop/colors-light.css";
if (useDarkMode)
colorSheet = "/bisq/desktop/colors-dark.css";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ private void activateDisplayPreferences() {
useAnimations.setSelected(preferences.isUseAnimations());
useAnimations.setOnAction(e -> preferences.setUseAnimations(useAnimations.isSelected()));

useDarkMode.setSelected(preferences.isUseDarkMode());
useDarkMode.setOnAction(e -> preferences.setUseDarkMode(useDarkMode.isSelected()));
useDarkMode.setSelected(preferences.getCssTheme() == 1);
useDarkMode.setOnAction(e -> preferences.setCssTheme(useDarkMode.isSelected()));

// useStickyMarketPriceCheckBox.setSelected(preferences.isUseStickyMarketPrice());
// useStickyMarketPriceCheckBox.setOnAction(e -> preferences.setUseStickyMarketPrice(useStickyMarketPriceCheckBox.isSelected()));
Expand Down

0 comments on commit 61976b0

Please sign in to comment.