diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java
index 5e9072b..f8c744b 100644
--- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java
+++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java
@@ -93,6 +93,10 @@ public class DashBoardController {
@FXML
private Button addFriendButton;
@FXML
+ private Button addFriend;
+ @FXML
+ private Button removeFriend;
+ @FXML
private Button addExtraActivityButton;
@FXML
private Button addExtraActivityButton2;
@@ -466,6 +470,7 @@ public class DashBoardController {
updateFriends();
}
+
/**
* Logs out the user.
* @param event the event (clicking the button)
@@ -570,6 +575,20 @@ public class DashBoardController {
calcStage.show();
}
+ /**
+ * method opens removeFriend scene.
+ * @throws IOException when file is not found
+ */
+ public void openRemoveFriend() throws IOException {
+ Parent calc = Application.load(this.getClass().getClassLoader()
+ .getResource("fxml/RemoveFriend.fxml"));
+ Scene scene = new Scene(calc);
+ Stage calcStage = new Stage();
+ calcStage.setScene(scene);
+ calcStage.setTitle("Remove your friend - " + userService.currentUser.getName());
+ calcStage.show();
+ }
+
/**
* Leaderboard is updating.
* @throws InterruptedException throws exception
diff --git a/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java b/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java
index 1270013..e510048 100644
--- a/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java
+++ b/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java
@@ -132,6 +132,10 @@ public class ExtraActivityController {
});
}
+ /**
+ * add transition animation.
+ * @param node adding animation
+ */
public void addFadeTransAnimation(Node node) {
FadeTransition fade = new FadeTransition(Duration.millis(350), node);
fade.setFromValue(0);
diff --git a/src/Client/src/main/java/greenify/client/controller/FriendController.java b/src/Client/src/main/java/greenify/client/controller/FriendController.java
index 4cbdc42..e4141d0 100644
--- a/src/Client/src/main/java/greenify/client/controller/FriendController.java
+++ b/src/Client/src/main/java/greenify/client/controller/FriendController.java
@@ -23,9 +23,13 @@ public class FriendController {
private Button addButton;
@FXML
private TextField userNameText;
+ @FXML
+ private Button removeButton;
+ @FXML
+ private TextField removeUserNameText;
/**
- * Signs up the user.
+ * Add a new friend.
* @param event the click of the sign up button
*/
@FXML
@@ -58,8 +62,48 @@ public class FriendController {
String friendName = userNameText.getText();
Stage current = (Stage) owner;
dashBoardController.updateAchievements();
+ dashBoardController.updateFriends();
current.close();
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend added!",
userNameText.getText() + " is now your friend!");
}
+
+ /**
+ * Removes one of the friends of the user.
+ * @param event the click of the sign up button
+ */
+ @FXML
+ public void removeFriend(ActionEvent event) throws InterruptedException {
+ //set the window to the current window (for displaying the alerts)
+ Window owner = removeButton.getScene().getWindow();
+ //check if the username field is empty
+ if (removeUserNameText.getText().isEmpty()) {
+ //if so, display an alert
+ UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
+ "Please enter a username!");
+ return;
+ } else if (removeUserNameText.getText().equals(userService.currentUser.getName())) {
+ UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
+ "You are not your friend!");
+ return;
+ } else if (!userService.getFriendNames(userService.currentUser.getName())
+ .contains(removeUserNameText.getText())) {
+ UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
+ "You do not have a friend with this username!");
+ return;
+ } else if (!userService.getAllUsers().contains(removeUserNameText.getText())) {
+ UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
+ "The user does not exist!");
+ return;
+ }
+ //add friend to the current user
+ userService.removeFriend(userService.currentUser.getName(), removeUserNameText.getText());
+ //close the register window after the user has entered all the credentials
+ Stage current = (Stage) owner;
+ dashBoardController.updateFriends();
+ dashBoardController.updateAchievements();
+ current.close();
+ UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend removed!",
+ removeUserNameText.getText() + " is not your friend anymore!");
+ }
}
diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java
index 1ebeac8..a74c818 100644
--- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java
+++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java
@@ -621,6 +621,10 @@ public class RegisterWindowController {
@SuppressWarnings("Duplicates")
public class registerButtonSkin extends ButtonSkin {
+ /**
+ * registers button skins.
+ * @param button clicking
+ */
public registerButtonSkin(Button button) {
super(button);
diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java
index d4ffefc..1c18c41 100644
--- a/src/Client/src/main/java/greenify/client/controller/UserController.java
+++ b/src/Client/src/main/java/greenify/client/controller/UserController.java
@@ -43,6 +43,7 @@ public class UserController {
loginButton.setSkin(new LoginButtonSkin(loginButton));
signUpButton.setSkin(new LoginButtonSkin(signUpButton));
}
+
/**
* Handles when the user clicks on the login button.
* it checks if the username and password fields are filled
@@ -52,7 +53,6 @@ public class UserController {
*/
@FXML
protected void handleLoginButtonAction(ActionEvent event) throws IOException {
-
Window owner = loginButton.getScene().getWindow(); //get the current window
if (usernameField.getText().isEmpty()) {
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
@@ -153,6 +153,10 @@ public class UserController {
@SuppressWarnings("Duplicates")
public class LoginButtonSkin extends ButtonSkin {
+ /**
+ * method for the skin of login button.
+ * @param button clicking
+ */
public LoginButtonSkin(Button button) {
super(button);
ScaleTransition scaleUp = new ScaleTransition(Duration.millis(140));
diff --git a/src/Client/src/main/resources/fxml/RemoveFriend.fxml b/src/Client/src/main/resources/fxml/RemoveFriend.fxml
new file mode 100644
index 0000000..5ea238a
--- /dev/null
+++ b/src/Client/src/main/resources/fxml/RemoveFriend.fxml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Client/src/main/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml
index 35fdf34..b8eba11 100644
--- a/src/Client/src/main/resources/fxml/dashboard.fxml
+++ b/src/Client/src/main/resources/fxml/dashboard.fxml
@@ -1,12 +1,5 @@
-
-
-
-
-
-
-
@@ -23,9 +16,8 @@
-
-
+
@@ -607,6 +599,30 @@
+
+
diff --git a/src/Client/src/main/resources/icons/remove_friend.png b/src/Client/src/main/resources/icons/remove_friend.png
new file mode 100644
index 0000000..f64e849
Binary files /dev/null and b/src/Client/src/main/resources/icons/remove_friend.png differ
diff --git a/src/Server/src/main/java/greenify/server/service/AchievementService.java b/src/Server/src/main/java/greenify/server/service/AchievementService.java
index cc59bdc..6035b6a 100644
--- a/src/Server/src/main/java/greenify/server/service/AchievementService.java
+++ b/src/Server/src/main/java/greenify/server/service/AchievementService.java
@@ -38,6 +38,8 @@ public class AchievementService {
public void achieveSocialButterfly(User user) {
if (user.getFriends().size() >= 3) {
userService.setAchievement(user.getName(), "Social butterfly", true);
+ } else {
+ userService.setAchievement(user.getName(), "Social butterfly", false);
}
}
@@ -48,6 +50,8 @@ public class AchievementService {
public void achieveGreenSaver(User user) {
if (20 > user.getFootPrint()) {
userService.setAchievement(user.getName(), "Green saver", true);
+ } else {
+ userService.setAchievement(user.getName(), "Green saver", false);
}
}
@@ -59,6 +63,8 @@ public class AchievementService {
int vegan = Integer.parseInt(user.getExtraInputs().get("vegan"));
if (vegan > 10) {
userService.setAchievement(user.getName(), "Animal friend", true);
+ } else {
+ userService.setAchievement(user.getName(), "Animal friend", false);
}
}
@@ -70,6 +76,8 @@ public class AchievementService {
int bike = Integer.parseInt(user.getExtraInputs().get("bike"));
if (bike > 15) {
userService.setAchievement(user.getName(), "Tom Dumoulin", true);
+ } else {
+ userService.setAchievement(user.getName(), "Tom Dumoulin", false);
}
}
@@ -81,6 +89,8 @@ public class AchievementService {
int solarPanels = Integer.parseInt(user.getExtraInputs().get("solar_panels"));
if (solarPanels >= 2) {
userService.setAchievement(user.getName(), "Let it shine", true);
+ } else {
+ userService.setAchievement(user.getName(), "Let it shine", false);
}
}