Skip to content

Commit

Permalink
Create separate ThemeService
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Nov 25, 2023
1 parent a49a2c8 commit 2c79f68
Show file tree
Hide file tree
Showing 41 changed files with 899 additions and 714 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/faforever/client/FafClientApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.faforever.client.notification.NotificationService;
import com.faforever.client.notification.Severity;
import com.faforever.client.svg.SvgImageLoaderFactory;
import com.faforever.client.theme.ThemeService;
import com.faforever.client.theme.UiService;
import com.faforever.client.ui.StageHolder;
import com.faforever.client.ui.taskbar.WindowsTaskbarProgressUpdater;
Expand Down Expand Up @@ -62,7 +63,8 @@ public void start(Stage stage) {
try {
StageHolder.setStage(stage);
FxStage fxStage = FxStage.configure(stage)
.withSceneFactory(parent -> applicationContext.getBean(UiService.class).createScene(parent))
.withSceneFactory(
parent -> applicationContext.getBean(ThemeService.class).createScene(parent))

Check warning on line 67 in src/main/java/com/faforever/client/FafClientApplication.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/faforever/client/FafClientApplication.java#L66-L67

Added lines #L66 - L67 were not covered by tests
.apply();

fxStage.getStage().setOnCloseRequest(this::closeMainWindow);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/faforever/client/audio/AudioService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.faforever.client.audio;

import com.faforever.client.preferences.NotificationPrefs;
import com.faforever.client.theme.UiService;
import com.faforever.client.theme.ThemeService;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.media.AudioClip;
Expand Down Expand Up @@ -30,7 +30,7 @@ public class AudioService implements InitializingBean {
private static final long MILLISECONDS_SILENT_AFTER_SOUND = 30000;

private final AudioClipPlayer audioClipPlayer;
private final UiService uiService;
private final ThemeService themeService;
private final NotificationPrefs notificationPrefs;

private final BooleanProperty playSounds = new SimpleBooleanProperty();
Expand Down Expand Up @@ -69,7 +69,7 @@ private void loadSounds() throws IOException {
}

private AudioClip loadSound(String sound) throws IOException {
return new AudioClip(uiService.getThemeFileUrl(sound).toString());
return new AudioClip(themeService.getThemeFileUrl(sound).toString());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.preferences.NotificationPrefs;
import com.faforever.client.theme.ThemeService;
import com.faforever.client.theme.UiService;
import com.faforever.client.ui.StageHolder;
import com.faforever.client.user.LoginService;
Expand Down Expand Up @@ -68,11 +69,11 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.faforever.client.theme.UiService.CHAT_CONTAINER;
import static com.faforever.client.theme.UiService.CHAT_SECTION_COMPACT;
import static com.faforever.client.theme.UiService.CHAT_SECTION_EXTENDED;
import static com.faforever.client.theme.UiService.CHAT_TEXT_COMPACT;
import static com.faforever.client.theme.UiService.CHAT_TEXT_EXTENDED;
import static com.faforever.client.theme.ThemeService.CHAT_CONTAINER;
import static com.faforever.client.theme.ThemeService.CHAT_SECTION_COMPACT;
import static com.faforever.client.theme.ThemeService.CHAT_SECTION_EXTENDED;
import static com.faforever.client.theme.ThemeService.CHAT_TEXT_COMPACT;
import static com.faforever.client.theme.ThemeService.CHAT_TEXT_EXTENDED;
import static com.google.common.html.HtmlEscapers.htmlEscaper;
import static java.time.temporal.ChronoUnit.MINUTES;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
Expand Down Expand Up @@ -125,6 +126,7 @@ public abstract class AbstractChatTabController extends TabController {
protected final I18n i18n;
protected final NotificationService notificationService;
protected final UiService uiService;
protected final ThemeService themeService;
protected final WebViewConfigurer webViewConfigurer;
protected final EmoticonService emoticonService;
protected final CountryFlagService countryFlagService;
Expand Down Expand Up @@ -303,7 +305,7 @@ private void initChatView() {
}

private void loadChatContainer() {
try (Reader reader = new InputStreamReader(uiService.getThemeFileUrl(CHAT_CONTAINER).openStream())) {
try (Reader reader = new InputStreamReader(themeService.getThemeFileUrl(CHAT_CONTAINER).openStream())) {
String chatContainerHtml = CharStreams.toString(reader)
.replace("{chat-container-js}", CHAT_JS_RESOURCE.getURL().toExternalForm())
.replace("{auto-linker-js}",
Expand Down Expand Up @@ -492,9 +494,9 @@ private boolean requiresNewChatSection(ChatMessage chatMessage) {
private void appendMessage(ChatMessage chatMessage) throws IOException {
URL themeFileUrl;
if (chatPrefs.getChatFormat() == ChatFormat.COMPACT) {
themeFileUrl = uiService.getThemeFileUrl(CHAT_TEXT_COMPACT);
themeFileUrl = themeService.getThemeFileUrl(CHAT_TEXT_COMPACT);
} else {
themeFileUrl = uiService.getThemeFileUrl(CHAT_TEXT_EXTENDED);
themeFileUrl = themeService.getThemeFileUrl(CHAT_TEXT_EXTENDED);

Check warning on line 499 in src/main/java/com/faforever/client/chat/AbstractChatTabController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/faforever/client/chat/AbstractChatTabController.java#L499

Added line #L499 was not covered by tests
}

String html = renderHtml(chatMessage, themeFileUrl, null);
Expand All @@ -505,9 +507,9 @@ private void appendMessage(ChatMessage chatMessage) throws IOException {
private void appendChatMessageSection(ChatMessage chatMessage) throws IOException {
URL themeFileURL;
if (chatPrefs.getChatFormat() == ChatFormat.COMPACT) {
themeFileURL = uiService.getThemeFileUrl(CHAT_SECTION_COMPACT);
themeFileURL = themeService.getThemeFileUrl(CHAT_SECTION_COMPACT);
} else {
themeFileURL = uiService.getThemeFileUrl(CHAT_SECTION_EXTENDED);
themeFileURL = themeService.getThemeFileUrl(CHAT_SECTION_EXTENDED);

Check warning on line 512 in src/main/java/com/faforever/client/chat/AbstractChatTabController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/faforever/client/chat/AbstractChatTabController.java#L512

Added line #L512 was not covered by tests
}

String html = renderHtml(chatMessage, themeFileURL, ++lastEntryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.preferences.NotificationPrefs;
import com.faforever.client.theme.ThemeService;
import com.faforever.client.theme.UiService;
import com.faforever.client.user.LoginService;
import com.faforever.client.util.TimeService;
Expand Down Expand Up @@ -91,13 +92,13 @@ public class ChannelTabController extends AbstractChatTabController {
public ChannelTabController(WebViewConfigurer webViewConfigurer, LoginService loginService, ChatService chatService,
PlayerService playerService,
TimeService timeService, I18n i18n,
NotificationService notificationService, UiService uiService,
NotificationService notificationService, UiService uiService, ThemeService themeService,
NavigationHandler navigationHandler,
CountryFlagService countryFlagService, EmoticonService emoticonService,
PlatformService platformService, ChatPrefs chatPrefs,
NotificationPrefs notificationPrefs,
FxApplicationThreadExecutor fxApplicationThreadExecutor) {
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService,
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService, themeService,
webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs,
fxApplicationThreadExecutor, navigationHandler);
this.platformService = platformService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.faforever.client.map.generator.MapGeneratorService;
import com.faforever.client.player.CountryFlagService;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.theme.ThemeService;
import com.faforever.client.theme.UiService;
import com.faforever.commons.lobby.GameStatus;
import javafx.beans.binding.Bindings;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class ChatUserItemController extends NodeController<Node> {

private final I18n i18n;
private final UiService uiService;
private final ThemeService themeService;
private final MapService mapService;
private final ChatService chatService;
private final MapGeneratorService mapGeneratorService;
Expand Down Expand Up @@ -240,9 +242,9 @@ private void bindProperties() {

ObservableValue<PlayerStatus> statusProperty = playerProperty.flatMap(PlayerBean::statusProperty);
gameStatusImageView.imageProperty().bind(statusProperty.map(status -> switch (status) {
case HOSTING -> uiService.getThemeImage(UiService.CHAT_LIST_STATUS_HOSTING);
case LOBBYING -> uiService.getThemeImage(UiService.CHAT_LIST_STATUS_LOBBYING);
case PLAYING -> uiService.getThemeImage(UiService.CHAT_LIST_STATUS_PLAYING);
case HOSTING -> themeService.getThemeImage(ThemeService.CHAT_LIST_STATUS_HOSTING);
case LOBBYING -> themeService.getThemeImage(ThemeService.CHAT_LIST_STATUS_LOBBYING);
case PLAYING -> themeService.getThemeImage(ThemeService.CHAT_LIST_STATUS_PLAYING);

Check warning on line 247 in src/main/java/com/faforever/client/chat/ChatUserItemController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/faforever/client/chat/ChatUserItemController.java#L247

Added line #L247 was not covered by tests
default -> null;
}).when(showing));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.preferences.NotificationPrefs;
import com.faforever.client.theme.ThemeService;
import com.faforever.client.theme.UiService;
import com.faforever.client.user.LoginService;
import com.faforever.client.util.TimeService;
Expand Down Expand Up @@ -58,14 +59,15 @@ public class MatchmakingChatController extends AbstractChatTabController {
public MatchmakingChatController(LoginService loginService,
PlayerService playerService, TimeService timeService, I18n i18n,
NotificationService notificationService, UiService uiService,
ThemeService themeService,
NavigationHandler navigationHandler,
ChatService chatService,
WebViewConfigurer webViewConfigurer, CountryFlagService countryFlagService,
EmoticonService emoticonService, ChatPrefs chatPrefs,
NotificationPrefs notificationPrefs,
FxApplicationThreadExecutor fxApplicationThreadExecutor,
JoinDiscordEventHandler joinDiscordEventHandler) {
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService,
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService, themeService,
webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs,
fxApplicationThreadExecutor, navigationHandler);
this.joinDiscordEventHandler = joinDiscordEventHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.faforever.client.player.PrivatePlayerInfoController;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.preferences.NotificationPrefs;
import com.faforever.client.theme.ThemeService;
import com.faforever.client.theme.UiService;
import com.faforever.client.user.LoginService;
import com.faforever.client.util.TimeService;
Expand Down Expand Up @@ -61,13 +62,14 @@ public class PrivateChatTabController extends AbstractChatTabController {
public PrivateChatTabController(LoginService loginService,
PlayerService playerService, TimeService timeService, I18n i18n,
NotificationService notificationService, UiService uiService,
ThemeService themeService,
NavigationHandler navigationHandler,
ChatService chatService,
WebViewConfigurer webViewConfigurer, CountryFlagService countryFlagService,
EmoticonService emoticonService, AvatarService avatarService, ChatPrefs chatPrefs,
NotificationPrefs notificationPrefs,
FxApplicationThreadExecutor fxApplicationThreadExecutor) {
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService,
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService, themeService,
webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs,
fxApplicationThreadExecutor, navigationHandler);
this.avatarService = avatarService;
Expand Down
Loading

0 comments on commit 2c79f68

Please sign in to comment.