diff --git a/pom.xml b/pom.xml index 82a9e6f..a31f960 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.kellerkinder Project-HomeFlix - 0.6.0 + 0.6.1 jar Project-HomeFlix @@ -19,7 +19,7 @@ junit junit - 4.11 + 4.12 test @@ -50,13 +50,13 @@ org.apache.logging.log4j log4j-api - 2.10.0 + 2.11.0 org.apache.logging.log4j log4j-core - 2.10.0 + 2.11.0 diff --git a/src/main/java/kellerkinder/HomeFlix/application/Main.java b/src/main/java/kellerkinder/HomeFlix/application/Main.java index ee36ce5..2e7356d 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/Main.java +++ b/src/main/java/kellerkinder/HomeFlix/application/Main.java @@ -19,7 +19,6 @@ * MA 02110-1301, USA. * */ - package kellerkinder.HomeFlix.application; import java.io.File; @@ -77,6 +76,10 @@ public class Main extends Application { mainWindow(); } + /** + * initialize the mainWindowController, GUI and load the saved settings or call addFirstSource + * initialize the primaryStage and set the file/directory paths + */ private void mainWindow(){ try { FXMLLoader loader = new FXMLLoader(); @@ -111,7 +114,7 @@ public class Main extends Application { // startup checks if (!configFile.exists()) { directory.mkdir(); - getFirstSource(); + addFirstSource(); mainWindowController.setColor("ee3523"); mainWindowController.setSize(FONT_SIZE); mainWindowController.setAutoUpdate(false); @@ -132,10 +135,10 @@ public class Main extends Application { } /** - * TODO add option to add streaming as first source when there i no config.xml - * we need to get the path for the first source from the user + * we need to get the path for the first source from the user and add it to + * sources.json, if the user ends the file-/directory-chooser the program will exit */ - private void getFirstSource() { + private void addFirstSource() { switch (System.getProperty("user.language") + "_" + System.getProperty("user.country")) { case "en_US": bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english @@ -192,6 +195,11 @@ public class Main extends Application { selectFirstSource.showAndWait(); } + /** + * set the log file location and initialize the logger + * launch the GUI + * @param args arguments given at the start + */ public static void main(String[] args) { if (System.getProperty("os.name").equals("Windows")) { System.setProperty("logFilename", userHome + "/Documents/HomeFlix/app.log"); @@ -210,10 +218,6 @@ public class Main extends Application { return primaryStage; } - public void setPrimaryStage(Stage primaryStage) { - this.primaryStage = primaryStage; - } - public AnchorPane getPane() { return pane; } diff --git a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java index 074fbf4..762ed15 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java +++ b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java @@ -19,7 +19,6 @@ * MA 02110-1301, USA. * */ - package kellerkinder.HomeFlix.application; import java.awt.Desktop; @@ -759,18 +758,22 @@ public class MainWindowController { } //set color of UI-Elements + /** + * set the color of the GUI-Elements + * if usedColor is less than checkColor set text fill white, else black + */ private void applyColor() { String style = "-fx-background-color: #" + getColor() + ";"; String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: BLACK;"; String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: WHITE;"; - BigInteger icolor = new BigInteger(getColor(), 16); - BigInteger ccolor = new BigInteger("78909cff", 16); + BigInteger usedColor = new BigInteger(getColor(), 16); + BigInteger checkColor = new BigInteger("78909cff", 16); sideMenuVBox.setStyle(style); topHBox.setStyle(style); searchTextField.setFocusColor(Color.valueOf(getColor())); - if (icolor.compareTo(ccolor) == -1) { + if (usedColor.compareTo(checkColor) == -1) { dialogBtnStyle = btnStyleWhite; settingsBtn.setStyle("-fx-text-fill: WHITE;"); aboutBtn.setStyle("-fx-text-fill: WHITE;"); @@ -822,6 +825,9 @@ public class MainWindowController { translateTransition.play(); } + /** + * set the local based on the languageChoisBox selection + */ void setLocalUI() { switch (getLocal()) { case "en_US": @@ -895,7 +901,9 @@ public class MainWindowController { LOGGER.error("An error occurred", exception); } - // save settings + /** + * save the configuration to the config.xml file + */ public void saveSettings() { LOGGER.info("saving settings ..."); try { @@ -907,14 +915,17 @@ public class MainWindowController { props.setProperty("ratingSortType", columnFavorite.getSortType().toString()); OutputStream outputStream = new FileOutputStream(main.getConfigFile()); // new output-stream - props.storeToXML(outputStream, "Project HomeFlix settings"); // writes new .xml + props.storeToXML(outputStream, "Project HomeFlix settings"); // write new .xml outputStream.close(); } catch (IOException e) { LOGGER.error(errorLoad, e); } } - // load settings + /** + * load the configuration from the config.xml file + * and try to load the API keys from apiKeys.json + */ public void loadSettings() { LOGGER.info("loading settings ..."); diff --git a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java index 410c561..b5f703f 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ - package kellerkinder.HomeFlix.controller; import java.io.File; @@ -53,12 +52,7 @@ import kellerkinder.HomeFlix.datatypes.SourceDataType; import kellerkinder.HomeFlix.datatypes.FilmTabelDataType; public class DBController { - - public DBController(Main main, MainWindowController mainWindowController) { - this.main = main; - this.mainWindowController = mainWindowController; - } - + private MainWindowController mainWindowController; private Main main; private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; //path to database file @@ -71,6 +65,22 @@ public class DBController { private Connection connection = null; private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName()); + /** + * constructor for DBController + * @param main the main object + * @param mainWindowController the mainWindowController object + */ + public DBController(Main main, MainWindowController mainWindowController) { + this.main = main; + this.mainWindowController = mainWindowController; + } + + /** + * initialize the {@link DBController} + * initialize the database connection + * check if there is a need to create a new database + * refresh the database + */ public void init() { LOGGER.info("<========== starting loading sql ==========>"); initDatabaseConnection(); @@ -79,12 +89,16 @@ public class DBController { LOGGER.info("<========== finished loading sql ==========>"); } + /** + * create a new connection to the HomeFlix.db database + * AutoCommit is set to false to prevent some issues, so manual commit is active! + */ private void initDatabaseConnection() { DB_PATH = main.getDirectory() + "/Homeflix.db"; try { // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH); - connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active + connection.setAutoCommit(false); } catch (SQLException e) { // if the error message is "out of memory", it probably means no database file is found LOGGER.error("error while loading the ROM database", e); @@ -94,6 +108,7 @@ public class DBController { /** * if tables don't exist create them + * films table: streamUrl is primary key * cache table: streamUrl is primary key */ private void createDatabase() { @@ -110,6 +125,9 @@ public class DBController { } } + /** + * get all database entries + */ private void loadDatabase() { // get all entries from the table try { @@ -131,7 +149,11 @@ public class DBController { LOGGER.info("filme in db: " + filmsdbStreamURL.size()); } - // load the sources from sources.json + /** + * load sources from sources.json + * if mode == local, get all files and series-folder from the directory + * else mode must be streaming, read all entries from the streaming file + */ private void loadSources() { // remove sources from table mainWindowController.getSourcesList().removeAll(mainWindowController.getSourcesList()); @@ -181,7 +203,10 @@ public class DBController { } } - // loading data from database to mainWindowController + /** + * load the data to the mainWindowController + * order entries by title + */ private void loadDataToMWC() { LOGGER.info("loading data to mwc ..."); try { @@ -381,7 +406,10 @@ public class DBController { } } - // prints all entries from the database to the console + /** + * DEBUG + * prints all entries from the database to the console + */ public void printAllDBEntriesDEBUG() { System.out.println("Outputting all entries ... \n"); try { @@ -581,6 +609,11 @@ public class DBController { } } + /** + * return the currentTime in ms saved in the database + * @param streamUrl URL of the film + * @return {@link Double} currentTime in ms + */ public double getCurrentTime(String streamUrl) { LOGGER.info("currentTime: " + streamUrl); double currentTime = 0; @@ -597,6 +630,11 @@ public class DBController { return currentTime; } + /** + * save the currentTime to the database + * @param streamUrl URL of the film + * @param currentTime currentTime in ms of the film + */ public void setCurrentTime(String streamUrl, double currentTime) { LOGGER.info("currentTime: " + streamUrl); try { @@ -609,12 +647,18 @@ public class DBController { } } - public String getNextEpisode(String streamUrl, int nextEp) { + /** + * get the next episode of a + * @param title URL of the film + * @param nextEp number of the next episode + * @return {@link String} the streamUrl of the next episode + */ + public String getNextEpisode(String title, int nextEp) { String nextStreamUrl = ""; try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( - "SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\" AND episode = " + nextEp + ";"); + "SELECT * FROM films WHERE title = \"" + title + "\" AND episode = " + nextEp + ";"); nextStreamUrl = rs.getString("streamUrl"); rs.close(); stmt.close(); @@ -624,7 +668,6 @@ public class DBController { return nextStreamUrl; } - // removes the ending private String cutOffEnd(String str) { if (str == null) return null; diff --git a/src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java b/src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java index a3e7580..b2bee2a 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java @@ -19,7 +19,6 @@ * MA 02110-1301, USA. * */ - package kellerkinder.HomeFlix.controller; import java.awt.image.BufferedImage; diff --git a/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java b/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java index a21b376..150f3d4 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ - package kellerkinder.HomeFlix.controller; import java.io.BufferedReader; diff --git a/src/main/java/kellerkinder/HomeFlix/datatypes/FilmTabelDataType.java b/src/main/java/kellerkinder/HomeFlix/datatypes/FilmTabelDataType.java index 3bc51b1..c2b86da 100644 --- a/src/main/java/kellerkinder/HomeFlix/datatypes/FilmTabelDataType.java +++ b/src/main/java/kellerkinder/HomeFlix/datatypes/FilmTabelDataType.java @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ - package kellerkinder.HomeFlix.datatypes; import javafx.beans.property.BooleanProperty; @@ -36,7 +35,6 @@ public class FilmTabelDataType { private final BooleanProperty favorite = new SimpleBooleanProperty(); private final BooleanProperty cached = new SimpleBooleanProperty(); private final SimpleObjectProperty image = new SimpleObjectProperty<>(); - /** * tableData is the data-type of tree-table-view diff --git a/src/main/java/kellerkinder/HomeFlix/datatypes/SourceDataType.java b/src/main/java/kellerkinder/HomeFlix/datatypes/SourceDataType.java index aab7fa5..fec991a 100644 --- a/src/main/java/kellerkinder/HomeFlix/datatypes/SourceDataType.java +++ b/src/main/java/kellerkinder/HomeFlix/datatypes/SourceDataType.java @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ - package kellerkinder.HomeFlix.datatypes; import javafx.beans.property.SimpleStringProperty; diff --git a/src/main/java/kellerkinder/HomeFlix/player/Player.java b/src/main/java/kellerkinder/HomeFlix/player/Player.java index 2ee468f..276e144 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/Player.java +++ b/src/main/java/kellerkinder/HomeFlix/player/Player.java @@ -1,6 +1,26 @@ +/** + * Project-HomeFlix + * + * Copyright 2016-2018 <@Seil0> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ package kellerkinder.HomeFlix.player; - import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -19,6 +39,12 @@ public class Player { private AnchorPane pane; private Scene scene; + /** + * generate a new PlayerWindow + * @param file the file you want to play + * @param currentEp the current episode (needed for autoplay) + * @param dbController the dbController object + */ public Player(String file, String currentEp, DBController dbController) { try { FXMLLoader fxmlLoader = new FXMLLoader(ClassLoader.getSystemResource("fxml/PlayerWindow.fxml")); diff --git a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java index 238d561..0c7d47c 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java +++ b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java @@ -1,3 +1,24 @@ +/** + * Project-HomeFlix + * + * Copyright 2016-2018 <@Seil0> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ package kellerkinder.HomeFlix.player; import java.io.File; @@ -69,6 +90,13 @@ public class PlayerController { private ImageView fullscreen_black = new ImageView(new Image("icons/ic_fullscreen_black_24dp_1x.png")); private ImageView fullscreen_exit_black = new ImageView(new Image("icons/ic_fullscreen_exit_black_24dp_1x.png")); + /** + * initialize the new PlayerWindow + * @param file the file you want to play + * @param currentEp the current episode (needed for autoplay) + * @param player the player object (needed for closing action) + * @param dbController the dbController object + */ public void init(String file, String currentEp, Player player, DBController dbController) { this.file = file; this.player = player; @@ -113,7 +141,7 @@ public class PlayerController { if (duration - currentTime < 10000) { if (nextEp != 0) { - dbController.getNextEpisode(file, nextEp); + dbController.getNextEpisode(new File(file).getName(), nextEp); System.out.println("next episode is: " + dbController.getNextEpisode(file, nextEp)); } else { if (duration - currentTime < 100) { @@ -135,6 +163,9 @@ public class PlayerController { fullscreenBtn.setGraphic(fullscreen_exit_black); } + /** + * initialize some PlayerWindow GUI-Elements actions + */ private void initActions() { player.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, new EventHandler() { diff --git a/src/main/java/org/kellerkinder/Alerts/JFX2BtnCancelAlert.java b/src/main/java/org/kellerkinder/Alerts/JFX2BtnCancelAlert.java index 8272b1d..63b8ff2 100644 --- a/src/main/java/org/kellerkinder/Alerts/JFX2BtnCancelAlert.java +++ b/src/main/java/org/kellerkinder/Alerts/JFX2BtnCancelAlert.java @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ - package org.kellerkinder.Alerts; import com.jfoenix.controls.JFXAlert; diff --git a/src/main/java/org/kellerkinder/Alerts/JFXInfoAlert.java b/src/main/java/org/kellerkinder/Alerts/JFXInfoAlert.java index 2375b4d..ab31c4d 100644 --- a/src/main/java/org/kellerkinder/Alerts/JFXInfoAlert.java +++ b/src/main/java/org/kellerkinder/Alerts/JFXInfoAlert.java @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ - package org.kellerkinder.Alerts; import com.jfoenix.controls.JFXAlert;