Merge branch 'removeFriend' into 'master'
Add remove friend See merge request cse1105/2018-2019/oopp-group-43/template!87
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
39
src/Client/src/main/resources/fxml/RemoveFriend.fxml
Normal file
39
src/Client/src/main/resources/fxml/RemoveFriend.fxml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="287.0" prefWidth="187.0" style="-fx-background-color: #e2f0c8;" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.FriendController">
|
||||
<children>
|
||||
<Text fill="#00650d" layoutX="114.0" layoutY="64.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Remove Friend" textAlignment="CENTER" wrappingWidth="234.96600341796875">
|
||||
<font>
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="removeUserNameText" layoutX="140.0" layoutY="100.0" prefHeight="35.0" prefWidth="183.0" promptText="Username">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<Button fx:id="removeButton" layoutX="206.0" layoutY="154.0" mnemonicParsing="false" onAction="#removeFriend" style="-fx-background-color: #005e07;" text="Remove!" textFill="#c4eec9">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<ImageView fitHeight="80.0" fitWidth="349.0" layoutY="211.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/grass.png"/>
|
||||
</image>
|
||||
</ImageView>
|
||||
<ImageView fitHeight="150.0" fitWidth="200.0" layoutY="43.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/friends.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -1,12 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.chart.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.chart.PieChart?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
@@ -23,9 +16,8 @@
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
<?import javafx.scene.control.Tooltip?>
|
||||
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
@@ -607,6 +599,30 @@
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
<Button fx:id="addFriend" contentDisplay="RIGHT" layoutX="575.0" layoutY="75.0" mnemonicParsing="false" onAction="#openAddFriend" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Add friend" textFill="#29721a">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="74.0" fitWidth="64.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/friend2.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="removeFriend" contentDisplay="RIGHT" layoutX="575.0" layoutY="150.0" mnemonicParsing="false" onAction="#openRemoveFriend" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Remove friend" textFill="#29721a">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="74.0" fitWidth="64.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/remove_friend.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
|
||||
BIN
src/Client/src/main/resources/icons/remove_friend.png
Normal file
BIN
src/Client/src/main/resources/icons/remove_friend.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user