From ee0d70647cafd1d46175b1f2ecf544f25408a422 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Mon, 31 Aug 2020 19:53:14 +0200 Subject: [PATCH 1/3] Edited onRestore method in ChatScene. --- .../java/envoy/client/ui/controller/ChatScene.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index c4e286b..1ad5d6e 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -346,7 +346,18 @@ public final class ChatScene implements Restorable { } @Override - public void onRestore() { updateRemainingCharsLabel(); } + public void onRestore() { + updateRemainingCharsLabel(); + settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE))); + voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE))); + attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE))); + attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE); + messageSearchButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("search", DEFAULT_ICON_SIZE))); + clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); + chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); + if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); + else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43)); + } /** * Actions to perform when the list of contacts has been clicked. From aa992e2bcfbf2214ae754b162ca467ac8895b45f Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Wed, 2 Sep 2020 11:10:05 +0200 Subject: [PATCH 2/3] Implemented custom preview support on theme change. --- .../envoy/client/ui/controller/ChatScene.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 1ad5d6e..a35a503 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -29,7 +29,9 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; -import javafx.scene.layout.*; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.FileChooser; @@ -145,6 +147,7 @@ public final class ChatScene implements Restorable { private boolean recording; private Attachment pendingAttachment; private boolean postingPermanentlyDisabled; + private boolean isCustomAttachmentImage = false; private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap(); @@ -152,7 +155,7 @@ public final class ChatScene implements Restorable { private static final EventBus eventBus = EventBus.getInstance(); private static final Logger logger = EnvoyLog.getLogger(ChatScene.class); - private static final Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20); + private static Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20); private static final int MAX_MESSAGE_LENGTH = 255; private static final int DEFAULT_ICON_SIZE = 16; @@ -283,6 +286,20 @@ public final class ChatScene implements Restorable { }); eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { newGroupButton.setDisable(!e.get()); })); + + eventBus.register(ThemeChangeEvent.class, e -> { + settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE))); + voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE))); + attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE))); + DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20); + attachmentView.setImage(isCustomAttachmentImage ? attachmentView.getImage() : DEFAULT_ATTACHMENT_VIEW_IMAGE); + messageSearchButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("search", DEFAULT_ICON_SIZE))); + clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); + chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); + messageList.setCellFactory(MessageListCell::new); + if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); + else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43)); + }); } private AnchorPane createOfflineNote() { @@ -348,15 +365,6 @@ public final class ChatScene implements Restorable { @Override public void onRestore() { updateRemainingCharsLabel(); - settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE))); - voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE))); - attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE))); - attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE); - messageSearchButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("search", DEFAULT_ICON_SIZE))); - clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); - chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); - if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); - else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43)); } /** @@ -523,8 +531,10 @@ public final class ChatScene implements Restorable { pendingAttachment = new Attachment(fileBytes, file.getName(), type); checkPostConditions(false); // Setting the preview image as image of the attachmentView - if (type == AttachmentType.PICTURE) + if (type == AttachmentType.PICTURE) { attachmentView.setImage(new Image(new ByteArrayInputStream(fileBytes), DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE, true, true)); + isCustomAttachmentImage = true; + } attachmentView.setVisible(true); } catch (final IOException e) { new Alert(AlertType.ERROR, "The selected file could not be loaded!").showAndWait(); @@ -705,6 +715,7 @@ public final class ChatScene implements Restorable { messageTextArea.setText(""); postButton.setDisable(true); updateRemainingCharsLabel(); + isCustomAttachmentImage = false; } /** From dd2e09b6dc0db5ebc41edcb6e840649b7e65f41e Mon Sep 17 00:00:00 2001 From: DieGurke Date: Wed, 2 Sep 2020 11:31:21 +0200 Subject: [PATCH 3/3] Apply suggestions from code review from @CyB3RC0nN0R Co-authored-by: CyB3RC0nN0R --- client/src/main/java/envoy/client/ui/controller/ChatScene.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 702e18a..d2b2184 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -134,7 +134,7 @@ public final class ChatScene implements Restorable { private boolean recording; private Attachment pendingAttachment; private boolean postingPermanentlyDisabled; - private boolean isCustomAttachmentImage = false; + private boolean isCustomAttachmentImage; private final LocalDB localDB = context.getLocalDB(); private final Client client = context.getClient();