Added ability to change user status
This commit is contained in:
		@@ -297,8 +297,9 @@ public final class ChatScene implements EventListener, Restorable {
 | 
			
		||||
		chatList.setCellFactory(new ListCellFactory<>(ChatControl::new));
 | 
			
		||||
		messageList.setCellFactory(MessageListCell::new);
 | 
			
		||||
		// TODO: cache image
 | 
			
		||||
		if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43));
 | 
			
		||||
		else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
 | 
			
		||||
		if (currentChat != null)
 | 
			
		||||
			if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43));
 | 
			
		||||
			else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Event(eventType = Logout.class, priority = 200)
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,6 @@ import javafx.scene.control.*;
 | 
			
		||||
import javafx.scene.layout.HBox;
 | 
			
		||||
import javafx.stage.DirectoryChooser;
 | 
			
		||||
 | 
			
		||||
import envoy.client.data.Context;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Displays options for downloading {@link envoy.data.Attachment}s.
 | 
			
		||||
 *
 | 
			
		||||
@@ -47,7 +45,7 @@ public final class DownloadSettingsPane extends SettingsPane {
 | 
			
		||||
			final var directoryChooser = new DirectoryChooser();
 | 
			
		||||
			directoryChooser.setTitle("Select the directory where attachments should be saved to");
 | 
			
		||||
			directoryChooser.setInitialDirectory(settings.getDownloadLocation());
 | 
			
		||||
			final var selectedDirectory = directoryChooser.showDialog(Context.getInstance().getSceneContext().getStage());
 | 
			
		||||
			final var selectedDirectory = directoryChooser.showDialog(context.getSceneContext().getStage());
 | 
			
		||||
 | 
			
		||||
			if (selectedDirectory != null) {
 | 
			
		||||
				currentPath.setText(selectedDirectory.getAbsolutePath());
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ import envoy.client.event.ThemeChangeEvent;
 | 
			
		||||
import envoy.client.helper.ShutdownHelper;
 | 
			
		||||
import envoy.client.ui.StatusTrayIcon;
 | 
			
		||||
import envoy.data.User.UserStatus;
 | 
			
		||||
import envoy.event.UserStatusChange;
 | 
			
		||||
 | 
			
		||||
import dev.kske.eventbus.EventBus;
 | 
			
		||||
 | 
			
		||||
@@ -55,13 +56,23 @@ public final class GeneralSettingsPane extends SettingsPane {
 | 
			
		||||
		combobox.setOnAction(e -> { settings.setCurrentTheme(combobox.getValue()); EventBus.getInstance().dispatch(new ThemeChangeEvent()); });
 | 
			
		||||
		getChildren().add(combobox);
 | 
			
		||||
 | 
			
		||||
		final var statusComboBox = new ComboBox<UserStatus>();
 | 
			
		||||
		statusComboBox.getItems().setAll(UserStatus.values());
 | 
			
		||||
		statusComboBox.setValue(UserStatus.ONLINE);
 | 
			
		||||
		statusComboBox.setTooltip(new Tooltip("Change your current status"));
 | 
			
		||||
		// TODO add action when value is changed
 | 
			
		||||
		statusComboBox.setOnAction(e -> {});
 | 
			
		||||
		getChildren().add(statusComboBox);
 | 
			
		||||
		if (context.getClient().isOnline()) {
 | 
			
		||||
			final var statusComboBox = new ComboBox<UserStatus>();
 | 
			
		||||
			statusComboBox.getItems().setAll(UserStatus.values());
 | 
			
		||||
			statusComboBox.setValue(context.getLocalDB().getUser().getStatus());
 | 
			
		||||
			statusComboBox.setTooltip(new Tooltip("Change your current status"));
 | 
			
		||||
			statusComboBox.setOnAction(e -> {
 | 
			
		||||
				final var status = statusComboBox.getValue();
 | 
			
		||||
				if (status == null) return;
 | 
			
		||||
				else {
 | 
			
		||||
					final var user = context.getLocalDB().getUser();
 | 
			
		||||
					user.setStatus(status);
 | 
			
		||||
					// TODO update status in ChatScene
 | 
			
		||||
					context.getClient().send(new UserStatusChange(user.getID(), status));
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
			getChildren().add(statusComboBox);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		final var logoutButton = new Button("Logout");
 | 
			
		||||
		logoutButton.setOnAction(e -> ShutdownHelper.logout());
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,6 @@ import javafx.scene.control.*;
 | 
			
		||||
import javafx.scene.layout.*;
 | 
			
		||||
import javafx.scene.paint.Color;
 | 
			
		||||
 | 
			
		||||
import envoy.client.data.Context;
 | 
			
		||||
import envoy.client.net.Client;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -20,7 +19,7 @@ import envoy.client.net.Client;
 | 
			
		||||
 */
 | 
			
		||||
public abstract class OnlineOnlySettingsPane extends SettingsPane {
 | 
			
		||||
 | 
			
		||||
	protected final Client client = Context.getInstance().getClient();
 | 
			
		||||
	protected final Client client = context.getClient();
 | 
			
		||||
 | 
			
		||||
	private final Tooltip beOnlineReminder = new Tooltip("You need to be online to modify your account.");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package envoy.client.ui.settings;
 | 
			
		||||
 | 
			
		||||
import javafx.scene.layout.VBox;
 | 
			
		||||
 | 
			
		||||
import envoy.client.data.Settings;
 | 
			
		||||
import envoy.client.data.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
@@ -12,7 +12,8 @@ public abstract class SettingsPane extends VBox {
 | 
			
		||||
 | 
			
		||||
	protected String title;
 | 
			
		||||
 | 
			
		||||
	protected static final Settings settings = Settings.getInstance();
 | 
			
		||||
	protected static final Settings	settings	= Settings.getInstance();
 | 
			
		||||
	protected static final Context	context		= Context.getInstance();
 | 
			
		||||
 | 
			
		||||
	protected SettingsPane(String title) { this.title = title; }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,6 @@ import javafx.scene.input.InputEvent;
 | 
			
		||||
import javafx.scene.layout.HBox;
 | 
			
		||||
import javafx.stage.FileChooser;
 | 
			
		||||
 | 
			
		||||
import envoy.client.data.Context;
 | 
			
		||||
import envoy.client.ui.control.ProfilePicImageView;
 | 
			
		||||
import envoy.client.util.IconUtil;
 | 
			
		||||
import envoy.event.*;
 | 
			
		||||
@@ -66,7 +65,7 @@ public final class UserSettingsPane extends OnlineOnlySettingsPane {
 | 
			
		||||
			pictureChooser.setInitialDirectory(new File(System.getProperty("user.home")));
 | 
			
		||||
			pictureChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Pictures", "*.png", "*.jpg", "*.bmp", "*.gif"));
 | 
			
		||||
 | 
			
		||||
			final var file = pictureChooser.showOpenDialog(Context.getInstance().getSceneContext().getStage());
 | 
			
		||||
			final var file = pictureChooser.showOpenDialog(context.getSceneContext().getStage());
 | 
			
		||||
 | 
			
		||||
			if (file != null) {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@
 | 
			
		||||
	-fx-background-radius: 15.0px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.list-cell:selected, .menu-item:hover {
 | 
			
		||||
.list-cell:selected, .menu-item:hover, .combo-box-popup .list-view .list-cell:selected {
 | 
			
		||||
    -fx-background-color: #454c4f;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@
 | 
			
		||||
	-fx-background-color: lightgray;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#message-list, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item, #quick-select-list {
 | 
			
		||||
#message-list, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item, .combo-box-popup .list-view .list-cell, #quick-select-list {
 | 
			
		||||
	-fx-background-color: #222222;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user