use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.
the class FafServiceImplTest method selectAvatar.
@Test
public void selectAvatar() throws Exception {
URL url = new URL("http://example.com");
instance.selectAvatar(new AvatarBean(url, "Description"));
ArgumentCaptor<AvatarChangedEvent> eventCaptor = ArgumentCaptor.forClass(AvatarChangedEvent.class);
verify(eventBus).post(eventCaptor.capture());
AvatarBean avatar = eventCaptor.getValue().getAvatar();
assertThat(avatar, not(nullValue()));
assertThat(avatar.getUrl(), is(url));
assertThat(avatar.getDescription(), is("Description"));
verify(fafServerAccessor).selectAvatar(url);
}
use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.
the class ChatUserContextMenuControllerTest method onSelectAvatar.
@Test
public void onSelectAvatar() throws Exception {
instance.avatarComboBox.show();
WaitForAsyncUtils.waitForAsyncFx(100000, () -> instance.avatarComboBox.getSelectionModel().select(2));
ArgumentCaptor<AvatarBean> captor = ArgumentCaptor.forClass(AvatarBean.class);
verify(avatarService).changeAvatar(captor.capture());
AvatarBean avatarBean = captor.getValue();
assertThat(avatarBean.getUrl(), equalTo(new URL("http://www.example.com/avatar2.png")));
assertThat(avatarBean.getDescription(), is("Avatar Number #2"));
}
use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.
the class PlayerServiceImpl method onAvatarChanged.
@Subscribe
public void onAvatarChanged(AvatarChangedEvent event) {
Player player = getCurrentPlayer().orElseThrow(() -> new IllegalStateException("Player has not been set"));
AvatarBean avatar = event.getAvatar();
if (avatar == null) {
player.setAvatarTooltip(null);
player.setAvatarUrl(null);
} else {
player.setAvatarTooltip(avatar.getDescription());
player.setAvatarUrl(Objects.toString(avatar.getUrl(), null));
}
}
use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.
the class ChatUserContextMenuControllerTest method setUp.
@Before
public void setUp() throws Exception {
instance = new ChatUserContextMenuController(userService, chatService, preferencesService, playerService, gameService, replayService, notificationService, i18n, eventBus, joinGameHelper, avatarService, uiService);
Preferences preferences = mock(Preferences.class);
ChatPrefs chatPrefs = mock(ChatPrefs.class);
ObjectProperty<ChatColorMode> chatColorModeObjectProperty = new SimpleObjectProperty<>();
when(preferencesService.getPreferences()).thenReturn(preferences);
when(preferences.getChat()).thenReturn(chatPrefs);
when(chatPrefs.getUserToColor()).thenReturn(mock(ObservableMap.class));
when(chatPrefs.chatColorModeProperty()).thenReturn(chatColorModeObjectProperty);
when(avatarService.getAvailableAvatars()).thenReturn(CompletableFuture.completedFuture(Arrays.asList(new AvatarBean(new URL("http://www.example.com/avatar1.png"), "Avatar Number #1"), new AvatarBean(new URL("http://www.example.com/avatar2.png"), "Avatar Number #2"), new AvatarBean(new URL("http://www.example.com/avatar3.png"), "Avatar Number #3"))));
loadFxml("theme/chat/chat_user_context_menu.fxml", clazz -> instance);
player = PlayerBuilder.create(TEST_USER_NAME).socialStatus(SELF).avatar(null).game(new Game()).get();
instance.setPlayer(player);
}
use of com.faforever.client.chat.avatar.AvatarBean in project downlords-faf-client by FAForever.
the class ChatUserContextMenuController method loadAvailableAvatars.
private void loadAvailableAvatars() {
avatarService.getAvailableAvatars().thenAccept(avatars -> {
ObservableList<AvatarBean> items = FXCollections.observableArrayList(avatars);
items.add(0, new AvatarBean(null, i18n.get("chat.userContext.noAvatar")));
String currentAvatarUrl = player.getAvatarUrl();
Platform.runLater(() -> {
avatarComboBox.setItems(items);
avatarComboBox.getSelectionModel().select(items.stream().filter(avatarBean -> Objects.equals(Objects.toString(avatarBean.getUrl(), null), currentAvatarUrl)).findFirst().orElse(null));
// Only after the box has been populated and we selected the current value, we add the listener.
// Otherwise the code above already triggers a changeAvatar()
avatarComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
player.setAvatarTooltip(newValue == null ? null : newValue.getDescription());
player.setAvatarUrl(newValue == null ? null : Objects.toString(newValue.getUrl(), null));
avatarService.changeAvatar(newValue);
});
});
});
}
Aggregations