From a820bddde66d7bf6fece0e58b2176301a1545740 Mon Sep 17 00:00:00 2001 From: westerwave Date: Tue, 27 Sep 2016 17:13:36 +0200 Subject: [PATCH 01/27] advance to next snapshot --- src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index 80fa8d3..e0df1d3 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -22,4 +22,4 @@ # SOFTWARE. # -versionNumber=3.4.0 \ No newline at end of file +versionNumber=3.5.0-SNAPSHOT \ No newline at end of file From a422ab2ae8a6da6f34c90cea866e239f94e39cd8 Mon Sep 17 00:00:00 2001 From: westerwave Date: Thu, 29 Sep 2016 00:56:48 +0200 Subject: [PATCH 02/27] move toolbar to own package, start work on tabbed browser, dont add a channel to list if it already exists --- .../app/lsgui/gui/main/LsGuiController.java | 7 ++- .../app/lsgui/gui/main/list/ChannelList.java | 17 +----- .../main/{ => toolbar}/QualityComboBox.java | 2 +- .../gui/main/{ => toolbar}/ServiceCell.java | 2 +- .../main/{ => toolbar}/ServiceComboBox.java | 2 +- .../main/{ => toolbar}/ServiceOperator.java | 2 +- .../gui/main/{ => toolbar}/TopToolBar.java | 4 +- .../gui/twitchbrowser/BrowserController.java | 23 +++----- .../lsgui/gui/twitchbrowser/BrowserTab.java | 34 ++++++++++++ .../gui/twitchbrowser/TwitchItemPane.java | 15 ++---- .../app/lsgui/model/twitch/TwitchService.java | 18 ++++--- .../java/app/lsgui/utils/BrowserCore.java | 54 +++++++++++++------ src/main/resources/fxml/BrowserWindow.fxml | 4 ++ 13 files changed, 114 insertions(+), 70 deletions(-) rename src/main/java/app/lsgui/gui/main/{ => toolbar}/QualityComboBox.java (95%) rename src/main/java/app/lsgui/gui/main/{ => toolbar}/ServiceCell.java (95%) rename src/main/java/app/lsgui/gui/main/{ => toolbar}/ServiceComboBox.java (96%) rename src/main/java/app/lsgui/gui/main/{ => toolbar}/ServiceOperator.java (95%) rename src/main/java/app/lsgui/gui/main/{ => toolbar}/TopToolBar.java (96%) create mode 100644 src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java diff --git a/src/main/java/app/lsgui/gui/main/LsGuiController.java b/src/main/java/app/lsgui/gui/main/LsGuiController.java index 1bf27a6..e4c4caa 100644 --- a/src/main/java/app/lsgui/gui/main/LsGuiController.java +++ b/src/main/java/app/lsgui/gui/main/LsGuiController.java @@ -28,6 +28,9 @@ import app.lsgui.gui.main.infopanel.ChannelInfoPanel; import app.lsgui.gui.main.list.ChannelList; +import app.lsgui.gui.main.toolbar.QualityComboBox; +import app.lsgui.gui.main.toolbar.ServiceComboBox; +import app.lsgui.gui.main.toolbar.TopToolBar; import app.lsgui.model.IService; import app.lsgui.utils.Settings; import javafx.fxml.FXML; @@ -85,7 +88,7 @@ private void setupChannelList() { }); final ServiceComboBox serviceComboBox = this.topToolBar.getServiceComboBox(); final IService service = serviceComboBox.getSelectionModel().getSelectedItem(); - this.channelList.getStreams().bind(service.getChannelProperty()); + this.channelList.channelListProperty().bind(service.getChannelProperty()); this.channelList.getListView().setUserData(service); this.contentBorderPane.setLeft(this.channelList); } @@ -95,7 +98,7 @@ private void setupChannelInfoPanel() { final ServiceComboBox serviceComboBox = this.topToolBar.getServiceComboBox(); final QualityComboBox qualityComboBox = this.topToolBar.getQualityComboBox(); final ChannelInfoPanel channelInfoPanel = new ChannelInfoPanel(serviceComboBox, qualityComboBox); - channelInfoPanel.getChannelProperty().bind(this.channelList.getSelectedChannelProperty()); + channelInfoPanel.getChannelProperty().bind(this.channelList.selectedChannelProperty()); this.contentBorderPane.setCenter(channelInfoPanel); } diff --git a/src/main/java/app/lsgui/gui/main/list/ChannelList.java b/src/main/java/app/lsgui/gui/main/list/ChannelList.java index 8b192a6..269f16b 100644 --- a/src/main/java/app/lsgui/gui/main/list/ChannelList.java +++ b/src/main/java/app/lsgui/gui/main/list/ChannelList.java @@ -24,7 +24,6 @@ package app.lsgui.gui.main.list; import java.io.IOException; -import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +33,6 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.control.ListView; @@ -75,27 +73,16 @@ private void setupChannelList() { this.channelListView.setCellFactory(listView -> new ChannelCell()); } - public ListProperty getStreams() { + public ListProperty channelListProperty() { return this.channelListProperty; } - public void setChannels(final List channels) { - this.channelListProperty.set(FXCollections.observableList(channels)); - } - public ListView getListView() { return this.channelListView; } - public void setListView(final ListView channelList) { - this.channelListView = channelList; - } - - public ObjectProperty getSelectedChannelProperty() { + public ObjectProperty selectedChannelProperty() { return this.selectedChannelProperty; } - public void setSelectedChannelProperty(final ObjectProperty channelProperty) { - this.selectedChannelProperty = channelProperty; - } } diff --git a/src/main/java/app/lsgui/gui/main/QualityComboBox.java b/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java similarity index 95% rename from src/main/java/app/lsgui/gui/main/QualityComboBox.java rename to src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java index 42ea387..5dbbfa4 100644 --- a/src/main/java/app/lsgui/gui/main/QualityComboBox.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package app.lsgui.gui.main; +package app.lsgui.gui.main.toolbar; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/app/lsgui/gui/main/ServiceCell.java b/src/main/java/app/lsgui/gui/main/toolbar/ServiceCell.java similarity index 95% rename from src/main/java/app/lsgui/gui/main/ServiceCell.java rename to src/main/java/app/lsgui/gui/main/toolbar/ServiceCell.java index aee5e1c..a424ee0 100644 --- a/src/main/java/app/lsgui/gui/main/ServiceCell.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/ServiceCell.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package app.lsgui.gui.main; +package app.lsgui.gui.main.toolbar; import app.lsgui.model.IService; import javafx.scene.control.ListCell; diff --git a/src/main/java/app/lsgui/gui/main/ServiceComboBox.java b/src/main/java/app/lsgui/gui/main/toolbar/ServiceComboBox.java similarity index 96% rename from src/main/java/app/lsgui/gui/main/ServiceComboBox.java rename to src/main/java/app/lsgui/gui/main/toolbar/ServiceComboBox.java index 0a11468..f0d2b15 100644 --- a/src/main/java/app/lsgui/gui/main/ServiceComboBox.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/ServiceComboBox.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package app.lsgui.gui.main; +package app.lsgui.gui.main.toolbar; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/app/lsgui/gui/main/ServiceOperator.java b/src/main/java/app/lsgui/gui/main/toolbar/ServiceOperator.java similarity index 95% rename from src/main/java/app/lsgui/gui/main/ServiceOperator.java rename to src/main/java/app/lsgui/gui/main/toolbar/ServiceOperator.java index 302e6cc..1315837 100644 --- a/src/main/java/app/lsgui/gui/main/ServiceOperator.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/ServiceOperator.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package app.lsgui.gui.main; +package app.lsgui.gui.main.toolbar; import app.lsgui.model.IService; diff --git a/src/main/java/app/lsgui/gui/main/TopToolBar.java b/src/main/java/app/lsgui/gui/main/toolbar/TopToolBar.java similarity index 96% rename from src/main/java/app/lsgui/gui/main/TopToolBar.java rename to src/main/java/app/lsgui/gui/main/toolbar/TopToolBar.java index 839b13a..e60c4ca 100644 --- a/src/main/java/app/lsgui/gui/main/TopToolBar.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/TopToolBar.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package app.lsgui.gui.main; +package app.lsgui.gui.main.toolbar; import org.controlsfx.control.PopOver; import org.slf4j.Logger; @@ -166,7 +166,7 @@ private void importFollowedChannels() { private void changeService(final IService newService) { LOGGER.debug("Change Service to {}", newService.getName().get()); - this.channelList.getStreams().bind(newService.getChannelProperty()); + this.channelList.channelListProperty().bind(newService.getChannelProperty()); this.channelList.getListView().setUserData(newService); if (TwitchUtils.isTwitchService(newService)) { this.importButton.setDisable(false); diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java index 188fa4a..be19f02 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java @@ -23,11 +23,9 @@ */ package app.lsgui.gui.twitchbrowser; -import org.controlsfx.control.GridView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import app.lsgui.model.twitch.ITwitchItem; import app.lsgui.remote.twitch.TwitchBrowserUpdateService; import app.lsgui.utils.BrowserCore; import app.lsgui.utils.Settings; @@ -44,6 +42,8 @@ import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.control.Separator; +import javafx.scene.control.TabPane; +import javafx.scene.control.TabPane.TabClosingPolicy; import javafx.scene.control.TextField; import javafx.scene.control.ToolBar; import javafx.scene.layout.BorderPane; @@ -65,9 +65,10 @@ public final class BrowserController { @FXML private BorderPane browserRootBorderPane; - private ComboBox qualityComboBox; + @FXML + private TabPane browserTabPane; - private GridView browserGridView; + private ComboBox qualityComboBox; private BrowserCore browserCore; public BrowserController() { @@ -78,10 +79,10 @@ public BrowserController() { public void initialize() { this.setupToolBar(); this.setupProgressBar(); - this.setupGrid(); + this.browserTabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS); this.browserCore = BrowserCore.getInstance(); - this.browserCore.setGridView(this.browserGridView); - this.browserRootBorderPane.setCenter(this.browserGridView); + this.browserCore.bindQualityProperty(this.qualityComboBox.getSelectionModel().selectedItemProperty()); + this.browserCore.setTabPane(this.browserTabPane); Platform.runLater(this.browserCore::goToHome); } @@ -155,12 +156,4 @@ private void refreshBrowser() { this.browserCore.refresh(); } - private void setupGrid() { - this.browserGridView = new GridView<>(); - this.browserGridView.setCellFactory( - param -> new TwitchItemPane(this.qualityComboBox.getSelectionModel().selectedItemProperty())); - this.browserGridView.setCellWidth(TwitchItemPane.WIDTH); - this.browserGridView.cellHeightProperty().bind(TwitchItemPane.HEIGHT_PROPERTY); - } - } diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java new file mode 100644 index 0000000..041a26e --- /dev/null +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -0,0 +1,34 @@ +package app.lsgui.gui.twitchbrowser; + +import org.controlsfx.control.GridView; + +import app.lsgui.model.twitch.ITwitchItem; +import javafx.scene.control.Tab; + +public class BrowserTab extends Tab { + + private String name; + + public BrowserTab(final String name) { + this.name = name; + setText(this.name); + setContent(buildGridView()); + } + + public String getName() { + return this.name; + } + + public GridView getGridView() { + return (GridView) getContent(); + } + + private static GridView buildGridView() { + final GridView gridView = new GridView<>(); + gridView.setCellFactory(param -> new TwitchItemPane()); + gridView.setCellWidth(TwitchItemPane.WIDTH); + gridView.cellHeightProperty().bind(TwitchItemPane.HEIGHT_PROPERTY); + return gridView; + } + +} diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java index 44cf7af..4cf7967 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java @@ -30,16 +30,12 @@ import app.lsgui.model.twitch.TwitchChannel; import app.lsgui.model.twitch.TwitchGame; import app.lsgui.utils.BrowserCore; -import app.lsgui.utils.LivestreamerUtils; import app.lsgui.utils.LsGuiUtils; import app.lsgui.utils.Settings; import de.jensd.fx.glyphs.GlyphsDude; import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon; import javafx.beans.property.DoubleProperty; -import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; import javafx.scene.Node; import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; @@ -63,10 +59,9 @@ public final class TwitchItemPane extends GridCell { private TwitchChannel channel; private TwitchGame game; - private StringProperty quality = new SimpleStringProperty(); - public TwitchItemPane(final ReadOnlyObjectProperty quality) { - this.quality.bind(quality); + public TwitchItemPane() { + // Empty Constructor } @Override @@ -159,12 +154,12 @@ private BorderPane createChannelBorderPane() { Tooltip.install(node, titleTooltip); contentBorderPane.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { if (event.getButton() == MouseButton.PRIMARY) { - LivestreamerUtils.startLivestreamer("twitch.tv/" + this.channel.getName().get(), this.quality.get()); + BrowserCore.getInstance().startStream(this.channel.getName().get()); } else if (event.getButton() == MouseButton.SECONDARY) { final ContextMenu contextMenu = new ContextMenu(); final MenuItem startStream = new MenuItem("Start Stream"); - startStream.setOnAction(eventStartContext -> LivestreamerUtils - .startLivestreamer("twitch.tv/" + this.channel.getName().get(), this.quality.get())); + startStream.setOnAction( + eventStartContext -> BrowserCore.getInstance().startStream(this.channel.getName().get())); final MenuItem addToList = new MenuItem("Add Stream To Favourites"); final IService twitchService = Settings.getInstance().getTwitchService(); addToList.setOnAction( diff --git a/src/main/java/app/lsgui/model/twitch/TwitchService.java b/src/main/java/app/lsgui/model/twitch/TwitchService.java index 960bde5..ccd6e21 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchService.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchService.java @@ -82,12 +82,18 @@ public TwitchService(final String name, final String url) { @Override public void addChannel(final String name) { - LOGGER.debug("Add Channel {} to {} Service", name, this.getName().get()); - final TwitchChannel channelToAdd = TwitchUtils.constructTwitchChannel(new JsonObject(), name, false); - final TwitchChannelUpdateService tcus = new TwitchChannelUpdateService(channelToAdd); - tcus.start(); - UPDATESERVICES.put(channelToAdd, tcus); - this.channelList.add(channelToAdd); + final boolean existsAlready = this.channelList.stream() + .anyMatch(channel -> channel.getName().get().equalsIgnoreCase(name)); + if (!existsAlready) { + LOGGER.debug("Add Channel {} to {} Service", name, this.getName().get()); + final TwitchChannel channelToAdd = TwitchUtils.constructTwitchChannel(new JsonObject(), name, false); + final TwitchChannelUpdateService tcus = new TwitchChannelUpdateService(channelToAdd); + tcus.start(); + UPDATESERVICES.put(channelToAdd, tcus); + this.channelList.add(channelToAdd); + } else { + LOGGER.debug("Skipping {}, exists already in list", name); + } } @Override diff --git a/src/main/java/app/lsgui/utils/BrowserCore.java b/src/main/java/app/lsgui/utils/BrowserCore.java index 87bdbb0..4ede933 100644 --- a/src/main/java/app/lsgui/utils/BrowserCore.java +++ b/src/main/java/app/lsgui/utils/BrowserCore.java @@ -29,6 +29,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import app.lsgui.gui.twitchbrowser.BrowserTab; import app.lsgui.model.twitch.ITwitchItem; import app.lsgui.model.twitch.TwitchChannel; import app.lsgui.model.twitch.TwitchChannels; @@ -36,11 +37,14 @@ import app.lsgui.model.twitch.TwitchGames; import app.lsgui.remote.twitch.TwitchAPIClient; import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; +import javafx.scene.Node; import javafx.scene.control.ScrollBar; +import javafx.scene.control.TabPane; /** * @@ -52,8 +56,8 @@ public final class BrowserCore { private static final Logger LOGGER = LoggerFactory.getLogger(BrowserCore.class); private static BrowserCore instance; - private GridView browserGridView; - private String currentGame = ""; + private ObjectProperty qualityProperty = new SimpleObjectProperty<>(); + private TabPane tabPane; private ObjectProperty> items = new SimpleObjectProperty<>( FXCollections.observableArrayList()); private ObjectProperty> activeItems = new SimpleObjectProperty<>( @@ -69,35 +73,45 @@ public static synchronized BrowserCore getInstance() { return instance; } - public void setGridView(final GridView displayGridView) { - this.browserGridView = displayGridView; - this.browserGridView.itemsProperty().bind(this.activeItems); + public void setTabPane(final TabPane tabPane) { + this.tabPane = tabPane; + } + + public void bindQualityProperty(final ReadOnlyObjectProperty qualityProperty) { + this.qualityProperty.bind(qualityProperty); } public void goToHome() { LOGGER.debug("Go to home"); final TwitchGames games = TwitchAPIClient.getInstance().getGamesData(); - this.items.set(games.getGames()); - this.activeItems.set(games.getGames()); - this.scrollToTop(); + if (this.tabPane.getTabs().isEmpty()) { + final BrowserTab homeTab = new BrowserTab("Home"); + homeTab.setClosable(false); + homeTab.getGridView().setItems(games.getGames()); + this.tabPane.getTabs().add(homeTab); + } else { + final GridView gridView = (GridView) this.tabPane.getTabs().get(0).getContent(); + gridView.setItems(games.getGames()); + this.scrollToTop(); + } } public void refresh() { LOGGER.debug("Refresh: redirect to home page"); - if ("".equals(this.currentGame)) { + if (this.tabPane.getSelectionModel().getSelectedIndex() == 0) { this.goToHome(); } else { - this.openGame(this.currentGame); + final BrowserTab currentTab = (BrowserTab) this.tabPane.getSelectionModel().getSelectedItem(); + this.openGame(currentTab.getName()); } } public void openGame(final String game) { LOGGER.debug("Open Data for Game '{}'", game); final TwitchChannels channels = TwitchAPIClient.getInstance().getGameData(game); - this.items.set(channels.getChannels()); - this.activeItems.set(channels.getChannels()); + final BrowserTab gameTab = this.addGameTab(game); + gameTab.getGridView().setItems(channels.getChannels()); this.scrollToTop(); - this.currentGame = game; } public void filter(final String filter) { @@ -117,14 +131,22 @@ public void filter(final String filter) { } private void scrollToTop() { - final ScrollBar vBar = (ScrollBar) this.browserGridView.lookup(".scroll-bar:vertical"); + final Node tabContent = this.tabPane.getTabs().get(0).getContent(); + final ScrollBar vBar = (ScrollBar) tabContent.lookup(".scroll-bar:vertical"); if (vBar != null) { vBar.setValue(0.0D); vBar.setVisible(true); } } - public ObjectProperty> getItems() { - return this.activeItems; + private BrowserTab addGameTab(final String name) { + final BrowserTab gameTab = new BrowserTab(name); + this.tabPane.getTabs().add(gameTab); + return gameTab; + } + + public void startStream(final String string) { + LivestreamerUtils.startLivestreamer("twitch.tv/" + string, this.qualityProperty.get()); + } } diff --git a/src/main/resources/fxml/BrowserWindow.fxml b/src/main/resources/fxml/BrowserWindow.fxml index 2ec68b5..094b8f2 100644 --- a/src/main/resources/fxml/BrowserWindow.fxml +++ b/src/main/resources/fxml/BrowserWindow.fxml @@ -1,5 +1,6 @@ + @@ -7,4 +8,7 @@ +
+ +
From 2ac99638baefd841207fd91f0345cf49970caace Mon Sep 17 00:00:00 2001 From: westerwave Date: Thu, 29 Sep 2016 12:49:59 +0200 Subject: [PATCH 03/27] add custom tabpane --- .../gui/twitchbrowser/BrowserController.java | 29 +++++-------------- .../gui/twitchbrowser/BrowserTabPane.java | 22 ++++++++++++++ .../java/app/lsgui/utils/BrowserCore.java | 8 ++--- 3 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java index be19f02..adc886e 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java @@ -42,7 +42,6 @@ import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.control.Separator; -import javafx.scene.control.TabPane; import javafx.scene.control.TabPane.TabClosingPolicy; import javafx.scene.control.TextField; import javafx.scene.control.ToolBar; @@ -65,22 +64,20 @@ public final class BrowserController { @FXML private BorderPane browserRootBorderPane; - @FXML - private TabPane browserTabPane; - - private ComboBox qualityComboBox; - private BrowserCore browserCore; + private BrowserTabPane browserTabPane = new BrowserTabPane(); + private ComboBox qualityComboBox = new ComboBox<>(); + private BrowserCore browserCore = BrowserCore.getInstance(); public BrowserController() { - // Empty Constructor + LOGGER.trace("BrowserController created."); } @FXML public void initialize() { this.setupToolBar(); this.setupProgressBar(); + this.browserRootBorderPane.setCenter(this.browserTabPane); this.browserTabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS); - this.browserCore = BrowserCore.getInstance(); this.browserCore.bindQualityProperty(this.qualityComboBox.getSelectionModel().selectedItemProperty()); this.browserCore.setTabPane(this.browserTabPane); Platform.runLater(this.browserCore::goToHome); @@ -110,9 +107,9 @@ private void setupProgressBar() { private void setupToolBar() { final Button homeButton = GlyphsDude.createIconButton(FontAwesomeIcon.HOME); - homeButton.setOnAction(event -> this.goToHome()); + homeButton.setOnAction(event -> this.browserCore.goToHome()); final Button refreshButton = GlyphsDude.createIconButton(FontAwesomeIcon.REFRESH); - refreshButton.setOnAction(event -> this.refreshBrowser()); + refreshButton.setOnAction(event -> this.browserCore.refresh()); final TextField searchTextField = new TextField(); searchTextField.textProperty().addListener((obs, oldValue, newValue) -> { if (!"".equals(newValue)) { @@ -129,7 +126,6 @@ private void setupToolBar() { } }); - this.qualityComboBox = new ComboBox<>(); this.qualityComboBox.getItems().add("Worst"); this.qualityComboBox.getItems().add("Best"); this.qualityComboBox.getSelectionModel().select(1); @@ -145,15 +141,4 @@ private void setupToolBar() { this.browserToolBar.getItems().add(new Separator(Orientation.VERTICAL)); this.browserToolBar.getItems().add(this.qualityComboBox); } - - private void goToHome() { - LOGGER.debug("Go to home directory"); - this.browserCore.goToHome(); - } - - private void refreshBrowser() { - LOGGER.debug("Refresh current page"); - this.browserCore.refresh(); - } - } diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java new file mode 100644 index 0000000..23ff86e --- /dev/null +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java @@ -0,0 +1,22 @@ +package app.lsgui.gui.twitchbrowser; + +import java.util.List; +import java.util.stream.Collectors; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.scene.control.TabPane; + +public class BrowserTabPane extends TabPane { + + public BrowserTabPane() { + super(); + } + + public ObservableList getBrowserTabs() { + final List browserTabs = getTabs().stream().map(tab -> (BrowserTab) tab) + .collect(Collectors.toList()); + return FXCollections.observableArrayList(browserTabs); + } + +} diff --git a/src/main/java/app/lsgui/utils/BrowserCore.java b/src/main/java/app/lsgui/utils/BrowserCore.java index 4ede933..1ce635c 100644 --- a/src/main/java/app/lsgui/utils/BrowserCore.java +++ b/src/main/java/app/lsgui/utils/BrowserCore.java @@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory; import app.lsgui.gui.twitchbrowser.BrowserTab; +import app.lsgui.gui.twitchbrowser.BrowserTabPane; import app.lsgui.model.twitch.ITwitchItem; import app.lsgui.model.twitch.TwitchChannel; import app.lsgui.model.twitch.TwitchChannels; @@ -44,7 +45,6 @@ import javafx.collections.transformation.FilteredList; import javafx.scene.Node; import javafx.scene.control.ScrollBar; -import javafx.scene.control.TabPane; /** * @@ -57,7 +57,7 @@ public final class BrowserCore { private static BrowserCore instance; private ObjectProperty qualityProperty = new SimpleObjectProperty<>(); - private TabPane tabPane; + private BrowserTabPane tabPane; private ObjectProperty> items = new SimpleObjectProperty<>( FXCollections.observableArrayList()); private ObjectProperty> activeItems = new SimpleObjectProperty<>( @@ -73,7 +73,7 @@ public static synchronized BrowserCore getInstance() { return instance; } - public void setTabPane(final TabPane tabPane) { + public void setTabPane(final BrowserTabPane tabPane) { this.tabPane = tabPane; } @@ -90,7 +90,7 @@ public void goToHome() { homeTab.getGridView().setItems(games.getGames()); this.tabPane.getTabs().add(homeTab); } else { - final GridView gridView = (GridView) this.tabPane.getTabs().get(0).getContent(); + final GridView gridView = this.tabPane.getBrowserTabs().get(0).getGridView(); gridView.setItems(games.getGames()); this.scrollToTop(); } From 2ce863f90dc3c63431b103c5e446c1bb6ddf70d6 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Thu, 29 Sep 2016 14:08:49 +0200 Subject: [PATCH 04/27] add filtering to tabs and select new tabs on creation --- .../gui/twitchbrowser/BrowserController.java | 36 ++++++++++++---- .../lsgui/gui/twitchbrowser/BrowserTab.java | 22 ++++++++-- .../gui/twitchbrowser/BrowserTabPane.java | 4 ++ .../java/app/lsgui/utils/BrowserCore.java | 43 +++++++++---------- 4 files changed, 71 insertions(+), 34 deletions(-) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java index adc886e..cf1e414 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java @@ -35,6 +35,7 @@ import javafx.beans.property.DoubleProperty; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleDoubleProperty; +import javafx.collections.ListChangeListener; import javafx.fxml.FXML; import javafx.geometry.Orientation; import javafx.scene.control.Button; @@ -42,6 +43,7 @@ import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.control.Separator; +import javafx.scene.control.Tab; import javafx.scene.control.TabPane.TabClosingPolicy; import javafx.scene.control.TextField; import javafx.scene.control.ToolBar; @@ -64,9 +66,10 @@ public final class BrowserController { @FXML private BorderPane browserRootBorderPane; - private BrowserTabPane browserTabPane = new BrowserTabPane(); - private ComboBox qualityComboBox = new ComboBox<>(); - private BrowserCore browserCore = BrowserCore.getInstance(); + private final BrowserTabPane browserTabPane = new BrowserTabPane(); + private final ComboBox qualityComboBox = new ComboBox<>(); + private final TextField searchTextField = new TextField(); + private final BrowserCore browserCore = BrowserCore.getInstance(); public BrowserController() { LOGGER.trace("BrowserController created."); @@ -76,13 +79,30 @@ public BrowserController() { public void initialize() { this.setupToolBar(); this.setupProgressBar(); - this.browserRootBorderPane.setCenter(this.browserTabPane); - this.browserTabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS); + this.setupTabPane(); this.browserCore.bindQualityProperty(this.qualityComboBox.getSelectionModel().selectedItemProperty()); this.browserCore.setTabPane(this.browserTabPane); Platform.runLater(this.browserCore::goToHome); } + private void setupTabPane() { + this.browserRootBorderPane.setCenter(this.browserTabPane); + this.browserTabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS); + this.browserTabPane.getTabs().addListener((ListChangeListener) change -> { + if (change.next() && change.wasAdded()) { + LOGGER.debug("Tab was added"); + this.browserTabPane.getSelectionModel().select(change.getAddedSubList().get(0)); + } + }); + this.browserTabPane.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { + final BrowserTab oldTab = (BrowserTab) oldValue; + if (oldTab != null) { + this.searchTextField.setText(""); + oldTab.resetActiveItems(); + } + }); + } + private void setupProgressBar() { final VBox vbox = new VBox(); final ProgressBar browserProgressBar = new ProgressBar(); @@ -110,8 +130,8 @@ private void setupToolBar() { homeButton.setOnAction(event -> this.browserCore.goToHome()); final Button refreshButton = GlyphsDude.createIconButton(FontAwesomeIcon.REFRESH); refreshButton.setOnAction(event -> this.browserCore.refresh()); - final TextField searchTextField = new TextField(); - searchTextField.textProperty().addListener((obs, oldValue, newValue) -> { + + this.searchTextField.textProperty().addListener((obs, oldValue, newValue) -> { if (!"".equals(newValue)) { this.browserCore.filter(newValue); } @@ -135,7 +155,7 @@ private void setupToolBar() { this.browserToolBar.getItems().add(refreshButton); this.browserToolBar.getItems().add(new Separator(Orientation.VERTICAL)); this.browserToolBar.getItems().add(searchLabel); - this.browserToolBar.getItems().add(searchTextField); + this.browserToolBar.getItems().add(this.searchTextField); this.browserToolBar.getItems().add(new Separator(Orientation.VERTICAL)); this.browserToolBar.getItems().add(favouriteGameComboBox); this.browserToolBar.getItems().add(new Separator(Orientation.VERTICAL)); diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java index 041a26e..60bc55f 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -3,15 +3,19 @@ import org.controlsfx.control.GridView; import app.lsgui.model.twitch.ITwitchItem; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; import javafx.scene.control.Tab; public class BrowserTab extends Tab { private String name; + private ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); + private ListProperty activeItems = new SimpleListProperty<>(FXCollections.observableArrayList()); public BrowserTab(final String name) { - this.name = name; - setText(this.name); + super(name); setContent(buildGridView()); } @@ -23,12 +27,24 @@ public GridView getGridView() { return (GridView) getContent(); } - private static GridView buildGridView() { + private GridView buildGridView() { final GridView gridView = new GridView<>(); gridView.setCellFactory(param -> new TwitchItemPane()); gridView.setCellWidth(TwitchItemPane.WIDTH); gridView.cellHeightProperty().bind(TwitchItemPane.HEIGHT_PROPERTY); + gridView.itemsProperty().bind(this.activeItemsProperty()); return gridView; } + public ListProperty itemsProperty() { + return this.items; + } + + public ListProperty activeItemsProperty() { + return this.activeItems; + } + + public void resetActiveItems() { + this.activeItemsProperty().set(this.itemsProperty().get()); + } } diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java index 23ff86e..251d89a 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java @@ -19,4 +19,8 @@ public ObservableList getBrowserTabs() { return FXCollections.observableArrayList(browserTabs); } + public BrowserTab getSelectedItem() { + return (BrowserTab) this.getSelectionModel().getSelectedItem(); + } + } diff --git a/src/main/java/app/lsgui/utils/BrowserCore.java b/src/main/java/app/lsgui/utils/BrowserCore.java index 1ce635c..acedfd1 100644 --- a/src/main/java/app/lsgui/utils/BrowserCore.java +++ b/src/main/java/app/lsgui/utils/BrowserCore.java @@ -25,7 +25,6 @@ import java.util.Locale; -import org.controlsfx.control.GridView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +39,6 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.scene.Node; @@ -58,10 +56,6 @@ public final class BrowserCore { private static BrowserCore instance; private ObjectProperty qualityProperty = new SimpleObjectProperty<>(); private BrowserTabPane tabPane; - private ObjectProperty> items = new SimpleObjectProperty<>( - FXCollections.observableArrayList()); - private ObjectProperty> activeItems = new SimpleObjectProperty<>( - FXCollections.observableArrayList()); private BrowserCore() { } @@ -81,41 +75,44 @@ public void bindQualityProperty(final ReadOnlyObjectProperty qualityProp this.qualityProperty.bind(qualityProperty); } + public void refresh() { + LOGGER.debug("Refresh: redirect to home page"); + if (this.tabPane.getSelectionModel().getSelectedIndex() == 0) { + this.goToHome(); + } else { + final BrowserTab currentTab = (BrowserTab) this.tabPane.getSelectionModel().getSelectedItem(); + this.openGame(currentTab.getName()); + } + } + public void goToHome() { LOGGER.debug("Go to home"); final TwitchGames games = TwitchAPIClient.getInstance().getGamesData(); + final BrowserTab homeTab; if (this.tabPane.getTabs().isEmpty()) { - final BrowserTab homeTab = new BrowserTab("Home"); + homeTab = new BrowserTab("Home"); homeTab.setClosable(false); - homeTab.getGridView().setItems(games.getGames()); this.tabPane.getTabs().add(homeTab); } else { - final GridView gridView = this.tabPane.getBrowserTabs().get(0).getGridView(); - gridView.setItems(games.getGames()); + homeTab = this.tabPane.getBrowserTabs().get(0); this.scrollToTop(); } - } - - public void refresh() { - LOGGER.debug("Refresh: redirect to home page"); - if (this.tabPane.getSelectionModel().getSelectedIndex() == 0) { - this.goToHome(); - } else { - final BrowserTab currentTab = (BrowserTab) this.tabPane.getSelectionModel().getSelectedItem(); - this.openGame(currentTab.getName()); - } + homeTab.itemsProperty().set(games.getGames()); + homeTab.activeItemsProperty().set(games.getGames()); } public void openGame(final String game) { LOGGER.debug("Open Data for Game '{}'", game); final TwitchChannels channels = TwitchAPIClient.getInstance().getGameData(game); final BrowserTab gameTab = this.addGameTab(game); - gameTab.getGridView().setItems(channels.getChannels()); + gameTab.itemsProperty().set(channels.getChannels()); + gameTab.activeItemsProperty().set(channels.getChannels()); this.scrollToTop(); } public void filter(final String filter) { - final ObservableList oldItems = this.items.get(); + final BrowserTab currentTab = this.tabPane.getSelectedItem(); + final ObservableList oldItems = currentTab.itemsProperty().get(); final FilteredList filteredItems = new FilteredList<>(oldItems); filteredItems.setPredicate(item -> { if (item.isTwitchGame()) { @@ -127,7 +124,7 @@ public void filter(final String filter) { } return true; }); - this.activeItems.set(filteredItems); + currentTab.activeItemsProperty().set(filteredItems); } private void scrollToTop() { From d001495242993d6ddc7bc66cf48c8b832889d89d Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Thu, 29 Sep 2016 14:15:03 +0200 Subject: [PATCH 05/27] remove unused method, make classes final --- .../java/app/lsgui/gui/twitchbrowser/BrowserTab.java | 9 ++------- .../java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java | 2 +- src/main/java/app/lsgui/utils/BrowserCore.java | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java index 60bc55f..c5c6a30 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -8,19 +8,14 @@ import javafx.collections.FXCollections; import javafx.scene.control.Tab; -public class BrowserTab extends Tab { +public final class BrowserTab extends Tab { - private String name; private ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); private ListProperty activeItems = new SimpleListProperty<>(FXCollections.observableArrayList()); public BrowserTab(final String name) { super(name); - setContent(buildGridView()); - } - - public String getName() { - return this.name; + setContent(this.buildGridView()); } public GridView getGridView() { diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java index 251d89a..34fd43d 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java @@ -7,7 +7,7 @@ import javafx.collections.ObservableList; import javafx.scene.control.TabPane; -public class BrowserTabPane extends TabPane { +public final class BrowserTabPane extends TabPane { public BrowserTabPane() { super(); diff --git a/src/main/java/app/lsgui/utils/BrowserCore.java b/src/main/java/app/lsgui/utils/BrowserCore.java index acedfd1..931c8b3 100644 --- a/src/main/java/app/lsgui/utils/BrowserCore.java +++ b/src/main/java/app/lsgui/utils/BrowserCore.java @@ -81,7 +81,7 @@ public void refresh() { this.goToHome(); } else { final BrowserTab currentTab = (BrowserTab) this.tabPane.getSelectionModel().getSelectedItem(); - this.openGame(currentTab.getName()); + this.openGame(currentTab.getText()); } } From 3ea6c579cb21564c2276ac6f61ed9b2a2e20ac21 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Thu, 29 Sep 2016 14:25:10 +0200 Subject: [PATCH 06/27] increase heap size for .exe --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 70891ee..5c2583b 100644 --- a/build.gradle +++ b/build.gradle @@ -93,8 +93,8 @@ launch4j { supportUrl = "https://github.com/westerwave/livestreamer_twitch_gui" copyright = "MIT LICENSE" language = "ENGLISH_US" - initialHeapSize = 128 - maxHeapSize = 384 + initialHeapSize = 64 + maxHeapSize = 512 } license { From 981b079bd40762ec398f97b53147f94d650729a1 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Fri, 30 Sep 2016 02:00:17 +0200 Subject: [PATCH 07/27] clear selection of favourite box --- src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java index cf1e414..ed32a17 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java @@ -143,6 +143,7 @@ private void setupToolBar() { favouriteGameComboBox.getSelectionModel().selectedItemProperty().addListener((obs, oldValue, newValue) -> { if (newValue != null) { this.browserCore.openGame(newValue); + Platform.runLater(() -> favouriteGameComboBox.setValue(null)); } }); From 3882a0fe725727d3e2706217ca090513b47ee7f0 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Fri, 30 Sep 2016 02:00:43 +0200 Subject: [PATCH 08/27] select existing game tab if the same game is requested --- .../java/app/lsgui/utils/BrowserCore.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/app/lsgui/utils/BrowserCore.java b/src/main/java/app/lsgui/utils/BrowserCore.java index 931c8b3..50afbf1 100644 --- a/src/main/java/app/lsgui/utils/BrowserCore.java +++ b/src/main/java/app/lsgui/utils/BrowserCore.java @@ -24,6 +24,7 @@ package app.lsgui.utils; import java.util.Locale; +import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,12 +105,36 @@ public void goToHome() { public void openGame(final String game) { LOGGER.debug("Open Data for Game '{}'", game); final TwitchChannels channels = TwitchAPIClient.getInstance().getGameData(game); - final BrowserTab gameTab = this.addGameTab(game); + final BrowserTab gameTab; + if (gameTabAlreadyExists(game)) { + final Optional optionalTab = this.tabPane.getBrowserTabs().stream() + .filter(tab -> tab.getText().equalsIgnoreCase(game)).findFirst(); + if (optionalTab.isPresent()) { + gameTab = optionalTab.get(); + } else { + throw new UnsupportedOperationException("Could not get already existing Game Tab"); + } + this.tabPane.getSelectionModel().select(gameTab); + } else { + gameTab = this.addGameTab(game); + } gameTab.itemsProperty().set(channels.getChannels()); gameTab.activeItemsProperty().set(channels.getChannels()); this.scrollToTop(); } + private boolean gameTabAlreadyExists(final String game) { + boolean alreadyExists = false; + final ObservableList browserTabs = this.tabPane.getBrowserTabs(); + for (final BrowserTab tab : browserTabs) { + if (tab.getText().equalsIgnoreCase(game)) { + alreadyExists = true; + break; + } + } + return alreadyExists; + } + public void filter(final String filter) { final BrowserTab currentTab = this.tabPane.getSelectedItem(); final ObservableList oldItems = currentTab.itemsProperty().get(); @@ -128,7 +153,7 @@ public void filter(final String filter) { } private void scrollToTop() { - final Node tabContent = this.tabPane.getTabs().get(0).getContent(); + final Node tabContent = this.tabPane.getSelectedItem().getContent(); final ScrollBar vBar = (ScrollBar) tabContent.lookup(".scroll-bar:vertical"); if (vBar != null) { vBar.setValue(0.0D); From 96fb959f6b11cc40cf22cfe86b6f90dc9f0a1f1f Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Sun, 2 Oct 2016 22:13:38 +0200 Subject: [PATCH 09/27] add display name for channels --- .../gui/main/infopanel/ChannelInfoPanel.java | 2 +- .../app/lsgui/gui/main/list/ChannelCell.java | 4 +- .../gui/twitchbrowser/TwitchItemPane.java | 95 ++++++++++--------- src/main/java/app/lsgui/model/IChannel.java | 2 + .../lsgui/model/generic/GenericChannel.java | 8 +- .../app/lsgui/model/twitch/TwitchChannel.java | 27 +++--- .../lsgui/model/twitch/TwitchChannels.java | 18 +--- .../java/app/lsgui/utils/TwitchUtils.java | 10 +- 8 files changed, 87 insertions(+), 79 deletions(-) diff --git a/src/main/java/app/lsgui/gui/main/infopanel/ChannelInfoPanel.java b/src/main/java/app/lsgui/gui/main/infopanel/ChannelInfoPanel.java index 0e09470..76d6100 100644 --- a/src/main/java/app/lsgui/gui/main/infopanel/ChannelInfoPanel.java +++ b/src/main/java/app/lsgui/gui/main/infopanel/ChannelInfoPanel.java @@ -175,7 +175,7 @@ private void bindToTwitchChannel(final TwitchChannel selectedChannel) { } private void bindToGenericChannel(final IChannel channel) { - this.channelDescription.textProperty().bind(channel.getName()); + this.channelDescription.textProperty().bind(channel.getDisplayName()); this.previewImageView.imageProperty().unbind(); this.channelUptime.textProperty().unbind(); this.channelUptime.setGraphic(null); diff --git a/src/main/java/app/lsgui/gui/main/list/ChannelCell.java b/src/main/java/app/lsgui/gui/main/list/ChannelCell.java index 311772a..58f8c7b 100644 --- a/src/main/java/app/lsgui/gui/main/list/ChannelCell.java +++ b/src/main/java/app/lsgui/gui/main/list/ChannelCell.java @@ -108,7 +108,7 @@ protected final void updateItem(final IChannel channel, final boolean isEmpty) { setGraphic(createReminderCheckBox(channel)); setContentDisplay(ContentDisplay.LEFT); setContextMenu(this.createContextMenu(channel)); - textProperty().bind(channel.getName()); + textProperty().bind(channel.getDisplayName()); setOnMouseClicked(mouseEvent -> { final int doubleClickAmount = 2; if (mouseEvent.getButton() == MouseButton.PRIMARY && mouseEvent.getClickCount() == doubleClickAmount) { @@ -136,7 +136,7 @@ private static CheckBox createReminderCheckBox(final IChannel channel) { private ContextMenu createContextMenu(final IChannel channel) { final ContextMenu contextMenu = new ContextMenu(); final MenuItem delete = new MenuItem(); - delete.textProperty().set("Delete " + channel.getName().get()); + delete.textProperty().set("Delete " + channel.getDisplayName().get()); delete.setOnAction(event -> { final IService service = (IService) this.getListView().getUserData(); LsGuiUtils.removeChannelFromService(channel, service); diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java index 4cf7967..d8728db 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java @@ -49,16 +49,14 @@ public final class TwitchItemPane extends GridCell { + public static final float WIDTH = 150; + public static final DoubleProperty HEIGHT_PROPERTY = new SimpleDoubleProperty(); + private static final int BOTTOM_OFFSET = 40; private static final double RATIO_GAME = 1.4D; private static final double RATIO_CHANNEL = 0.5625D; - public static final float WIDTH = 150; private static final double HEIGHT_GAME = WIDTH * RATIO_GAME; private static final double HEIGHT_CHANNEL = WIDTH * RATIO_CHANNEL; - public static final DoubleProperty HEIGHT_PROPERTY = new SimpleDoubleProperty(); - - private TwitchChannel channel; - private TwitchGame game; public TwitchItemPane() { // Empty Constructor @@ -72,54 +70,43 @@ protected void updateItem(final ITwitchItem item, final boolean empty) { setGraphic(null); } else { if (item instanceof TwitchGame) { - this.game = (TwitchGame) item; - setGraphic(this.createGameBorderPane()); + final TwitchGame game = (TwitchGame) item; + setGraphic(this.createGameBorderPane(game)); HEIGHT_PROPERTY.set(HEIGHT_GAME + BOTTOM_OFFSET); } else if (item instanceof TwitchChannel) { - this.channel = (TwitchChannel) item; - setGraphic(this.createChannelBorderPane()); + final TwitchChannel channel = (TwitchChannel) item; + setGraphic(this.createChannelBorderPane(channel)); HEIGHT_PROPERTY.set(HEIGHT_CHANNEL + BOTTOM_OFFSET); } } } - private BorderPane createGameBorderPane() { + private BorderPane createGameBorderPane(final TwitchGame game) { final BorderPane contentBorderPane = new BorderPane(); final ImageView gameImage = new ImageView(); - gameImage.imageProperty().bind(this.game.getBoxImage()); + gameImage.imageProperty().bind(game.getBoxImage()); gameImage.setFitWidth(WIDTH); gameImage.setFitHeight(HEIGHT_GAME); final Label nameLabel = new Label(); nameLabel.setTooltip(new Tooltip("Name of Category")); - nameLabel.textProperty().bind(this.game.getName()); + nameLabel.textProperty().bind(game.getName()); nameLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.GAMEPAD)); final Label viewersLabel = new Label(); viewersLabel.setTooltip(new Tooltip("Amount of Viewers")); - viewersLabel.textProperty().bind(this.game.getViewers()); + viewersLabel.textProperty().bind(game.getViewers()); viewersLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.GROUP)); final Label channelLabel = new Label(); channelLabel.setTooltip(new Tooltip("Amount of Channels")); - channelLabel.textProperty().bind(this.game.getChannelCount()); + channelLabel.textProperty().bind(game.getChannelCount()); channelLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.USER)); final VBox textBox = new VBox(nameLabel, viewersLabel, channelLabel); contentBorderPane.setCenter(gameImage); contentBorderPane.setBottom(textBox); contentBorderPane.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { if (event.getButton() == MouseButton.PRIMARY) { - BrowserCore.getInstance().openGame(this.game.getName().get()); + BrowserCore.getInstance().openGame(game.getName().get()); } else if (event.getButton() == MouseButton.SECONDARY) { - final ContextMenu contextMenu = new ContextMenu(); - if (!Settings.getInstance().getFavouriteGames().contains(this.game.getName().get())) { - final MenuItem addToFavourites = new MenuItem("Add to Favourites"); - addToFavourites.setOnAction( - eventStartContext -> Settings.getInstance().addFavouriteGame(this.game.getName().get())); - contextMenu.getItems().add(addToFavourites); - } else { - final MenuItem removeFromFavourites = new MenuItem("Remove from Favourites"); - removeFromFavourites.setOnAction( - eventStartContext -> Settings.getInstance().removeFavouriteGame(this.game.getName().get())); - contextMenu.getItems().add(removeFromFavourites); - } + final ContextMenu contextMenu = createContextMenu(game); this.contextMenuProperty().set(contextMenu); } event.consume(); @@ -127,49 +114,69 @@ private BorderPane createGameBorderPane() { return contentBorderPane; } - private BorderPane createChannelBorderPane() { + private BorderPane createChannelBorderPane(final TwitchChannel channel) { final BorderPane contentBorderPane = new BorderPane(); final ImageView channelImage = new ImageView(); - channelImage.imageProperty().bind(this.channel.getPreviewImageMedium()); + channelImage.imageProperty().bind(channel.getPreviewImageMedium()); channelImage.setFitWidth(WIDTH); channelImage.setFitHeight(HEIGHT_CHANNEL); final Label nameLabel = new Label(); nameLabel.setTooltip(new Tooltip("Name of the Channel")); - nameLabel.textProperty().bind(this.channel.getName()); + nameLabel.textProperty().bind(channel.getDisplayName()); nameLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.GAMEPAD)); final Label viewersLabel = new Label(); viewersLabel.setTooltip(new Tooltip("Amount of Viewers")); - viewersLabel.textProperty().bind(this.channel.getViewersString()); + viewersLabel.textProperty().bind(channel.getViewersString()); viewersLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.USER)); final Label uptimeLabel = new Label(); uptimeLabel.setTooltip(new Tooltip("Uptime of the Channel")); - uptimeLabel.textProperty().bind(this.channel.getUptimeString()); + uptimeLabel.textProperty().bind(channel.getUptimeString()); uptimeLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.CLOCK_ALT)); final VBox textBox = new VBox(nameLabel, viewersLabel, uptimeLabel); contentBorderPane.setCenter(channelImage); contentBorderPane.setBottom(textBox); final Tooltip titleTooltip = new Tooltip(); - titleTooltip.textProperty().bind(this.channel.getTitle()); + titleTooltip.textProperty().bind(channel.getTitle()); final Node node = contentBorderPane; Tooltip.install(node, titleTooltip); contentBorderPane.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { if (event.getButton() == MouseButton.PRIMARY) { - BrowserCore.getInstance().startStream(this.channel.getName().get()); + BrowserCore.getInstance().startStream(channel.getName().get()); } else if (event.getButton() == MouseButton.SECONDARY) { - final ContextMenu contextMenu = new ContextMenu(); - final MenuItem startStream = new MenuItem("Start Stream"); - startStream.setOnAction( - eventStartContext -> BrowserCore.getInstance().startStream(this.channel.getName().get())); - final MenuItem addToList = new MenuItem("Add Stream To Favourites"); - final IService twitchService = Settings.getInstance().getTwitchService(); - addToList.setOnAction( - eventAddContext -> LsGuiUtils.addChannelToService(this.channel.getName().get(), twitchService)); - contextMenu.getItems().add(startStream); - contextMenu.getItems().add(addToList); + final ContextMenu contextMenu = createContextMenu(channel); this.contextMenuProperty().set(contextMenu); } event.consume(); }); return contentBorderPane; } + + private static ContextMenu createContextMenu(final TwitchChannel channel) { + final ContextMenu contextMenu = new ContextMenu(); + final MenuItem startStream = new MenuItem("Start Stream"); + startStream.setOnAction(eventStartContext -> BrowserCore.getInstance().startStream(channel.getName().get())); + final MenuItem addToList = new MenuItem("Add Stream To Favourites"); + final IService twitchService = Settings.getInstance().getTwitchService(); + addToList + .setOnAction(eventAddContext -> LsGuiUtils.addChannelToService(channel.getName().get(), twitchService)); + contextMenu.getItems().add(startStream); + contextMenu.getItems().add(addToList); + return contextMenu; + } + + private static ContextMenu createContextMenu(final TwitchGame game) { + final ContextMenu contextMenu = new ContextMenu(); + if (!Settings.getInstance().getFavouriteGames().contains(game.getName().get())) { + final MenuItem addToFavourites = new MenuItem("Add to Favourites"); + addToFavourites + .setOnAction(eventStartContext -> Settings.getInstance().addFavouriteGame(game.getName().get())); + contextMenu.getItems().add(addToFavourites); + } else { + final MenuItem removeFromFavourites = new MenuItem("Remove from Favourites"); + removeFromFavourites + .setOnAction(eventStartContext -> Settings.getInstance().removeFavouriteGame(game.getName().get())); + contextMenu.getItems().add(removeFromFavourites); + } + return contextMenu; + } } diff --git a/src/main/java/app/lsgui/model/IChannel.java b/src/main/java/app/lsgui/model/IChannel.java index e885b81..a14c055 100644 --- a/src/main/java/app/lsgui/model/IChannel.java +++ b/src/main/java/app/lsgui/model/IChannel.java @@ -36,6 +36,8 @@ public interface IChannel { StringProperty getName(); + StringProperty getDisplayName(); + BooleanProperty isOnline(); BooleanProperty hasReminder(); diff --git a/src/main/java/app/lsgui/model/generic/GenericChannel.java b/src/main/java/app/lsgui/model/generic/GenericChannel.java index 448157b..d691f34 100644 --- a/src/main/java/app/lsgui/model/generic/GenericChannel.java +++ b/src/main/java/app/lsgui/model/generic/GenericChannel.java @@ -76,7 +76,13 @@ public void setReminder(final boolean hasReminder) { } public static Callback extractor() { - return (IChannel sm) -> new Observable[] { ((GenericChannel) sm).getName(), ((GenericChannel) sm).isOnline() }; + return (IChannel sm) -> new Observable[] { ((GenericChannel) sm).getName(), + ((GenericChannel) sm).getDisplayName(), ((GenericChannel) sm).isOnline() }; + } + + @Override + public StringProperty getDisplayName() { + return this.getName(); } } diff --git a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java index 9b001fb..8fe3b7e 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java @@ -53,10 +53,10 @@ */ public final class TwitchChannel implements IChannel, ITwitchItem { - private static final String CHANNEL_IS_OFFLINE = "Channel is offline"; private static final Logger LOGGER = LoggerFactory.getLogger(TwitchChannel.class); private StringProperty name = new SimpleStringProperty(); + private StringProperty displayName = new SimpleStringProperty(); private StringProperty logoURL = new SimpleStringProperty(); private StringProperty previewUrlLarge = new SimpleStringProperty(); private StringProperty previewUrlMedium = new SimpleStringProperty(); @@ -101,22 +101,13 @@ private void displayNotification(final boolean notify) { } private void setOffline(final String name) { - this.name.set(name); - this.logoURL.set(""); - this.previewUrlLarge.set(""); - this.game.set(""); - this.title.set(CHANNEL_IS_OFFLINE); - this.uptime.set(0); - this.viewers.set(0); - this.isOnline.set(false); - this.isPlaylist.set(false); - this.previewImageLarge.setValue(TwitchUtils.DEFAULT_LOGO); - this.availableQualities.clear(); + TwitchUtils.setOfflineData(this, name); } private void setOnline(final TwitchChannel data) { LOGGER.trace("update {} with data {}", data.getName(), data.isOnline()); this.name.setValue(data.getName().get()); + this.displayName.set(data.displayNameProperty().get()); this.logoURL.setValue(data.getLogoURL().get()); this.previewUrlLarge.setValue(data.getPreviewUrlLarge().get()); this.previewUrlMedium.setValue(data.getPreviewUrlMedium().get()); @@ -145,13 +136,18 @@ private void setOnline(final TwitchChannel data) { } public static Callback extractor() { - return (IChannel sm) -> new Observable[] { ((TwitchChannel) sm).getName(), ((TwitchChannel) sm).getGame(), + return (IChannel sm) -> new Observable[] { ((TwitchChannel) sm).getName(), + ((TwitchChannel) sm).displayNameProperty(), ((TwitchChannel) sm).getGame(), ((TwitchChannel) sm).isOnline(), ((TwitchChannel) sm).getTitle(), ((TwitchChannel) sm).getLogoURL(), ((TwitchChannel) sm).getPreviewImageLarge(), ((TwitchChannel) sm).getPreviewUrlLarge(), ((TwitchChannel) sm).getPreviewUrlMedium(), ((TwitchChannel) sm).getUptime(), ((TwitchChannel) sm).getViewers(), }; } + public StringProperty displayNameProperty() { + return this.displayName; + } + @Override public StringProperty getName() { return this.name; @@ -246,4 +242,9 @@ public boolean isTwitchGame() { public boolean isTwitchChannel() { return true; } + + @Override + public StringProperty getDisplayName() { + return this.displayName; + } } diff --git a/src/main/java/app/lsgui/model/twitch/TwitchChannels.java b/src/main/java/app/lsgui/model/twitch/TwitchChannels.java index ac71807..fd5bd8e 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchChannels.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchChannels.java @@ -32,8 +32,9 @@ import app.lsgui.remote.twitch.TwitchBrowserUpdateService; import app.lsgui.utils.TwitchUtils; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; -import javafx.collections.ObservableList; /** * @@ -44,18 +45,13 @@ public final class TwitchChannels { private static final Logger LOGGER = LoggerFactory.getLogger(TwitchChannels.class); private JsonObject jsonData; - private ObservableList channels; + private ListProperty channels = new SimpleListProperty<>(FXCollections.observableArrayList()); public TwitchChannels(final JsonObject jsonData) { this.jsonData = jsonData; - this.channels = FXCollections.observableArrayList(); this.addGames(); } - public TwitchChannels() { - this.channels = FXCollections.observableArrayList(); - } - private void addGames() { final JsonArray streams = this.jsonData.get("streams").getAsJsonArray(); LOGGER.debug("Update {} channels", streams.size()); @@ -72,13 +68,7 @@ private void addGames() { } } - public void updateData(final TwitchChannels updatedGames) { - LOGGER.debug("Update Twitch Channels Data"); - this.channels.clear(); - this.channels.addAll(updatedGames.getChannels()); - } - - public ObservableList getChannels() { + public ListProperty getChannels() { return this.channels; } diff --git a/src/main/java/app/lsgui/utils/TwitchUtils.java b/src/main/java/app/lsgui/utils/TwitchUtils.java index aa3bfe3..e712b6a 100644 --- a/src/main/java/app/lsgui/utils/TwitchUtils.java +++ b/src/main/java/app/lsgui/utils/TwitchUtils.java @@ -124,7 +124,7 @@ public static void openTwitchChat(final IChannel channel) { } public static void showOnlineNotification(final TwitchChannel channel) { - final String nameString = channel.getName().get(); + final String nameString = channel.getDisplayName().get(); final String gameString = channel.getGame().get(); final String titleString = channel.getTitle().get(); if (nameString != null && gameString != null && titleString != null) { @@ -135,7 +135,7 @@ public static void showOnlineNotification(final TwitchChannel channel) { } public static void showReminderNotification(final TwitchChannel twitchChannel) { - final String nameString = twitchChannel.getName().get(); + final String nameString = twitchChannel.getDisplayName().get(); final String gameString = twitchChannel.getGame().get(); final String titleString = twitchChannel.getTitle().get(); if (nameString != null && gameString != null && titleString != null) { @@ -179,7 +179,8 @@ private static void setData(final TwitchChannel channel, final JsonObject channe private static void setOnlineData(final TwitchChannel channel, final JsonObject channelObject) { final JsonObject channelJson = channelObject.get("channel").getAsJsonObject(); final JsonObject previewJson = channelObject.get("preview").getAsJsonObject(); - channel.getName().set(JsonUtils.getStringIfNotNull("display_name", channelJson)); + channel.getName().set(JsonUtils.getStringIfNotNull("name", channelJson)); + channel.displayNameProperty().set(JsonUtils.getStringIfNotNull("display_name", channelJson)); channel.getLogoURL().set(JsonUtils.getStringIfNotNull("logo", channelJson)); channel.isPartneredProperty().set(JsonUtils.getBooleanIfNotNull("partner", channelJson)); channel.getPreviewUrlLarge().set(JsonUtils.getStringIfNotNull("large", previewJson)); @@ -207,8 +208,9 @@ private static void setOnlineData(final TwitchChannel channel, final JsonObject } } - private static void setOfflineData(final TwitchChannel channel, final String name) { + public static void setOfflineData(final TwitchChannel channel, final String name) { channel.getName().set(name); + channel.displayNameProperty().set(name); channel.getLogoURL().set(""); channel.isPartneredProperty().set(false); channel.getPreviewUrlLarge().set(""); From 8619737d9a6003e7241c87c86ce8526060cbc8ec Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Sun, 2 Oct 2016 22:54:08 +0200 Subject: [PATCH 10/27] add variable for gridview --- .../app/lsgui/gui/twitchbrowser/BrowserTab.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java index c5c6a30..202e695 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -6,20 +6,23 @@ import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.scene.control.Tab; public final class BrowserTab extends Tab { private ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); private ListProperty activeItems = new SimpleListProperty<>(FXCollections.observableArrayList()); + private GridView contentGridView; public BrowserTab(final String name) { super(name); - setContent(this.buildGridView()); + this.contentGridView = this.buildGridView(); + setContent(this.contentGridView); } public GridView getGridView() { - return (GridView) getContent(); + return this.contentGridView; } private GridView buildGridView() { @@ -31,6 +34,13 @@ private GridView buildGridView() { return gridView; } + public void refresh() { + final ObservableList gridViewItems = this.getGridView().getItems(); + this.getGridView().itemsProperty().unbind(); + this.getGridView().setItems(FXCollections.observableArrayList()); + this.getGridView().setItems(gridViewItems); + } + public ListProperty itemsProperty() { return this.items; } From 6e533941e492e52e3ef15e417169b6e9ff5f9e71 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Wed, 5 Oct 2016 01:37:47 +0200 Subject: [PATCH 11/27] renamed all variables in settings to *property and made all to properties --- .../app/lsgui/gui/chat/ChatController.java | 9 +- .../java/app/lsgui/gui/chat/ChatWindow.java | 2 +- .../app/lsgui/gui/main/LsGuiController.java | 4 +- .../java/app/lsgui/gui/main/LsGuiWindow.java | 6 +- .../app/lsgui/gui/main/list/ChannelCell.java | 2 +- .../gui/main/toolbar/QualityComboBox.java | 2 +- .../gui/main/toolbar/ServiceComboBox.java | 6 +- .../gui/settings/SettingsController.java | 34 ++-- .../lsgui/gui/settings/SettingsWindow.java | 2 +- .../gui/twitchbrowser/BrowserController.java | 2 +- .../gui/twitchbrowser/BrowserWindow.java | 2 +- .../gui/twitchbrowser/TwitchItemPane.java | 2 +- .../app/lsgui/model/twitch/TwitchService.java | 2 +- .../app/lsgui/remote/GithubUpdateService.java | 2 +- .../lsgui/remote/twitch/TwitchAPIClient.java | 4 +- .../app/lsgui/utils/LivestreamerUtils.java | 8 +- src/main/java/app/lsgui/utils/LsGuiUtils.java | 6 +- .../java/app/lsgui/utils/PopOverUtil.java | 2 +- src/main/java/app/lsgui/utils/Settings.java | 165 ++++++++---------- 19 files changed, 123 insertions(+), 139 deletions(-) diff --git a/src/main/java/app/lsgui/gui/chat/ChatController.java b/src/main/java/app/lsgui/gui/chat/ChatController.java index 5c97cba..f3a8d69 100644 --- a/src/main/java/app/lsgui/gui/chat/ChatController.java +++ b/src/main/java/app/lsgui/gui/chat/ChatController.java @@ -87,7 +87,7 @@ public void initialize() { private void sendMessage(final String message) { if (!"".equals(message)) { - final String twitchUsername = Settings.getInstance().getTwitchUser(); + final String twitchUsername = Settings.getInstance().twitchUserProperty().get(); final int start = this.chatTextArea.getText().length(); final int end = start + twitchUsername.length() + 1; this.client.sendMessage(this.client.getChannel(), message); @@ -100,9 +100,10 @@ private void sendMessage(final String message) { public void connect(final String channel) { final String twitchIrc = "irc.chat.twitch.tv"; - if (!"".equals(Settings.getInstance().getTwitchUser()) && !"".equals(Settings.getInstance().getTwitchOAuth())) { - final String user = Settings.getInstance().getTwitchUser(); - final String oauth = Settings.getInstance().getTwitchOAuth(); + if (!"".equals(Settings.getInstance().twitchUserProperty().get()) + && !"".equals(Settings.getInstance().twitchOAuthProperty().get())) { + final String user = Settings.getInstance().twitchUserProperty().get(); + final String oauth = Settings.getInstance().twitchOAuthProperty().get(); this.client.setUserName(user); this.client.setChannel(channel); diff --git a/src/main/java/app/lsgui/gui/chat/ChatWindow.java b/src/main/java/app/lsgui/gui/chat/ChatWindow.java index 1ef3cec..3204bcb 100644 --- a/src/main/java/app/lsgui/gui/chat/ChatWindow.java +++ b/src/main/java/app/lsgui/gui/chat/ChatWindow.java @@ -76,7 +76,7 @@ private void setupStage(final Parent root) { this.getIcons().add(new Image(getClass().getResourceAsStream("/icon.jpg"))); final Scene scene = new Scene(root); scene.getStylesheets().add(ChatWindow.class - .getResource("/styles/" + Settings.getInstance().getWindowStyle() + ".css").toExternalForm()); + .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); this.setScene(scene); this.initModality(Modality.NONE); this.show(); diff --git a/src/main/java/app/lsgui/gui/main/LsGuiController.java b/src/main/java/app/lsgui/gui/main/LsGuiController.java index e4c4caa..0ea6d24 100644 --- a/src/main/java/app/lsgui/gui/main/LsGuiController.java +++ b/src/main/java/app/lsgui/gui/main/LsGuiController.java @@ -75,11 +75,11 @@ private void setupChannelList() { final QualityComboBox qualityComboBox = this.topToolBar.getQualityComboBox(); qualityComboBox.itemsProperty().bind(newValue.getAvailableQualities()); if (qualityComboBox.getItems().size() > 1) { - final String quality = Settings.getInstance().getQuality().get(); + final String quality = Settings.getInstance().qualityProperty().get(); if (qualityComboBox.getItems().contains(quality)) { qualityComboBox.getSelectionModel().select(quality); } else { - qualityComboBox.getSelectionModel().select("Best"); + qualityComboBox.getSelectionModel().select(Settings.DEFAULT_QUALITY); } } else { qualityComboBox.getSelectionModel().select(0); diff --git a/src/main/java/app/lsgui/gui/main/LsGuiWindow.java b/src/main/java/app/lsgui/gui/main/LsGuiWindow.java index a0b9dbc..8199fa3 100644 --- a/src/main/java/app/lsgui/gui/main/LsGuiWindow.java +++ b/src/main/java/app/lsgui/gui/main/LsGuiWindow.java @@ -106,7 +106,7 @@ private void setupStage(final Parent root, final Stage primaryStage) { primaryStage.setOnCloseRequest(event -> { Settings.getInstance().saveSettings(); Iterator> it = ((TwitchService) Settings.getInstance() - .getStreamServices().get(0)).getUpdateServices().entrySet().iterator(); + .servicesProperty().get(0)).getUpdateServices().entrySet().iterator(); while (it.hasNext()) { it.next(); it.remove(); @@ -117,7 +117,7 @@ private void setupStage(final Parent root, final Stage primaryStage) { primaryStage.setOnHiding(event -> { Settings.getInstance().saveSettings(); Iterator> it = ((TwitchService) Settings.getInstance() - .getStreamServices().get(0)).getUpdateServices().entrySet().iterator(); + .servicesProperty().get(0)).getUpdateServices().entrySet().iterator(); while (it.hasNext()) { it.next(); it.remove(); @@ -125,7 +125,7 @@ private void setupStage(final Parent root, final Stage primaryStage) { Platform.exit(); }); LsGuiWindow.getRootStage().getScene().getStylesheets().add(LsGuiWindow.class - .getResource("/styles/" + Settings.getInstance().getWindowStyle() + ".css").toExternalForm()); + .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); } public static final synchronized Stage getRootStage() { diff --git a/src/main/java/app/lsgui/gui/main/list/ChannelCell.java b/src/main/java/app/lsgui/gui/main/list/ChannelCell.java index 58f8c7b..9e3316e 100644 --- a/src/main/java/app/lsgui/gui/main/list/ChannelCell.java +++ b/src/main/java/app/lsgui/gui/main/list/ChannelCell.java @@ -182,7 +182,7 @@ private ContextMenu createContextMenu(final IChannel channel) { private void startLivestreamerStream(final IChannel channel) { final IService service = (IService) this.getListView().getUserData(); final String url = LsGuiUtils.buildUrl(service.getUrl().get(), channel.getName().get()); - final String quality = Settings.getInstance().getQuality().get(); + final String quality = Settings.getInstance().qualityProperty().get(); LivestreamerUtils.startLivestreamer(url, quality); LOGGER.info("Starting Stream for {}", channel.getName().get()); } diff --git a/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java b/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java index 5dbbfa4..762f285 100644 --- a/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java @@ -41,7 +41,7 @@ public void initialize() { getSelectionModel().selectedItemProperty().addListener((obs, oldValue, newValue) -> { if (!OFFLINEQUALITY.equals(newValue)) { LOGGER.debug("Set selected Quality to {}", newValue); - Settings.getInstance().getQuality().set(newValue); + Settings.getInstance().qualityProperty().set(newValue); } }); } diff --git a/src/main/java/app/lsgui/gui/main/toolbar/ServiceComboBox.java b/src/main/java/app/lsgui/gui/main/toolbar/ServiceComboBox.java index f0d2b15..a49cdb9 100644 --- a/src/main/java/app/lsgui/gui/main/toolbar/ServiceComboBox.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/ServiceComboBox.java @@ -41,10 +41,10 @@ public ServiceComboBox() { } public void initialize(final ServiceOperator serviceOperator) { - if (Settings.getInstance().getStreamServices().isEmpty()) { - Settings.getInstance().getStreamServices().add(new TwitchService("Twitch.tv", "http://twitch.tv/")); + if (Settings.getInstance().servicesProperty().isEmpty()) { + Settings.getInstance().servicesProperty().add(new TwitchService("Twitch.tv", "http://twitch.tv/")); } - itemsProperty().bind(Settings.getInstance().getStreamServices()); + itemsProperty().bind(Settings.getInstance().servicesProperty()); setCellFactory(listView -> new ServiceCell()); setConverter(new StringConverter() { @Override diff --git a/src/main/java/app/lsgui/gui/settings/SettingsController.java b/src/main/java/app/lsgui/gui/settings/SettingsController.java index 9ad0e34..0525dfd 100644 --- a/src/main/java/app/lsgui/gui/settings/SettingsController.java +++ b/src/main/java/app/lsgui/gui/settings/SettingsController.java @@ -90,19 +90,19 @@ public void initialize() { this.setupLoadChoiceBoxes(); final Settings settings = Settings.getInstance(); - this.sortCheckBox.setSelected(settings.getSortTwitch().get()); - this.oauthTextField.setText(settings.getTwitchOAuth()); - this.usernameTextField.setText(settings.getTwitchUser()); - this.gamesToLoadChoiceBox.getSelectionModel().select(Integer.valueOf(settings.getMaxGamesLoad())); - this.channelsToLoadChoiceBox.getSelectionModel().select(Integer.valueOf(settings.getMaxChannelsLoad())); + this.sortCheckBox.setSelected(settings.sortTwitchProperty().get()); + this.oauthTextField.setText(settings.twitchOAuthProperty().get()); + this.usernameTextField.setText(settings.twitchUserProperty().get()); + this.gamesToLoadChoiceBox.getSelectionModel().select(Integer.valueOf(settings.maxGamesProperty().get())); + this.channelsToLoadChoiceBox.getSelectionModel().select(Integer.valueOf(settings.maxChannelsProperty().get())); - this.sortCheckBox.setOnAction(event -> settings.getSortTwitch().setValue(this.sortCheckBox.isSelected())); + this.sortCheckBox.setOnAction(event -> settings.sortTwitchProperty().setValue(this.sortCheckBox.isSelected())); this.usernameTextField.textProperty() - .addListener((observable, oldValue, newValue) -> settings.setTwitchUser(newValue)); + .addListener((observable, oldValue, newValue) -> settings.twitchUserProperty().setValue(newValue)); this.oauthTextField.textProperty() - .addListener((observable, oldValue, newValue) -> settings.setTwitchOAuth(newValue)); + .addListener((observable, oldValue, newValue) -> settings.twitchOAuthProperty().setValue(newValue)); this.styleChoiceBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { - settings.setWindowStyle(newValue); + settings.windowStyleProperty().setValue(newValue); final String style = SettingsController.class.getResource("/styles/" + newValue + ".css").toExternalForm(); LsGuiUtils.clearStyleSheetsFromStage(LsGuiWindow.getRootStage()); @@ -113,10 +113,10 @@ public void initialize() { }); this.gamesToLoadChoiceBox.getSelectionModel().selectedItemProperty() - .addListener((observable, oldValue, newValue) -> settings.setMaxGamesLoad(newValue)); + .addListener((observable, oldValue, newValue) -> settings.maxGamesProperty().setValue(newValue)); this.channelsToLoadChoiceBox.getSelectionModel().selectedItemProperty() - .addListener((observable, oldValue, newValue) -> settings.setMaxChannelsLoad(newValue)); + .addListener((observable, oldValue, newValue) -> settings.maxChannelsProperty().setValue(newValue)); this.exeBrowseButton.setOnAction(event -> { final FileChooser exeFileChooser = new FileChooser(); @@ -124,13 +124,13 @@ public void initialize() { exeFileChooser.getExtensionFilters().add(new ExtensionFilter("EXE", "*.exe")); final File exeFile = exeFileChooser.showOpenDialog(LsGuiWindow.getRootStage()); if (exeFile != null) { - Settings.getInstance().getLivestreamerExePath().set(exeFile.getAbsolutePath()); + Settings.getInstance().livestreamerPathProperty().set(exeFile.getAbsolutePath()); } }); - final String updateLinkString = settings.getUpdateLink().get(); + final String updateLinkString = settings.updateLinkProperty().get(); if (updateLinkString != null && !"".equals(updateLinkString)) { this.updateLink.setText("New Version available!"); - this.updateLink.setOnAction(event -> LsGuiUtils.openURLInBrowser(settings.getUpdateLink().get())); + this.updateLink.setOnAction(event -> LsGuiUtils.openURLInBrowser(settings.updateLinkProperty().get())); } else { this.updateLink.setDisable(true); } @@ -148,8 +148,8 @@ private void setupLoadChoiceBoxes() { this.channelsToLoadChoiceBox.getItems().add(i); } final Settings settings = Settings.getInstance(); - final int maxGamesToLoad = settings.getMaxGamesLoad(); - final int maxChannelsToLoad = settings.getMaxChannelsLoad(); + final int maxGamesToLoad = settings.maxGamesProperty().get(); + final int maxChannelsToLoad = settings.maxChannelsProperty().get(); this.gamesToLoadChoiceBox.getSelectionModel().select(maxGamesToLoad); this.channelsToLoadChoiceBox.getSelectionModel().select(maxChannelsToLoad); } @@ -157,7 +157,7 @@ private void setupLoadChoiceBoxes() { private void setupStyleChoiceBox() { this.styleChoiceBox.getItems().add("DarkStyle"); this.styleChoiceBox.getItems().add("LightStyle"); - this.styleChoiceBox.getSelectionModel().select(Settings.getInstance().getWindowStyle()); + this.styleChoiceBox.getSelectionModel().select(Settings.getInstance().windowStyleProperty().get()); } private static void cancelSettingsAction() { diff --git a/src/main/java/app/lsgui/gui/settings/SettingsWindow.java b/src/main/java/app/lsgui/gui/settings/SettingsWindow.java index c181caa..785584f 100644 --- a/src/main/java/app/lsgui/gui/settings/SettingsWindow.java +++ b/src/main/java/app/lsgui/gui/settings/SettingsWindow.java @@ -77,7 +77,7 @@ private void setupStage(final Parent root, final Stage settingsStage, final Wind settingsStage.initModality(Modality.APPLICATION_MODAL); settingsStage.initOwner(parentWindow); SettingsWindow.getSettingsStage().getScene().getStylesheets().add(SettingsWindow.class - .getResource("/styles/" + Settings.getInstance().getWindowStyle() + ".css").toExternalForm()); + .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); settingsStage.setOnCloseRequest(event -> setSettingsStage(null)); } diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java index ed32a17..f1edd58 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserController.java @@ -138,7 +138,7 @@ private void setupToolBar() { }); final Label searchLabel = new Label("Filter"); final ComboBox favouriteGameComboBox = new ComboBox<>(); - final ListProperty favouriteGames = Settings.getInstance().getFavouriteGames(); + final ListProperty favouriteGames = Settings.getInstance().favouriteGamesProperty(); favouriteGameComboBox.itemsProperty().bind(favouriteGames); favouriteGameComboBox.getSelectionModel().selectedItemProperty().addListener((obs, oldValue, newValue) -> { if (newValue != null) { diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java index 06bb61c..a59af2f 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java @@ -79,6 +79,6 @@ private void setupStage(final Parent root, final Window parentWindow) { this.initModality(Modality.APPLICATION_MODAL); this.initOwner(parentWindow); this.getScene().getStylesheets().add(BrowserWindow.class - .getResource("/styles/" + Settings.getInstance().getWindowStyle() + ".css").toExternalForm()); + .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); } } diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java index d8728db..7f94793 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java @@ -166,7 +166,7 @@ private static ContextMenu createContextMenu(final TwitchChannel channel) { private static ContextMenu createContextMenu(final TwitchGame game) { final ContextMenu contextMenu = new ContextMenu(); - if (!Settings.getInstance().getFavouriteGames().contains(game.getName().get())) { + if (!Settings.getInstance().favouriteGamesProperty().contains(game.getName().get())) { final MenuItem addToFavourites = new MenuItem("Add to Favourites"); addToFavourites .setOnAction(eventStartContext -> Settings.getInstance().addFavouriteGame(game.getName().get())); diff --git a/src/main/java/app/lsgui/model/twitch/TwitchService.java b/src/main/java/app/lsgui/model/twitch/TwitchService.java index ccd6e21..45b5e2b 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchService.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchService.java @@ -72,7 +72,7 @@ public TwitchService(final String name, final String url) { this.url = new SimpleStringProperty(url); this.channelProperty = new SimpleObjectProperty<>(new SortedList<>(this.channelList)); this.sortChannels = new SimpleBooleanProperty(); - this.sortChannels.bind(Settings.getInstance().getSortTwitch()); + this.sortChannels.bind(Settings.getInstance().sortTwitchProperty()); this.sortChannels.addListener((observable, oldValue, newVale) -> this.changeComparator(newVale)); this.channelProperty.get().addListener((ListChangeListener) change -> { change.next(); diff --git a/src/main/java/app/lsgui/remote/GithubUpdateService.java b/src/main/java/app/lsgui/remote/GithubUpdateService.java index 18216b5..baaf760 100644 --- a/src/main/java/app/lsgui/remote/GithubUpdateService.java +++ b/src/main/java/app/lsgui/remote/GithubUpdateService.java @@ -119,7 +119,7 @@ private static void processJsonResponse(final String responseString) { if (!isPreRelease && isVersionNewer(tag)) { final ZonedDateTime publishedDate = convertPublishedDate(publishedAt); LsGuiUtils.showUpdateNotification(tag, publishedDate, event -> LsGuiUtils.openURLInBrowser(htmlUrl)); - Settings.getInstance().getUpdateLink().set(htmlUrl); + Settings.getInstance().updateLinkProperty().set(htmlUrl); } } } diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java b/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java index faaf867..95c2291 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java @@ -106,7 +106,7 @@ public TwitchChannel getStreamData(final String channelName, final boolean isBro public TwitchChannels getGameData(final String game) { LOGGER.debug("Load game Data"); final String gameName = game.replace(' ', '+'); - final int maxChannelsToLoad = Settings.getInstance().getMaxChannelsLoad(); + final int maxChannelsToLoad = Settings.getInstance().maxChannelsProperty().get(); final URI uri = convertToURI( TWITCH_BASE_URL + "streams/?game=" + gameName + "&offset=0&limit=" + maxChannelsToLoad); final String response = getAPIResponse(uri); @@ -116,7 +116,7 @@ public TwitchChannels getGameData(final String game) { public TwitchGames getGamesData() { LOGGER.debug("Load gamesData"); - final int maxGamesToLoad = Settings.getInstance().getMaxGamesLoad(); + final int maxGamesToLoad = Settings.getInstance().maxGamesProperty().get(); final URI uri = convertToURI(TWITCH_BASE_URL + "games/top?offset=0&limit=" + maxGamesToLoad); final String response = getAPIResponse(uri); final JsonObject jo = JSONPARSER.parse(response).getAsJsonObject(); diff --git a/src/main/java/app/lsgui/utils/LivestreamerUtils.java b/src/main/java/app/lsgui/utils/LivestreamerUtils.java index a168da4..b4090cc 100644 --- a/src/main/java/app/lsgui/utils/LivestreamerUtils.java +++ b/src/main/java/app/lsgui/utils/LivestreamerUtils.java @@ -119,7 +119,7 @@ private static List getRunCommand(final String url, final String quality } private static String getTwitchOAuth() { - final String oauth = Settings.getInstance().getTwitchOAuth(); + final String oauth = Settings.getInstance().twitchOAuthProperty().get(); String parameter; if (oauth.startsWith("oauth")) { final String oauthKey = oauth.split(":")[1]; @@ -139,7 +139,7 @@ public static void recordLivestreamer(final String url, final String quality, fi try { String path = "\"" + filePath.getAbsolutePath() + "\""; path = path.replace('\\', '/'); - Settings.getInstance().getRecordingPath().set(path); + Settings.getInstance().recordingPathProperty().set(path); ProcessBuilder pb = new ProcessBuilder(Arrays.asList(getLivestreamerExe(), "-o", path, url, quality)); pb.redirectOutput(Redirect.INHERIT); pb.redirectError(Redirect.INHERIT); @@ -154,14 +154,14 @@ public static void recordLivestreamer(final String url, final String quality, fi } private static String getLivestreamerExe() { - if ("".equals(Settings.getInstance().getLivestreamerExePath().get())) { + if ("".equals(Settings.getInstance().livestreamerPathProperty().get())) { if (!checkForLivestreamerOnPath()) { Platform.runLater(LivestreamerUtils::showLivestreamerPathWarning); return ""; } return LIVESTREAMERCMD; } else { - return Settings.getInstance().getLivestreamerExePath().get(); + return Settings.getInstance().livestreamerPathProperty().get(); } } diff --git a/src/main/java/app/lsgui/utils/LsGuiUtils.java b/src/main/java/app/lsgui/utils/LsGuiUtils.java index 8d04999..ceb8d69 100644 --- a/src/main/java/app/lsgui/utils/LsGuiUtils.java +++ b/src/main/java/app/lsgui/utils/LsGuiUtils.java @@ -104,7 +104,7 @@ public static void addService(final String serviceName, final String serviceUrl) LOGGER.debug("Add new Service {} with URL {}", serviceName, serviceUrl); if (!"".equals(serviceName) && !"".equals(serviceUrl)) { String correctedUrl = correctUrl(serviceUrl); - Settings.getInstance().getStreamServices().add(new GenericService(serviceName, correctedUrl)); + Settings.getInstance().servicesProperty().add(new GenericService(serviceName, correctedUrl)); } } @@ -121,7 +121,7 @@ public static String buildUrl(final String serviceUrl, final String channelUrl) public static void recordStream(final Stage stage, final IService service, final IChannel channel) { final String url = buildUrl(service.getUrl().get(), channel.getName().get()); - final String quality = Settings.getInstance().getQuality().get(); + final String quality = Settings.getInstance().qualityProperty().get(); final FileChooser recordFileChooser = new FileChooser(); recordFileChooser.setTitle("Choose Target file"); @@ -134,7 +134,7 @@ public static void recordStream(final Stage stage, final IService service, final public static void removeService(final IService service) { LOGGER.debug("Removing Service {}", service.getName().get()); - Settings.getInstance().getStreamServices().remove(service); + Settings.getInstance().servicesProperty().remove(service); } public static void showUpdateNotification(final String version, final ZonedDateTime date, diff --git a/src/main/java/app/lsgui/utils/PopOverUtil.java b/src/main/java/app/lsgui/utils/PopOverUtil.java index 47c5b2f..beea0b7 100644 --- a/src/main/java/app/lsgui/utils/PopOverUtil.java +++ b/src/main/java/app/lsgui/utils/PopOverUtil.java @@ -140,7 +140,7 @@ public static PopOver createImportPopOver(final Node root, final TwitchService s private static PopOver createBasePopOver(final String title) { final PopOver popOver = new PopOver(); popOver.getRoot().getStylesheets().add(PopOverUtil.class - .getResource("/styles/" + Settings.getInstance().getWindowStyle() + ".css").toExternalForm()); + .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); popOver.setArrowLocation(ArrowLocation.TOP_LEFT); popOver.setCornerRadius(CORDER_RADIUS); popOver.setTitle(title); diff --git a/src/main/java/app/lsgui/utils/Settings.java b/src/main/java/app/lsgui/utils/Settings.java index e05e993..b45780d 100644 --- a/src/main/java/app/lsgui/utils/Settings.java +++ b/src/main/java/app/lsgui/utils/Settings.java @@ -45,8 +45,10 @@ import app.lsgui.model.generic.GenericService; import app.lsgui.model.twitch.TwitchService; import javafx.beans.property.BooleanProperty; +import javafx.beans.property.IntegerProperty; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -80,20 +82,22 @@ public final class Settings { private static final String FAVOURITE_GAMES = "favouriteGames"; private static final String DEFAULT_TOKEN = "vkwhrtlhzcz3o91nu386ub62p5j6sk"; + public static final String DEFAULT_QUALITY = "Source"; + private static Settings instance; private ListProperty services = new SimpleListProperty<>(); private ListProperty favouriteGames = new SimpleListProperty<>(); private BooleanProperty sortTwitch = new SimpleBooleanProperty(); - private boolean minimizeToTray = true; - private String windowStyle = "LightStyle"; - private String currentService = "twitch.tv"; - private String twitchUser = ""; - private String twitchOAuth = ""; - private int maxGamesLoad; - private int maxChannelsLoad; + private BooleanProperty minimizeToTray = new SimpleBooleanProperty(); + private StringProperty windowStyle = new SimpleStringProperty("LightStyle"); + private StringProperty currentService = new SimpleStringProperty("twitch.tv"); + private StringProperty twitchUser = new SimpleStringProperty(); + private StringProperty twitchOAuth = new SimpleStringProperty(); + private IntegerProperty maxGamesLoad = new SimpleIntegerProperty(); + private IntegerProperty maxChannelsLoad = new SimpleIntegerProperty(); private StringProperty liveStreamerExePath = new SimpleStringProperty(); - private StringProperty quality = new SimpleStringProperty("Best"); + private StringProperty quality = new SimpleStringProperty(DEFAULT_QUALITY); private StringProperty recordingPath = new SimpleStringProperty(); private StringProperty updateLink = new SimpleStringProperty(); @@ -139,16 +143,18 @@ private void loadSettingsFromFile(final File file) { private void loadSettings(final JsonArray jArray) { final JsonObject settings = jArray.get(0).getAsJsonObject(); - this.sortTwitch.setValue(JsonUtils.getBooleanSafe(settings.get(TWITCH_SORT), false)); - this.minimizeToTray = JsonUtils.getBooleanSafe(settings.get(MINIMIZE_TO_TRAY_STRING), false); - this.twitchUser = JsonUtils.getStringSafe(settings.get(TWITCH_USER_STRING), ""); - this.twitchOAuth = JsonUtils.getStringSafe(settings.get(TWITCH_OAUTH_STRING), DEFAULT_TOKEN); - this.windowStyle = JsonUtils.getStringSafe(settings.get(WINDOWSTYLE_STRING), "LightStyle"); - this.liveStreamerExePath.set(JsonUtils.getStringSafe(settings.get(EXEPATH_STRING), "")); - this.maxChannelsLoad = JsonUtils.getIntSafe(settings.get(CHANNELS_LOAD), DEFAULT_CHANNELS_TO_LOAD); - this.maxGamesLoad = JsonUtils.getIntSafe(settings.get(GAMES_LOAD), DEFAULT_GAMES_TO_LOAD); - this.quality.set(JsonUtils.getStringSafe(settings.get(QUALITY_STRING), "Best")); - this.recordingPath.set(JsonUtils.getStringSafe(settings.get(PATH), System.getProperty("user.home"))); + this.sortTwitchProperty().setValue(JsonUtils.getBooleanSafe(settings.get(TWITCH_SORT), false)); + this.minimizeToTrayProperty().setValue(JsonUtils.getBooleanSafe(settings.get(MINIMIZE_TO_TRAY_STRING), false)); + this.twitchUserProperty().setValue(JsonUtils.getStringSafe(settings.get(TWITCH_USER_STRING), "")); + this.twitchOAuthProperty().setValue(JsonUtils.getStringSafe(settings.get(TWITCH_OAUTH_STRING), DEFAULT_TOKEN)); + this.windowStyleProperty().setValue(JsonUtils.getStringSafe(settings.get(WINDOWSTYLE_STRING), "LightStyle")); + this.livestreamerPathProperty().setValue(JsonUtils.getStringSafe(settings.get(EXEPATH_STRING), "")); + this.maxChannelsProperty() + .setValue(JsonUtils.getIntSafe(settings.get(CHANNELS_LOAD), DEFAULT_CHANNELS_TO_LOAD)); + this.maxGamesProperty().setValue(JsonUtils.getIntSafe(settings.get(GAMES_LOAD), DEFAULT_GAMES_TO_LOAD)); + this.qualityProperty().setValue(JsonUtils.getStringSafe(settings.get(QUALITY_STRING), DEFAULT_QUALITY)); + this.recordingPathProperty() + .setValue(JsonUtils.getStringSafe(settings.get(PATH), System.getProperty("user.home"))); final JsonArray favouritesArray = JsonUtils.getJsonArraySafe(FAVOURITE_GAMES, settings); for (int i = 0; i < favouritesArray.size(); i++) { final String favourite = favouritesArray.get(i).getAsString(); @@ -157,7 +163,7 @@ private void loadSettings(final JsonArray jArray) { } private void loadServices(final JsonArray jArray) { - this.services.set(FXCollections.observableArrayList()); + this.services.setValue(FXCollections.observableArrayList()); final JsonArray servicesArray = jArray.get(1).getAsJsonArray(); for (int i = 0; i < servicesArray.size(); i++) { final JsonObject serviceJson = servicesArray.get(i).getAsJsonObject(); @@ -187,16 +193,16 @@ private void createSettingsJson(final File file) { jsonWriter.setIndent(" "); jsonWriter.beginArray(); jsonWriter.beginObject(); - jsonWriter.name(TWITCH_USER_STRING).value(this.twitchUser); - jsonWriter.name(TWITCH_OAUTH_STRING).value(this.twitchOAuth); - jsonWriter.name(TWITCH_SORT).value(this.sortTwitch.get()); - jsonWriter.name(QUALITY_STRING).value(this.getQuality().get()); - jsonWriter.name(PATH).value(this.getRecordingPath().get()); - jsonWriter.name(CHANNELS_LOAD).value(this.maxChannelsLoad); - jsonWriter.name(GAMES_LOAD).value(this.maxGamesLoad); - jsonWriter.name(MINIMIZE_TO_TRAY_STRING).value(this.minimizeToTray); - jsonWriter.name(WINDOWSTYLE_STRING).value(this.windowStyle); - jsonWriter.name(EXEPATH_STRING).value(this.getLivestreamerExePath().get()); + jsonWriter.name(TWITCH_USER_STRING).value(this.twitchUserProperty().get()); + jsonWriter.name(TWITCH_OAUTH_STRING).value(this.twitchOAuthProperty().get()); + jsonWriter.name(TWITCH_SORT).value(this.sortTwitchProperty().get()); + jsonWriter.name(QUALITY_STRING).value(this.qualityProperty().get()); + jsonWriter.name(PATH).value(this.recordingPathProperty().get()); + jsonWriter.name(CHANNELS_LOAD).value(this.maxChannelsProperty().get()); + jsonWriter.name(GAMES_LOAD).value(this.maxGamesProperty().get()); + jsonWriter.name(MINIMIZE_TO_TRAY_STRING).value(this.minimizeToTrayProperty().get()); + jsonWriter.name(WINDOWSTYLE_STRING).value(this.windowStyleProperty().get()); + jsonWriter.name(EXEPATH_STRING).value(this.livestreamerPathProperty().get()); this.writeFavouriteGames(jsonWriter); jsonWriter.endObject(); this.writeServices(jsonWriter); @@ -239,109 +245,86 @@ private void writeFavouriteGames(final JsonWriter writer) throws IOException { writer.endArray(); } - public ListProperty getStreamServices() { - return this.services; - } - - public BooleanProperty getSortTwitch() { - return this.sortTwitch; + public IService getTwitchService() { + final List servicesAsList = this.servicesProperty().get(); + final Optional serviceOptional = servicesAsList.stream().filter(TwitchUtils::isTwitchService) + .findFirst(); + if (serviceOptional.isPresent()) { + return serviceOptional.get(); + } + return null; } - public String getCurrentStreamService() { - return this.currentService; + public void addFavouriteGame(final String game) { + final ObservableList favourites = FXCollections.observableArrayList(this.favouriteGames); + favourites.add(game); + this.favouriteGamesProperty().set(favourites); } - public String getTwitchUser() { - return this.twitchUser; + public void removeFavouriteGame(final String game) { + final ObservableList favourites = FXCollections.observableArrayList(this.favouriteGames); + favourites.remove(game); + this.favouriteGamesProperty().set(favourites); } - public void setTwitchUser(final String twitchUser) { - this.twitchUser = twitchUser; + public long getTimeout() { + return TIMEOUT; } - public String getTwitchOAuth() { - return this.twitchOAuth; + public ListProperty servicesProperty() { + return this.services; } - public void setTwitchOAuth(final String twitchOAuth) { - this.twitchOAuth = twitchOAuth; + public BooleanProperty sortTwitchProperty() { + return this.sortTwitch; } - public int getMaxGamesLoad() { - return this.maxGamesLoad; + public StringProperty currentServiceProperty() { + return this.currentService; } - public void setMaxGamesLoad(final int maxGamesLoad) { - this.maxGamesLoad = maxGamesLoad; + public StringProperty twitchUserProperty() { + return this.twitchUser; } - public int getMaxChannelsLoad() { - return this.maxChannelsLoad; + public StringProperty twitchOAuthProperty() { + return this.twitchOAuth; } - public void setMaxChannelsLoad(final int maxChannelsLoad) { - this.maxChannelsLoad = maxChannelsLoad; + public IntegerProperty maxGamesProperty() { + return this.maxGamesLoad; } - public long getTimeout() { - return TIMEOUT; + public IntegerProperty maxChannelsProperty() { + return this.maxChannelsLoad; } - public boolean isMinimizeToTray() { + public BooleanProperty minimizeToTrayProperty() { return this.minimizeToTray; } - public void setMinimizeToTray(final boolean minimizeToTray) { - this.minimizeToTray = minimizeToTray; - } - - public String getWindowStyle() { + public StringProperty windowStyleProperty() { return this.windowStyle; } - public void setWindowStyle(final String windowStyle) { - this.windowStyle = windowStyle; - } - - public StringProperty getLivestreamerExePath() { + public StringProperty livestreamerPathProperty() { return this.liveStreamerExePath; } - public StringProperty getQuality() { + public StringProperty qualityProperty() { return this.quality; } - public StringProperty getRecordingPath() { + public StringProperty recordingPathProperty() { return this.recordingPath; } - public IService getTwitchService() { - final List servicesAsList = this.getStreamServices().get(); - final Optional serviceOptional = servicesAsList.stream().filter(TwitchUtils::isTwitchService) - .findFirst(); - if (serviceOptional.isPresent()) { - return serviceOptional.get(); - } - return null; - } - - public StringProperty getUpdateLink() { + public StringProperty updateLinkProperty() { return this.updateLink; } - public ListProperty getFavouriteGames() { + public ListProperty favouriteGamesProperty() { return this.favouriteGames; } - public void addFavouriteGame(final String game) { - final ObservableList favourites = FXCollections.observableArrayList(this.favouriteGames); - favourites.add(game); - this.getFavouriteGames().set(favourites); - } - - public void removeFavouriteGame(final String game) { - final ObservableList favourites = FXCollections.observableArrayList(this.favouriteGames); - favourites.remove(game); - this.getFavouriteGames().set(favourites); - } } From c8972133c8499c29f1510a18347fd2a70d11bce8 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Wed, 5 Oct 2016 01:42:30 +0200 Subject: [PATCH 12/27] add method in settings class for gettings the currently selected stylesheet --- src/main/java/app/lsgui/gui/chat/ChatWindow.java | 3 +-- src/main/java/app/lsgui/gui/main/LsGuiWindow.java | 3 +-- src/main/java/app/lsgui/gui/settings/SettingsWindow.java | 4 ++-- src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java | 3 +-- src/main/java/app/lsgui/utils/PopOverUtil.java | 3 +-- src/main/java/app/lsgui/utils/Settings.java | 5 +++++ 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/app/lsgui/gui/chat/ChatWindow.java b/src/main/java/app/lsgui/gui/chat/ChatWindow.java index 3204bcb..907a4bd 100644 --- a/src/main/java/app/lsgui/gui/chat/ChatWindow.java +++ b/src/main/java/app/lsgui/gui/chat/ChatWindow.java @@ -75,8 +75,7 @@ private void setupStage(final Parent root) { this.setTitle(this.channel + " - Livestreamer GUI Chat v" + LsGuiUtils.readVersionProperty()); this.getIcons().add(new Image(getClass().getResourceAsStream("/icon.jpg"))); final Scene scene = new Scene(root); - scene.getStylesheets().add(ChatWindow.class - .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); + scene.getStylesheets().add(Settings.getInstance().getCurrentStyleSheet()); this.setScene(scene); this.initModality(Modality.NONE); this.show(); diff --git a/src/main/java/app/lsgui/gui/main/LsGuiWindow.java b/src/main/java/app/lsgui/gui/main/LsGuiWindow.java index 8199fa3..658b2a1 100644 --- a/src/main/java/app/lsgui/gui/main/LsGuiWindow.java +++ b/src/main/java/app/lsgui/gui/main/LsGuiWindow.java @@ -124,8 +124,7 @@ private void setupStage(final Parent root, final Stage primaryStage) { } Platform.exit(); }); - LsGuiWindow.getRootStage().getScene().getStylesheets().add(LsGuiWindow.class - .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); + LsGuiWindow.getRootStage().getScene().getStylesheets().add(Settings.getInstance().getCurrentStyleSheet()); } public static final synchronized Stage getRootStage() { diff --git a/src/main/java/app/lsgui/gui/settings/SettingsWindow.java b/src/main/java/app/lsgui/gui/settings/SettingsWindow.java index 785584f..49d7620 100644 --- a/src/main/java/app/lsgui/gui/settings/SettingsWindow.java +++ b/src/main/java/app/lsgui/gui/settings/SettingsWindow.java @@ -76,8 +76,8 @@ private void setupStage(final Parent root, final Stage settingsStage, final Wind settingsStage.setScene(scene); settingsStage.initModality(Modality.APPLICATION_MODAL); settingsStage.initOwner(parentWindow); - SettingsWindow.getSettingsStage().getScene().getStylesheets().add(SettingsWindow.class - .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); + SettingsWindow.getSettingsStage().getScene().getStylesheets() + .add(Settings.getInstance().getCurrentStyleSheet()); settingsStage.setOnCloseRequest(event -> setSettingsStage(null)); } diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java index a59af2f..9efad15 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserWindow.java @@ -78,7 +78,6 @@ private void setupStage(final Parent root, final Window parentWindow) { this.setScene(scene); this.initModality(Modality.APPLICATION_MODAL); this.initOwner(parentWindow); - this.getScene().getStylesheets().add(BrowserWindow.class - .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); + this.getScene().getStylesheets().add(Settings.getInstance().getCurrentStyleSheet()); } } diff --git a/src/main/java/app/lsgui/utils/PopOverUtil.java b/src/main/java/app/lsgui/utils/PopOverUtil.java index beea0b7..4d5f88b 100644 --- a/src/main/java/app/lsgui/utils/PopOverUtil.java +++ b/src/main/java/app/lsgui/utils/PopOverUtil.java @@ -139,8 +139,7 @@ public static PopOver createImportPopOver(final Node root, final TwitchService s private static PopOver createBasePopOver(final String title) { final PopOver popOver = new PopOver(); - popOver.getRoot().getStylesheets().add(PopOverUtil.class - .getResource("/styles/" + Settings.getInstance().windowStyleProperty() + ".css").toExternalForm()); + popOver.getRoot().getStylesheets().add(Settings.getInstance().getCurrentStyleSheet()); popOver.setArrowLocation(ArrowLocation.TOP_LEFT); popOver.setCornerRadius(CORDER_RADIUS); popOver.setTitle(title); diff --git a/src/main/java/app/lsgui/utils/Settings.java b/src/main/java/app/lsgui/utils/Settings.java index b45780d..71e0676 100644 --- a/src/main/java/app/lsgui/utils/Settings.java +++ b/src/main/java/app/lsgui/utils/Settings.java @@ -267,6 +267,11 @@ public void removeFavouriteGame(final String game) { this.favouriteGamesProperty().set(favourites); } + public String getCurrentStyleSheet() { + return Settings.class.getResource("/styles/" + Settings.getInstance().windowStyleProperty().get() + ".css") + .toExternalForm(); + } + public long getTimeout() { return TIMEOUT; } From 5072b759e7c3df0480379ea1fe271628e61399f2 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Wed, 5 Oct 2016 02:24:05 +0200 Subject: [PATCH 13/27] small fixes and improvements --- src/main/java/app/lsgui/model/twitch/TwitchChannel.java | 7 ++++--- .../lsgui/remote/twitch/TwitchBrowserUpdateService.java | 2 +- .../lsgui/remote/twitch/TwitchChannelUpdateService.java | 2 +- src/main/java/app/lsgui/utils/TwitchUtils.java | 9 --------- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java index 8fe3b7e..fd1d03c 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java @@ -101,13 +101,14 @@ private void displayNotification(final boolean notify) { } private void setOffline(final String name) { + LOGGER.debug("set {} offline", name); TwitchUtils.setOfflineData(this, name); } private void setOnline(final TwitchChannel data) { LOGGER.trace("update {} with data {}", data.getName(), data.isOnline()); this.name.setValue(data.getName().get()); - this.displayName.set(data.displayNameProperty().get()); + this.displayName.setValue(data.displayNameProperty().get()); this.logoURL.setValue(data.getLogoURL().get()); this.previewUrlLarge.setValue(data.getPreviewUrlLarge().get()); this.previewUrlMedium.setValue(data.getPreviewUrlMedium().get()); @@ -118,10 +119,10 @@ private void setOnline(final TwitchChannel data) { this.viewers.setValue(data.getViewers().get()); this.viewersString.setValue(Integer.toString(this.getViewers().get())); if (data.isOnline().get() && !this.isOnline.get()) { - this.isOnline.set(true); + this.isOnline.setValue(true); this.cameOnline = true; } else if (!data.isOnline().get()) { - this.isOnline.set(false); + this.isOnline.setValue(false); } this.isPlaylist.setValue(data.getIsPlaylist().get()); this.previewImageLarge.setValue(data.getPreviewImageLarge().get()); diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java b/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java index 175dde2..60ff66f 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java @@ -54,7 +54,7 @@ public void setUpChannel() { this.channel.updateData(updatedChannel, false); } } - TwitchUtils.removeTwitchChannelFromList(ACTIVE_LIST, this.channel); + ACTIVE_LIST.remove(this.channel); }); setOnFailed(event -> LOGGER.warn("UPDATE SERVICE FAILED")); } diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java b/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java index 24aa1af..ce3bb5e 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java @@ -64,7 +64,7 @@ public void setUpConstant() { this.channel.updateData(updatedModel, true); } } - TwitchUtils.removeTwitchChannelFromList(ACTIVE_LIST, this.channel); + ACTIVE_LIST.remove(this.channel); }); setOnFailed(event -> LOGGER.warn("UPDATE SERVICE FAILED {}", event.getEventType())); } diff --git a/src/main/java/app/lsgui/utils/TwitchUtils.java b/src/main/java/app/lsgui/utils/TwitchUtils.java index e712b6a..f02e1b8 100644 --- a/src/main/java/app/lsgui/utils/TwitchUtils.java +++ b/src/main/java/app/lsgui/utils/TwitchUtils.java @@ -240,15 +240,6 @@ public static String buildUptimeString(final Long uptime) { return String.format("%02d:%02d:%02d Uptime", hours, minutes, seconds); } - public static void removeTwitchChannelFromList(final ListProperty activeList, - final TwitchChannel channel) { - synchronized (activeList) { - ObservableList activeChannelServices = FXCollections.observableArrayList(activeList.get()); - activeChannelServices.remove(channel); - activeList.set(activeChannelServices); - } - } - public static void addChannelToList(final ListProperty activeList, final TwitchChannel channel) { synchronized (activeList) { final ObservableList activeChannelServices = FXCollections From be9fd0a68c5caf6addfbf5d0fdcd288832c50c39 Mon Sep 17 00:00:00 2001 From: westerwave Date: Mon, 10 Oct 2016 16:41:30 +0200 Subject: [PATCH 14/27] convert browsertab from gridview to scrollpane with tilepane --- .../lsgui/gui/twitchbrowser/BrowserTab.java | 55 ++++++++----- .../gui/twitchbrowser/TwitchItemPane.java | 79 +++++++------------ 2 files changed, 66 insertions(+), 68 deletions(-) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java index 202e695..e4226b5 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -1,44 +1,61 @@ package app.lsgui.gui.twitchbrowser; -import org.controlsfx.control.GridView; - import app.lsgui.model.twitch.ITwitchItem; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.scene.Node; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.control.Tab; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.TilePane; public final class BrowserTab extends Tab { private ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); private ListProperty activeItems = new SimpleListProperty<>(FXCollections.observableArrayList()); - private GridView contentGridView; + private ScrollPane content; public BrowserTab(final String name) { super(name); - this.contentGridView = this.buildGridView(); - setContent(this.contentGridView); + this.content = this.buildContent(); + setContent(this.content); + } + + public ScrollPane getCustomContent() { + return this.content; } - public GridView getGridView() { - return this.contentGridView; + private ScrollPane buildContent() { + final ScrollPane scrollPane = new ScrollPane(); + scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER); + scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS); + scrollPane.setFitToHeight(true); + scrollPane.setFitToWidth(true); + final TilePane pane = new TilePane(); + pane.setPrefColumns(5); + pane.setVgap(10.0D); + pane.setHgap(15.0D); + this.activeItemsProperty().addListener((ListChangeListener.Change c) -> { + pane.getChildren().setAll(this.convertToNodeList(this.activeItemsProperty().get())); + }); + scrollPane.setContent(pane); + return scrollPane; } - private GridView buildGridView() { - final GridView gridView = new GridView<>(); - gridView.setCellFactory(param -> new TwitchItemPane()); - gridView.setCellWidth(TwitchItemPane.WIDTH); - gridView.cellHeightProperty().bind(TwitchItemPane.HEIGHT_PROPERTY); - gridView.itemsProperty().bind(this.activeItemsProperty()); - return gridView; + private ObservableList convertToNodeList(final ObservableList items) { + final ObservableList list = FXCollections.observableArrayList(); + items.stream().forEach((item) -> { + list.add(this.convertToBorderPane(item)); + }); + return list; } - public void refresh() { - final ObservableList gridViewItems = this.getGridView().getItems(); - this.getGridView().itemsProperty().unbind(); - this.getGridView().setItems(FXCollections.observableArrayList()); - this.getGridView().setItems(gridViewItems); + private BorderPane convertToBorderPane(final ITwitchItem item) { + return new TwitchItemPane(item); } public ListProperty itemsProperty() { diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java index 7f94793..97595a7 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java @@ -23,8 +23,6 @@ */ package app.lsgui.gui.twitchbrowser; -import org.controlsfx.control.GridCell; - import app.lsgui.model.IService; import app.lsgui.model.twitch.ITwitchItem; import app.lsgui.model.twitch.TwitchChannel; @@ -47,45 +45,33 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; -public final class TwitchItemPane extends GridCell { +public final class TwitchItemPane extends BorderPane { - public static final float WIDTH = 150; + public static final DoubleProperty WIDTH_PROPERTY = new SimpleDoubleProperty(150); public static final DoubleProperty HEIGHT_PROPERTY = new SimpleDoubleProperty(); private static final int BOTTOM_OFFSET = 40; private static final double RATIO_GAME = 1.4D; private static final double RATIO_CHANNEL = 0.5625D; - private static final double HEIGHT_GAME = WIDTH * RATIO_GAME; - private static final double HEIGHT_CHANNEL = WIDTH * RATIO_CHANNEL; - - public TwitchItemPane() { - // Empty Constructor - } + private static final double HEIGHT_GAME = WIDTH_PROPERTY.get() * RATIO_GAME; + private static final double HEIGHT_CHANNEL = WIDTH_PROPERTY.get() * RATIO_CHANNEL; - @Override - protected void updateItem(final ITwitchItem item, final boolean empty) { - super.updateItem(item, empty); - if (empty || item == null) { - setText(null); - setGraphic(null); - } else { - if (item instanceof TwitchGame) { - final TwitchGame game = (TwitchGame) item; - setGraphic(this.createGameBorderPane(game)); - HEIGHT_PROPERTY.set(HEIGHT_GAME + BOTTOM_OFFSET); - } else if (item instanceof TwitchChannel) { - final TwitchChannel channel = (TwitchChannel) item; - setGraphic(this.createChannelBorderPane(channel)); - HEIGHT_PROPERTY.set(HEIGHT_CHANNEL + BOTTOM_OFFSET); - } + public TwitchItemPane(final ITwitchItem item) { + if (item instanceof TwitchGame) { + final TwitchGame game = (TwitchGame) item; + this.createGameBorderPane(game); + HEIGHT_PROPERTY.set(HEIGHT_GAME + BOTTOM_OFFSET); + } else if (item instanceof TwitchChannel) { + final TwitchChannel channel = (TwitchChannel) item; + this.createChannelBorderPane(channel); + HEIGHT_PROPERTY.set(HEIGHT_CHANNEL + BOTTOM_OFFSET); } } - private BorderPane createGameBorderPane(final TwitchGame game) { - final BorderPane contentBorderPane = new BorderPane(); + private void createGameBorderPane(final TwitchGame game) { final ImageView gameImage = new ImageView(); gameImage.imageProperty().bind(game.getBoxImage()); - gameImage.setFitWidth(WIDTH); + gameImage.setFitWidth(WIDTH_PROPERTY.get()); gameImage.setFitHeight(HEIGHT_GAME); final Label nameLabel = new Label(); nameLabel.setTooltip(new Tooltip("Name of Category")); @@ -100,25 +86,22 @@ private BorderPane createGameBorderPane(final TwitchGame game) { channelLabel.textProperty().bind(game.getChannelCount()); channelLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.USER)); final VBox textBox = new VBox(nameLabel, viewersLabel, channelLabel); - contentBorderPane.setCenter(gameImage); - contentBorderPane.setBottom(textBox); - contentBorderPane.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { + this.setCenter(gameImage); + this.setBottom(textBox); + this.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { if (event.getButton() == MouseButton.PRIMARY) { BrowserCore.getInstance().openGame(game.getName().get()); } else if (event.getButton() == MouseButton.SECONDARY) { - final ContextMenu contextMenu = createContextMenu(game); - this.contextMenuProperty().set(contextMenu); + this.showContextMenu(game, event.getScreenX(), event.getScreenY()); } event.consume(); }); - return contentBorderPane; } - private BorderPane createChannelBorderPane(final TwitchChannel channel) { - final BorderPane contentBorderPane = new BorderPane(); + private void createChannelBorderPane(final TwitchChannel channel) { final ImageView channelImage = new ImageView(); channelImage.imageProperty().bind(channel.getPreviewImageMedium()); - channelImage.setFitWidth(WIDTH); + channelImage.setFitWidth(WIDTH_PROPERTY.get()); channelImage.setFitHeight(HEIGHT_CHANNEL); final Label nameLabel = new Label(); nameLabel.setTooltip(new Tooltip("Name of the Channel")); @@ -133,25 +116,23 @@ private BorderPane createChannelBorderPane(final TwitchChannel channel) { uptimeLabel.textProperty().bind(channel.getUptimeString()); uptimeLabel.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.CLOCK_ALT)); final VBox textBox = new VBox(nameLabel, viewersLabel, uptimeLabel); - contentBorderPane.setCenter(channelImage); - contentBorderPane.setBottom(textBox); + this.setCenter(channelImage); + this.setBottom(textBox); final Tooltip titleTooltip = new Tooltip(); titleTooltip.textProperty().bind(channel.getTitle()); - final Node node = contentBorderPane; + final Node node = this; Tooltip.install(node, titleTooltip); - contentBorderPane.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { + this.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { if (event.getButton() == MouseButton.PRIMARY) { BrowserCore.getInstance().startStream(channel.getName().get()); } else if (event.getButton() == MouseButton.SECONDARY) { - final ContextMenu contextMenu = createContextMenu(channel); - this.contextMenuProperty().set(contextMenu); + this.showContextMenu(channel, event.getScreenX(), event.getScreenY()); } event.consume(); }); - return contentBorderPane; } - private static ContextMenu createContextMenu(final TwitchChannel channel) { + private void showContextMenu(final TwitchChannel channel, final double xPos, final double yPos) { final ContextMenu contextMenu = new ContextMenu(); final MenuItem startStream = new MenuItem("Start Stream"); startStream.setOnAction(eventStartContext -> BrowserCore.getInstance().startStream(channel.getName().get())); @@ -161,10 +142,10 @@ private static ContextMenu createContextMenu(final TwitchChannel channel) { .setOnAction(eventAddContext -> LsGuiUtils.addChannelToService(channel.getName().get(), twitchService)); contextMenu.getItems().add(startStream); contextMenu.getItems().add(addToList); - return contextMenu; + contextMenu.show(this.getScene().getWindow(), xPos, yPos); } - private static ContextMenu createContextMenu(final TwitchGame game) { + private void showContextMenu(final TwitchGame game, final double xPos, final double yPos) { final ContextMenu contextMenu = new ContextMenu(); if (!Settings.getInstance().favouriteGamesProperty().contains(game.getName().get())) { final MenuItem addToFavourites = new MenuItem("Add to Favourites"); @@ -177,6 +158,6 @@ private static ContextMenu createContextMenu(final TwitchGame game) { .setOnAction(eventStartContext -> Settings.getInstance().removeFavouriteGame(game.getName().get())); contextMenu.getItems().add(removeFromFavourites); } - return contextMenu; + contextMenu.show(this.getScene().getWindow(), xPos, yPos); } } From a36718c08b087ea6bca6aeb8441384eba5742c13 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Tue, 11 Oct 2016 03:04:53 +0200 Subject: [PATCH 15/27] style improvements, simplified writing settings --- .../app/lsgui/gui/chat/ChatController.java | 8 +- .../lsgui/gui/twitchbrowser/BrowserTab.java | 50 ++++++++--- .../gui/twitchbrowser/BrowserTabPane.java | 23 +++++ .../lsgui/model/generic/GenericChannel.java | 2 +- .../app/lsgui/model/twitch/TwitchChannel.java | 4 +- .../java/app/lsgui/utils/BrowserCore.java | 4 +- src/main/java/app/lsgui/utils/JsonUtils.java | 13 +++ src/main/java/app/lsgui/utils/Settings.java | 90 +++++++------------ 8 files changed, 115 insertions(+), 79 deletions(-) diff --git a/src/main/java/app/lsgui/gui/chat/ChatController.java b/src/main/java/app/lsgui/gui/chat/ChatController.java index f3a8d69..2f5b723 100644 --- a/src/main/java/app/lsgui/gui/chat/ChatController.java +++ b/src/main/java/app/lsgui/gui/chat/ChatController.java @@ -100,11 +100,9 @@ private void sendMessage(final String message) { public void connect(final String channel) { final String twitchIrc = "irc.chat.twitch.tv"; - if (!"".equals(Settings.getInstance().twitchUserProperty().get()) - && !"".equals(Settings.getInstance().twitchOAuthProperty().get())) { - final String user = Settings.getInstance().twitchUserProperty().get(); - final String oauth = Settings.getInstance().twitchOAuthProperty().get(); - + final String user = Settings.getInstance().twitchUserProperty().get(); + final String oauth = Settings.getInstance().twitchOAuthProperty().get(); + if (!"".equals(user) && !"".equals(oauth)) { this.client.setUserName(user); this.client.setChannel(channel); this.clientConnect(twitchIrc, oauth); diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java index e4226b5..ffc4f3a 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -1,5 +1,31 @@ +/** + * MIT License + * + * Copyright (c) 2016 Jan-Niklas Keck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package app.lsgui.gui.twitchbrowser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import app.lsgui.model.twitch.ITwitchItem; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; @@ -15,6 +41,10 @@ public final class BrowserTab extends Tab { + private static final Logger LOGGER = LoggerFactory.getLogger(BrowserTab.class); + private static final double ITEM_GAP = 15.0D; + private static final int PREFERED_COLUMNS = 5; + private ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); private ListProperty activeItems = new SimpleListProperty<>(FXCollections.observableArrayList()); private ScrollPane content; @@ -23,6 +53,7 @@ public BrowserTab(final String name) { super(name); this.content = this.buildContent(); setContent(this.content); + LOGGER.trace("Created Browsertab for: {}", name); } public ScrollPane getCustomContent() { @@ -36,25 +67,22 @@ private ScrollPane buildContent() { scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); final TilePane pane = new TilePane(); - pane.setPrefColumns(5); - pane.setVgap(10.0D); - pane.setHgap(15.0D); - this.activeItemsProperty().addListener((ListChangeListener.Change c) -> { - pane.getChildren().setAll(this.convertToNodeList(this.activeItemsProperty().get())); - }); + pane.setPrefColumns(PREFERED_COLUMNS); + pane.setVgap(ITEM_GAP); + pane.setHgap(ITEM_GAP); + this.activeItemsProperty().addListener((ListChangeListener.Change c) -> pane + .getChildren().setAll(convertToNodeList(this.activeItemsProperty().get()))); scrollPane.setContent(pane); return scrollPane; } - private ObservableList convertToNodeList(final ObservableList items) { + private static ObservableList convertToNodeList(final ObservableList items) { final ObservableList list = FXCollections.observableArrayList(); - items.stream().forEach((item) -> { - list.add(this.convertToBorderPane(item)); - }); + items.stream().forEach(item -> list.add(convertToBorderPane(item))); return list; } - private BorderPane convertToBorderPane(final ITwitchItem item) { + private static BorderPane convertToBorderPane(final ITwitchItem item) { return new TwitchItemPane(item); } diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java index 34fd43d..2e01b8d 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTabPane.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2016 Jan-Niklas Keck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package app.lsgui.gui.twitchbrowser; import java.util.List; diff --git a/src/main/java/app/lsgui/model/generic/GenericChannel.java b/src/main/java/app/lsgui/model/generic/GenericChannel.java index d691f34..0c337cd 100644 --- a/src/main/java/app/lsgui/model/generic/GenericChannel.java +++ b/src/main/java/app/lsgui/model/generic/GenericChannel.java @@ -77,7 +77,7 @@ public void setReminder(final boolean hasReminder) { public static Callback extractor() { return (IChannel sm) -> new Observable[] { ((GenericChannel) sm).getName(), - ((GenericChannel) sm).getDisplayName(), ((GenericChannel) sm).isOnline() }; + ((GenericChannel) sm).getDisplayName(), ((GenericChannel) sm).isOnline(), }; } @Override diff --git a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java index fd1d03c..e1aaf06 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java @@ -119,10 +119,10 @@ private void setOnline(final TwitchChannel data) { this.viewers.setValue(data.getViewers().get()); this.viewersString.setValue(Integer.toString(this.getViewers().get())); if (data.isOnline().get() && !this.isOnline.get()) { - this.isOnline.setValue(true); + this.isOnline.setValue(Boolean.TRUE); this.cameOnline = true; } else if (!data.isOnline().get()) { - this.isOnline.setValue(false); + this.isOnline.setValue(Boolean.FALSE); } this.isPlaylist.setValue(data.getIsPlaylist().get()); this.previewImageLarge.setValue(data.getPreviewImageLarge().get()); diff --git a/src/main/java/app/lsgui/utils/BrowserCore.java b/src/main/java/app/lsgui/utils/BrowserCore.java index 50afbf1..88563eb 100644 --- a/src/main/java/app/lsgui/utils/BrowserCore.java +++ b/src/main/java/app/lsgui/utils/BrowserCore.java @@ -104,9 +104,8 @@ public void goToHome() { public void openGame(final String game) { LOGGER.debug("Open Data for Game '{}'", game); - final TwitchChannels channels = TwitchAPIClient.getInstance().getGameData(game); final BrowserTab gameTab; - if (gameTabAlreadyExists(game)) { + if (this.gameTabAlreadyExists(game)) { final Optional optionalTab = this.tabPane.getBrowserTabs().stream() .filter(tab -> tab.getText().equalsIgnoreCase(game)).findFirst(); if (optionalTab.isPresent()) { @@ -118,6 +117,7 @@ public void openGame(final String game) { } else { gameTab = this.addGameTab(game); } + final TwitchChannels channels = TwitchAPIClient.getInstance().getGameData(game); gameTab.itemsProperty().set(channels.getChannels()); gameTab.activeItemsProperty().set(channels.getChannels()); this.scrollToTop(); diff --git a/src/main/java/app/lsgui/utils/JsonUtils.java b/src/main/java/app/lsgui/utils/JsonUtils.java index daf26fb..3abd8a1 100644 --- a/src/main/java/app/lsgui/utils/JsonUtils.java +++ b/src/main/java/app/lsgui/utils/JsonUtils.java @@ -26,14 +26,17 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -116,4 +119,14 @@ public static JsonArray getJsonArrayFromFile(final File file) { } return jsonArray; } + + public static void writeJsonToFile(final File file, final JsonElement element) { + try (final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), + StandardCharsets.UTF_8)) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + gson.toJson(element, writer); + } catch (IOException e) { + LOGGER.error("Could not write settings to File", e); + } + } } diff --git a/src/main/java/app/lsgui/utils/Settings.java b/src/main/java/app/lsgui/utils/Settings.java index 71e0676..ff79563 100644 --- a/src/main/java/app/lsgui/utils/Settings.java +++ b/src/main/java/app/lsgui/utils/Settings.java @@ -23,12 +23,8 @@ */ package app.lsgui.utils; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Locale; import java.util.Optional; @@ -37,8 +33,8 @@ import org.slf4j.LoggerFactory; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.stream.JsonWriter; import app.lsgui.model.IChannel; import app.lsgui.model.IService; @@ -131,7 +127,8 @@ public void saveSettings() { } catch (IOException e) { LOGGER.error("ERROR while creaing Settings file", e); } - this.createSettingsJson(settings); + final JsonElement data = this.createSettingsJson(); + JsonUtils.writeJsonToFile(settings, data); } private void loadSettingsFromFile(final File file) { @@ -185,64 +182,41 @@ private void loadServices(final JsonArray jArray) { } } - private void createSettingsJson(final File file) { - try (final FileOutputStream outputStream = new FileOutputStream(file);) { - final BufferedWriter bufferedWriter = new BufferedWriter( - new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); - final JsonWriter jsonWriter = new JsonWriter(bufferedWriter); - jsonWriter.setIndent(" "); - jsonWriter.beginArray(); - jsonWriter.beginObject(); - jsonWriter.name(TWITCH_USER_STRING).value(this.twitchUserProperty().get()); - jsonWriter.name(TWITCH_OAUTH_STRING).value(this.twitchOAuthProperty().get()); - jsonWriter.name(TWITCH_SORT).value(this.sortTwitchProperty().get()); - jsonWriter.name(QUALITY_STRING).value(this.qualityProperty().get()); - jsonWriter.name(PATH).value(this.recordingPathProperty().get()); - jsonWriter.name(CHANNELS_LOAD).value(this.maxChannelsProperty().get()); - jsonWriter.name(GAMES_LOAD).value(this.maxGamesProperty().get()); - jsonWriter.name(MINIMIZE_TO_TRAY_STRING).value(this.minimizeToTrayProperty().get()); - jsonWriter.name(WINDOWSTYLE_STRING).value(this.windowStyleProperty().get()); - jsonWriter.name(EXEPATH_STRING).value(this.livestreamerPathProperty().get()); - this.writeFavouriteGames(jsonWriter); - jsonWriter.endObject(); - this.writeServices(jsonWriter); - jsonWriter.endArray(); - jsonWriter.close(); - bufferedWriter.close(); - } catch (IOException e) { - LOGGER.error("ERROR while writing to Settings file", e); + private JsonElement createSettingsJson() { + final JsonObject generalSettings = new JsonObject(); + generalSettings.addProperty(TWITCH_USER_STRING, this.twitchUserProperty().get()); + generalSettings.addProperty(TWITCH_OAUTH_STRING, this.twitchOAuthProperty().get()); + generalSettings.addProperty(TWITCH_SORT, this.sortTwitchProperty().get()); + generalSettings.addProperty(QUALITY_STRING, this.qualityProperty().get()); + generalSettings.addProperty(PATH, this.recordingPathProperty().get()); + generalSettings.addProperty(CHANNELS_LOAD, this.maxChannelsProperty().get()); + generalSettings.addProperty(GAMES_LOAD, this.maxGamesProperty().get()); + generalSettings.addProperty(MINIMIZE_TO_TRAY_STRING, this.minimizeToTrayProperty().get()); + generalSettings.addProperty(WINDOWSTYLE_STRING, this.windowStyleProperty().get()); + generalSettings.addProperty(EXEPATH_STRING, this.livestreamerPathProperty().get()); + final JsonArray favouriteGamesArray = new JsonArray(); + for (final String favourite : this.favouriteGames.get()) { + favouriteGamesArray.add(favourite); } - } - - private void writeServices(final JsonWriter writer) throws IOException { - writer.beginArray(); - for (final IService service : this.services) { - LOGGER.debug("Creating JSON for Service {}", service.getName().get()); - writer.beginObject(); - writer.name(SERVICE_NAME).value(service.getName().get()); - writer.name(SERVICE_URL).value(service.getUrl().get()); - writer.name("channels"); - writer.beginArray(); + generalSettings.add(FAVOURITE_GAMES, favouriteGamesArray); + final JsonArray servicesArray = new JsonArray(); + for (final IService service : this.services.get()) { + final JsonObject serviceObject = new JsonObject(); + serviceObject.addProperty(SERVICE_NAME, service.getName().get()); + serviceObject.addProperty(SERVICE_URL, service.getUrl().get()); + final JsonArray channelArray = new JsonArray(); for (final IChannel channel : service.getChannelProperty().get()) { if (channel.getName().get() != null) { - writer.value(channel.getName().get()); + channelArray.add(channel.getName().get()); } } - writer.endArray(); - writer.endObject(); - } - writer.endArray(); - } - - private void writeFavouriteGames(final JsonWriter writer) throws IOException { - LOGGER.debug("Writing Favourites to Settings file"); - writer.name(FAVOURITE_GAMES); - writer.beginArray(); - for (final String favourite : this.favouriteGames) { - LOGGER.trace("Writing Favourite '{}' to file", favourite); - writer.value(favourite); + serviceObject.add("channels", channelArray); + servicesArray.add(serviceObject); } - writer.endArray(); + final JsonArray settingsArray = new JsonArray(); + settingsArray.add(generalSettings); + settingsArray.add(servicesArray); + return settingsArray; } public IService getTwitchService() { From 2050e748693378d8b9748dc610d37616c8953497 Mon Sep 17 00:00:00 2001 From: westerwave Date: Tue, 11 Oct 2016 15:01:14 +0200 Subject: [PATCH 16/27] increase scroll amount --- .../java/app/lsgui/gui/twitchbrowser/BrowserTab.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java index ffc4f3a..d059166 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -32,10 +32,12 @@ import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.control.Tab; +import javafx.scene.input.ScrollEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.TilePane; @@ -66,7 +68,17 @@ private ScrollPane buildContent() { scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS); scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); + final TilePane pane = new TilePane(); + pane.setOnScroll(new EventHandler() { + @Override + public void handle(final ScrollEvent scrollEvent) { + final double deltaY = scrollEvent.getDeltaY() * 2; + final double height = BrowserTab.this.getCustomContent().getBoundsInLocal().getHeight(); + final double vValue = BrowserTab.this.getCustomContent().getVvalue(); + BrowserTab.this.getCustomContent().setVvalue(vValue - deltaY/height); + } + }); pane.setPrefColumns(PREFERED_COLUMNS); pane.setVgap(ITEM_GAP); pane.setHgap(ITEM_GAP); From 2e0ba0b0dd7c83401b5d4e632057df46751bca05 Mon Sep 17 00:00:00 2001 From: westerwave Date: Tue, 11 Oct 2016 15:01:29 +0200 Subject: [PATCH 17/27] add this to variables --- .../app/lsgui/remote/twitch/TwitchBrowserUpdateService.java | 5 +++-- .../app/lsgui/remote/twitch/TwitchChannelUpdateService.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java b/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java index 60ff66f..7df58db 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchBrowserUpdateService.java @@ -64,8 +64,9 @@ protected Task createTask() { return new Task() { @Override protected TwitchChannel call() throws Exception { - TwitchUtils.addChannelToList(ACTIVE_LIST, channel); - return TwitchAPIClient.getInstance().getStreamData(channel.getName().get(), true); + TwitchUtils.addChannelToList(ACTIVE_LIST, TwitchBrowserUpdateService.this.channel); + return TwitchAPIClient.getInstance() + .getStreamData(TwitchBrowserUpdateService.this.channel.getName().get(), true); } }; } diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java b/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java index ce3bb5e..958e454 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java @@ -74,8 +74,9 @@ protected Task createTask() { return new Task() { @Override protected TwitchChannel call() throws Exception { - TwitchUtils.addChannelToList(ACTIVE_LIST, channel); - return TwitchAPIClient.getInstance().getStreamData(channel.getName().get(), false); + TwitchUtils.addChannelToList(ACTIVE_LIST, TwitchChannelUpdateService.this.channel); + return TwitchAPIClient.getInstance() + .getStreamData(TwitchChannelUpdateService.this.channel.getName().get(), false); } }; } From fbe7b01a714024fbe79156a8ee21d4342aab69fc Mon Sep 17 00:00:00 2001 From: westerwave Date: Tue, 11 Oct 2016 15:02:01 +0200 Subject: [PATCH 18/27] improve classpath --- .classpath | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.classpath b/.classpath index ebff373..16b5dca 100644 --- a/.classpath +++ b/.classpath @@ -15,7 +15,7 @@ - + From 6181ea28740a004c1debf1d21f407dd2fbb97298 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Thu, 13 Oct 2016 01:06:14 +0200 Subject: [PATCH 19/27] convert to lambda and add padding --- .../lsgui/gui/twitchbrowser/BrowserTab.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java index d059166..48333bd 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/BrowserTab.java @@ -32,12 +32,11 @@ import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; -import javafx.event.EventHandler; +import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.control.Tab; -import javafx.scene.input.ScrollEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.TilePane; @@ -68,20 +67,18 @@ private ScrollPane buildContent() { scrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS); scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); - + final TilePane pane = new TilePane(); - pane.setOnScroll(new EventHandler() { - @Override - public void handle(final ScrollEvent scrollEvent) { - final double deltaY = scrollEvent.getDeltaY() * 2; - final double height = BrowserTab.this.getCustomContent().getBoundsInLocal().getHeight(); - final double vValue = BrowserTab.this.getCustomContent().getVvalue(); - BrowserTab.this.getCustomContent().setVvalue(vValue - deltaY/height); - } + pane.setOnScroll(scrollEvent -> { + final double deltaY = scrollEvent.getDeltaY() * 2; + final double height = BrowserTab.this.getCustomContent().getBoundsInLocal().getHeight(); + final double vValue = BrowserTab.this.getCustomContent().getVvalue(); + BrowserTab.this.getCustomContent().setVvalue(vValue - deltaY / height); }); pane.setPrefColumns(PREFERED_COLUMNS); pane.setVgap(ITEM_GAP); pane.setHgap(ITEM_GAP); + pane.setPadding(new Insets(ITEM_GAP)); this.activeItemsProperty().addListener((ListChangeListener.Change c) -> pane .getChildren().setAll(convertToNodeList(this.activeItemsProperty().get()))); scrollPane.setContent(pane); From b495bfec95431e1fa897e890fbc37bb5d79546fd Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Thu, 13 Oct 2016 01:06:27 +0200 Subject: [PATCH 20/27] explicitly use utf8 --- src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java b/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java index 95c2291..24a0213 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java @@ -27,6 +27,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.util.Set; import java.util.TreeSet; @@ -168,9 +169,11 @@ public boolean channelExists(final String channel) { private static String getAPIResponse(final URI apiUrl) { LOGGER.trace("Send Request to API URL '{}'", apiUrl); final HttpGet request = new HttpGet(apiUrl); - request.setHeader("Client-ID", LSGUI_CLIENT_ID); + request.addHeader("Client-ID", LSGUI_CLIENT_ID); + request.addHeader("Content-Type", "charset=UTF-8"); try (final CloseableHttpResponse response = HTTP_CLIENT.execute(request)) { - return new BasicResponseHandler().handleResponse(response); + final String responseString = new BasicResponseHandler().handleResponse(response); + return new String(responseString.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8); } catch (UnknownHostException e) { LOGGER.error("Twitch is not reachable. Check your Internet Connection", e); } catch (HttpResponseException e) { From 7240bfd2635d22f7b32a32f9e9730a24e7284686 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Thu, 13 Oct 2016 01:06:44 +0200 Subject: [PATCH 21/27] make constants private --- .../java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java index 97595a7..b5fb83f 100644 --- a/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java +++ b/src/main/java/app/lsgui/gui/twitchbrowser/TwitchItemPane.java @@ -47,9 +47,8 @@ public final class TwitchItemPane extends BorderPane { - public static final DoubleProperty WIDTH_PROPERTY = new SimpleDoubleProperty(150); - public static final DoubleProperty HEIGHT_PROPERTY = new SimpleDoubleProperty(); - + private static final DoubleProperty HEIGHT_PROPERTY = new SimpleDoubleProperty(); + private static final DoubleProperty WIDTH_PROPERTY = new SimpleDoubleProperty(150); private static final int BOTTOM_OFFSET = 40; private static final double RATIO_GAME = 1.4D; private static final double RATIO_CHANNEL = 0.5625D; From 19c8dd4fde670484d63f98d5951b1a46e8823df0 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Thu, 13 Oct 2016 01:06:55 +0200 Subject: [PATCH 22/27] shorten game name string --- .../java/app/lsgui/model/twitch/TwitchGame.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/app/lsgui/model/twitch/TwitchGame.java b/src/main/java/app/lsgui/model/twitch/TwitchGame.java index 4b29b41..095994c 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchGame.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchGame.java @@ -45,7 +45,7 @@ public final class TwitchGame implements ITwitchItem { private TwitchChannels channels; public TwitchGame(final String name, final int viewers, final int channelCount, final Image boxImage) { - this.name = new SimpleStringProperty(name); + this.name = new SimpleStringProperty(shortenString(name)); this.viewers = new SimpleStringProperty(Integer.toString(viewers)); this.boxImage = new SimpleObjectProperty<>(boxImage); this.channelCount = new SimpleStringProperty(Integer.toString(channelCount)); @@ -56,13 +56,22 @@ public void loadChannelData() { } public void updateData(final TwitchGame updatedGame) { - this.name = new SimpleStringProperty(updatedGame.getName().get()); + this.name = new SimpleStringProperty(shortenString(updatedGame.getName().get())); this.viewers = new SimpleStringProperty(updatedGame.getViewers().get()); this.boxImage = new SimpleObjectProperty<>(updatedGame.getBoxImage().get()); this.channelCount = new SimpleStringProperty(updatedGame.getChannelCount().get()); this.loadChannelData(); } + public static String shortenString(final String input) { + String result = input; + final int maxLength = 20; + if (input.length() > maxLength) { + result = input.substring(0, maxLength - 1); + } + return result; + } + public TwitchChannels getChannels() { return this.channels; } From d3e934cb34396b19a614dc4949b802423685ee2f Mon Sep 17 00:00:00 2001 From: westerwave Date: Mon, 17 Oct 2016 15:04:03 +0200 Subject: [PATCH 23/27] add null check --- src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java b/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java index 762f285..c8aeaab 100644 --- a/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java +++ b/src/main/java/app/lsgui/gui/main/toolbar/QualityComboBox.java @@ -39,7 +39,7 @@ public QualityComboBox() { public void initialize() { getSelectionModel().selectedItemProperty().addListener((obs, oldValue, newValue) -> { - if (!OFFLINEQUALITY.equals(newValue)) { + if (newValue != null && !OFFLINEQUALITY.equals(newValue)) { LOGGER.debug("Set selected Quality to {}", newValue); Settings.getInstance().qualityProperty().set(newValue); } From ab224339fd55c70784c1e3ac22c77c748dc6b40d Mon Sep 17 00:00:00 2001 From: westerwave Date: Mon, 17 Oct 2016 15:05:26 +0200 Subject: [PATCH 24/27] select quality after channel update --- .../app/lsgui/gui/main/LsGuiController.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/app/lsgui/gui/main/LsGuiController.java b/src/main/java/app/lsgui/gui/main/LsGuiController.java index 0ea6d24..016f565 100644 --- a/src/main/java/app/lsgui/gui/main/LsGuiController.java +++ b/src/main/java/app/lsgui/gui/main/LsGuiController.java @@ -31,8 +31,10 @@ import app.lsgui.gui.main.toolbar.QualityComboBox; import app.lsgui.gui.main.toolbar.ServiceComboBox; import app.lsgui.gui.main.toolbar.TopToolBar; +import app.lsgui.model.IChannel; import app.lsgui.model.IService; import app.lsgui.utils.Settings; +import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.layout.BorderPane; @@ -72,18 +74,7 @@ private void setupChannelList() { this.channelList.getListView().getSelectionModel().selectedItemProperty() .addListener((observable, oldValue, newValue) -> { if (newValue != null) { - final QualityComboBox qualityComboBox = this.topToolBar.getQualityComboBox(); - qualityComboBox.itemsProperty().bind(newValue.getAvailableQualities()); - if (qualityComboBox.getItems().size() > 1) { - final String quality = Settings.getInstance().qualityProperty().get(); - if (qualityComboBox.getItems().contains(quality)) { - qualityComboBox.getSelectionModel().select(quality); - } else { - qualityComboBox.getSelectionModel().select(Settings.DEFAULT_QUALITY); - } - } else { - qualityComboBox.getSelectionModel().select(0); - } + this.bindAndSelect(newValue); } }); final ServiceComboBox serviceComboBox = this.topToolBar.getServiceComboBox(); @@ -93,6 +84,22 @@ private void setupChannelList() { this.contentBorderPane.setLeft(this.channelList); } + private void bindAndSelect(final IChannel newValue) { + final QualityComboBox qualityComboBox = this.topToolBar.getQualityComboBox(); + qualityComboBox.itemsProperty().bind(newValue.getAvailableQualities()); + if (qualityComboBox.getItems().size() > 1) { + final String quality = Settings.getInstance().qualityProperty().get(); + if (qualityComboBox.getItems().contains(quality)) { + Platform.runLater( + () -> qualityComboBox.getSelectionModel().select(quality)); + } else { + qualityComboBox.getSelectionModel().select(Settings.DEFAULT_QUALITY); + } + } else { + qualityComboBox.getSelectionModel().select(0); + } + } + private void setupChannelInfoPanel() { LOGGER.debug("Initialize ChannelInfoPanel"); final ServiceComboBox serviceComboBox = this.topToolBar.getServiceComboBox(); From 4dd6e205d53464172e1984d6f10ef78a22f2d307 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Fri, 18 Nov 2016 18:19:21 +0100 Subject: [PATCH 25/27] update libraries --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 5c2583b..ca9087a 100644 --- a/build.gradle +++ b/build.gradle @@ -27,10 +27,10 @@ ext { richtextfxVersion = "0.6.10" fontawesomefxVersion = "8.9" controlsfxVersion = "8.40.12" - gsonVersion = "2.7" + gsonVersion = "2.8.0" httpclientVersion = "4.5.2" slf4jVersion = "1.7.21" - log4jVersion = "2.6.2" + log4jVersion = "2.7" junitVersion = "4.12" } From e6aee6237432c4ff1341c26c2321e6c8b457ef15 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Fri, 18 Nov 2016 18:19:49 +0100 Subject: [PATCH 26/27] update API requests to Twitch API v5, also fixes browser --- .../app/lsgui/model/twitch/TwitchChannel.java | 6 ++++ .../lsgui/remote/twitch/TwitchAPIClient.java | 30 +++++++++++++++++-- .../twitch/TwitchChannelUpdateService.java | 2 +- .../java/app/lsgui/utils/TwitchUtils.java | 2 ++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java index e1aaf06..3019263 100644 --- a/src/main/java/app/lsgui/model/twitch/TwitchChannel.java +++ b/src/main/java/app/lsgui/model/twitch/TwitchChannel.java @@ -55,6 +55,7 @@ public final class TwitchChannel implements IChannel, ITwitchItem { private static final Logger LOGGER = LoggerFactory.getLogger(TwitchChannel.class); + private IntegerProperty id = new SimpleIntegerProperty(); private StringProperty name = new SimpleStringProperty(); private StringProperty displayName = new SimpleStringProperty(); private StringProperty logoURL = new SimpleStringProperty(); @@ -107,6 +108,7 @@ private void setOffline(final String name) { private void setOnline(final TwitchChannel data) { LOGGER.trace("update {} with data {}", data.getName(), data.isOnline()); + this.id.setValue(data.getId().get()); this.name.setValue(data.getName().get()); this.displayName.setValue(data.displayNameProperty().get()); this.logoURL.setValue(data.getLogoURL().get()); @@ -248,4 +250,8 @@ public boolean isTwitchChannel() { public StringProperty getDisplayName() { return this.displayName; } + + public IntegerProperty getId() { + return this.id; + } } diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java b/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java index 24a0213..f5bec68 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchAPIClient.java @@ -50,6 +50,7 @@ import app.lsgui.model.twitch.TwitchChannel; import app.lsgui.model.twitch.TwitchChannels; import app.lsgui.model.twitch.TwitchGames; +import app.lsgui.utils.JsonUtils; import app.lsgui.utils.Settings; import app.lsgui.utils.TwitchUtils; @@ -62,8 +63,11 @@ public final class TwitchAPIClient { private static final Logger LOGGER = LoggerFactory.getLogger(TwitchAPIClient.class); private static final JsonParser JSONPARSER = new JsonParser(); + + private static final String TWITCH_API_VERSION_HEADER = "application/vnd.twitchtv.v5+json"; private static final String TWITCH_BASE_URL = "https://api.twitch.tv/kraken/"; private static final String LSGUI_CLIENT_ID = "rfpepzumaxd1iija3ip3fixao6z13pj"; + private static final int CONNECTION_COUNT = 100; private static final CloseableHttpClient HTTP_CLIENT; @@ -92,7 +96,8 @@ public TwitchChannel getStreamData(final String channelName, final boolean isBro TwitchChannel channel = TwitchUtils.constructTwitchChannel(new JsonObject(), channelName, isBrowser); if (!"".equals(channelName)) { try { - final URI uri = convertToURI(TWITCH_BASE_URL + "streams/" + channelName); + final String twitchUserId = getTwitchUserIdFromName(channelName); + final URI uri = convertToURI(TWITCH_BASE_URL + "streams/" + twitchUserId); final JsonObject jsonData = JSONPARSER.parse(getAPIResponse(uri)).getAsJsonObject(); channel = TwitchUtils.constructTwitchChannel(jsonData, channelName, isBrowser); } catch (JsonSyntaxException e) { @@ -104,6 +109,24 @@ public TwitchChannel getStreamData(final String channelName, final boolean isBro return channel; } + private static String getTwitchUserIdFromName(final String channelName) { + LOGGER.debug("Request Twitch UserId for username {}", channelName); + String userId = ""; + final URI uri = convertToURI(TWITCH_BASE_URL + "search/channels?query=" + channelName); + final JsonObject jsonData = JSONPARSER.parse(getAPIResponse(uri)).getAsJsonObject(); + final JsonArray channels = jsonData.get("channels").getAsJsonArray(); + for (final JsonElement element : channels) { + final JsonObject jsonObject = element.getAsJsonObject(); + final String userName = JsonUtils.getStringIfNotNull("name", jsonObject); + if (userName.equalsIgnoreCase(channelName)) { + userId = jsonObject.get("_id").getAsString(); + break; + } + } + LOGGER.debug("Return Twitch User id {} for username {}", userId, channelName); + return userId; + } + public TwitchChannels getGameData(final String game) { LOGGER.debug("Load game Data"); final String gameName = game.replace(' ', '+'); @@ -167,16 +190,17 @@ public boolean channelExists(final String channel) { } private static String getAPIResponse(final URI apiUrl) { - LOGGER.trace("Send Request to API URL '{}'", apiUrl); + LOGGER.debug("Send Request to API URL '{}'", apiUrl); final HttpGet request = new HttpGet(apiUrl); request.addHeader("Client-ID", LSGUI_CLIENT_ID); - request.addHeader("Content-Type", "charset=UTF-8"); + request.addHeader("Accept", TWITCH_API_VERSION_HEADER); try (final CloseableHttpResponse response = HTTP_CLIENT.execute(request)) { final String responseString = new BasicResponseHandler().handleResponse(response); return new String(responseString.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8); } catch (UnknownHostException e) { LOGGER.error("Twitch is not reachable. Check your Internet Connection", e); } catch (HttpResponseException e) { + LOGGER.error("HTTP Code {}", e.getStatusCode()); LOGGER.error("Http Error when fetching twitch api response.", e); } catch (IOException e) { LOGGER.error("Error when fetching twitch api response", e); diff --git a/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java b/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java index 958e454..77b0fad 100644 --- a/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java +++ b/src/main/java/app/lsgui/remote/twitch/TwitchChannelUpdateService.java @@ -66,7 +66,7 @@ public void setUpConstant() { } ACTIVE_LIST.remove(this.channel); }); - setOnFailed(event -> LOGGER.warn("UPDATE SERVICE FAILED {}", event.getEventType())); + setOnFailed(event -> LOGGER.warn("Channel Update Service FAILED. Event: {}", event.getEventType())); } @Override diff --git a/src/main/java/app/lsgui/utils/TwitchUtils.java b/src/main/java/app/lsgui/utils/TwitchUtils.java index f02e1b8..16457fb 100644 --- a/src/main/java/app/lsgui/utils/TwitchUtils.java +++ b/src/main/java/app/lsgui/utils/TwitchUtils.java @@ -179,6 +179,7 @@ private static void setData(final TwitchChannel channel, final JsonObject channe private static void setOnlineData(final TwitchChannel channel, final JsonObject channelObject) { final JsonObject channelJson = channelObject.get("channel").getAsJsonObject(); final JsonObject previewJson = channelObject.get("preview").getAsJsonObject(); + channel.getId().set(JsonUtils.getIntegerIfNotNull("_id", channelJson)); channel.getName().set(JsonUtils.getStringIfNotNull("name", channelJson)); channel.displayNameProperty().set(JsonUtils.getStringIfNotNull("display_name", channelJson)); channel.getLogoURL().set(JsonUtils.getStringIfNotNull("logo", channelJson)); @@ -209,6 +210,7 @@ private static void setOnlineData(final TwitchChannel channel, final JsonObject } public static void setOfflineData(final TwitchChannel channel, final String name) { + channel.getId().setValue(0); channel.getName().set(name); channel.displayNameProperty().set(name); channel.getLogoURL().set(""); From 97cd21462b9f7bd149466e535c42b11f7c6220ed Mon Sep 17 00:00:00 2001 From: Jan-Niklas Keck Date: Fri, 18 Nov 2016 18:27:01 +0100 Subject: [PATCH 27/27] change to release version --- src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index e0df1d3..1c53ee1 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -22,4 +22,4 @@ # SOFTWARE. # -versionNumber=3.5.0-SNAPSHOT \ No newline at end of file +versionNumber=3.5.0 \ No newline at end of file