Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Disable action button and label it "Fully funded" when not participat…
Browse files Browse the repository at this point in the history
…ing and all pledges are gathered. Feedback from Manfred and Lloydy
  • Loading branch information
mikehearn committed Dec 10, 2014
1 parent 47857eb commit d2cc514
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions client/src/main/java/lighthouse/controls/ProjectView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.binding.StringExpression;
import javafx.beans.property.LongProperty;
Expand Down Expand Up @@ -107,14 +108,16 @@ public class ProjectView extends HBox {
@Nullable private Sha256Hash myPledgeHash;

private String goalAmountFormatStr;
private BooleanBinding isFullyFundedAndNotParticipating;

private enum Mode {
OPEN_FOR_PLEDGES,
PLEDGED,
CAN_CLAIM,
CLAIMED,
}
private Mode mode, priorMode;
private SimpleObjectProperty<Mode> mode = new SimpleObjectProperty<>(Mode.OPEN_FOR_PLEDGES);
private Mode priorMode;

public ProjectView() {
// Don't try and access Main.backend here in case you race with startup.
Expand Down Expand Up @@ -157,6 +160,11 @@ public UIBindings() {
// - Make the action button update when the amount pledged changes.
pledgedValue.addListener(o -> pledgedValueChanged(goalAmount, pledgedValue));
pledgedValueChanged(goalAmount, pledgedValue);
isFullyFundedAndNotParticipating =
pledgedValue.isEqualTo(project.get().getGoalAmount().longValue()).and(
mode.isEqualTo(Mode.OPEN_FOR_PLEDGES)
);
actionButton.disableProperty().bind(isFullyFundedAndNotParticipating);

// - Put pledges into the list view.
ObservableList<LHProtos.Pledge> list1 = FXCollections.observableArrayList();
Expand Down Expand Up @@ -194,7 +202,7 @@ public void updateForVisibility(boolean visible, @Nullable ObservableMap<Project
checkStatus.addListener(o -> updateInfoBar());
// Don't let the user perform an action whilst loading or if there's an error.
actionButton.disableProperty().unbind();
actionButton.disableProperty().bind(checkStatus.isNotNull());
actionButton.disableProperty().bind(isFullyFundedAndNotParticipating.or(checkStatus.isNotNull()));
updateInfoBar();
} else {
// Take the back keyboard shortcut out later, because removing an accelerator whilst its callback is being
Expand Down Expand Up @@ -290,9 +298,15 @@ private void pledgedValueChanged(long goalAmount, LongProperty pledgedValue) {

private void updateGUIForState() {
coverImage.setEffect(null);
switch (mode) {
actionButton.setDisable(false);
switch (mode.get()) {
case OPEN_FOR_PLEDGES:
actionButton.setText("Pledge");
if (pledgedValue.get() == project.get().getGoalAmount().longValue()) {
actionButton.setText("Fully funded");
actionButton.setDisable(true);
} else {
actionButton.setText("Pledge");
}
break;
case PLEDGED:
actionButton.setText("Revoke");
Expand All @@ -315,18 +329,19 @@ private void updateGUIForState() {
}

private void setModeFor(Project project, long value) {
priorMode = mode;
mode = Mode.OPEN_FOR_PLEDGES;
priorMode = mode.get();
Mode newMode = Mode.OPEN_FOR_PLEDGES;
if (projectStates.get(project.getID()).state == LighthouseBackend.ProjectState.CLAIMED) {
mode = Mode.CLAIMED;
newMode = Mode.CLAIMED;
} else {
if (Main.wallet.getPledgedAmountFor(project) > 0)
mode = Mode.PLEDGED;
newMode = Mode.PLEDGED;
if (value >= project.getGoalAmount().value && Main.wallet.isProjectMine(project))
mode = Mode.CAN_CLAIM;
newMode = Mode.CAN_CLAIM;
}
log.info("Mode is {}", mode);
if (priorMode == null) priorMode = mode;
log.info("Mode is {}", newMode);
mode.set(newMode);
if (priorMode == null) priorMode = newMode;
updateGUIForState();
}

Expand Down Expand Up @@ -379,7 +394,7 @@ private void backClicked(@Nullable ActionEvent event) {
@FXML
private void actionClicked(ActionEvent event) {
final Project p = project.get();
switch (mode) {
switch (mode.get()) {
case OPEN_FOR_PLEDGES:
makePledge(p);
break;
Expand Down Expand Up @@ -411,7 +426,7 @@ private void makePledge(Project p) {
window.project = p;
window.setLimits(p.getGoalAmount().subtract(Coin.valueOf(pledgedValue.get())), p.getMinPledgeAmount());
window.onSuccess = () -> {
mode = Mode.PLEDGED;
mode.set(Mode.PLEDGED);
updateGUIForState();
};
}
Expand All @@ -420,7 +435,7 @@ private void claimPledges(Project p) {
log.info("Claim button clicked for {}", p);
Main.OverlayUI<RevokeAndClaimWindow> overlay = RevokeAndClaimWindow.openForClaim(p, pledges);
overlay.controller.onSuccess = () -> {
mode = Mode.OPEN_FOR_PLEDGES;
mode.set(Mode.OPEN_FOR_PLEDGES);
updateGUIForState();
};
}
Expand All @@ -432,7 +447,7 @@ private void revokePledge(Project project) {

Main.OverlayUI<RevokeAndClaimWindow> overlay = RevokeAndClaimWindow.openForRevoke(pledge);
overlay.controller.onSuccess = () -> {
mode = Mode.OPEN_FOR_PLEDGES;
mode.set(Mode.OPEN_FOR_PLEDGES);
updateGUIForState();
};
}
Expand Down

0 comments on commit d2cc514

Please sign in to comment.