use try with resourcess
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* rename package kellerkinder.HomeFlix to org.mosad.homeflix
This commit is contained in:
227
src/main/java/org/mosad/homeflix/application/FilmDetailView.java
Normal file
227
src/main/java/org/mosad/homeflix/application/FilmDetailView.java
Normal file
@ -0,0 +1,227 @@
|
||||
/**
|
||||
* Project-HomeFlix
|
||||
*
|
||||
* Copyright 2016-2019 <@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 org.mosad.homeflix.application;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.mosad.homeflix.controller.DBController;
|
||||
import org.mosad.homeflix.controller.XMLController;
|
||||
import org.mosad.homeflix.datatypes.OMDbAPIResponseDataType;
|
||||
import org.mosad.homeflix.player.Player;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Duration;
|
||||
|
||||
public class FilmDetailView {
|
||||
|
||||
@FXML private AnchorPane filmDVPane;
|
||||
|
||||
@FXML private Label lblTitle;
|
||||
@FXML private Label lblYear;
|
||||
@FXML private Label lblScore;
|
||||
|
||||
@FXML private Label lblCrew;
|
||||
@FXML private Label lblDirectors;
|
||||
@FXML private Label lblDirectorsInfo;
|
||||
@FXML private Label lblWriters;
|
||||
@FXML private Label lblWritersInfo;
|
||||
@FXML private Label lblActors;
|
||||
@FXML private Label lblActorsInfo;
|
||||
|
||||
@FXML private Label lblInfo;
|
||||
@FXML private Label lblRuntimeInfo;
|
||||
@FXML private Label lblRuntime;
|
||||
@FXML private Label lblLanguageInfo;
|
||||
@FXML private Label lblLanguage;
|
||||
@FXML private Label lblRevenueInfo;
|
||||
@FXML private Label lblRevenue;
|
||||
@FXML private Label lblRatingInfo;
|
||||
@FXML private Label lblRating;
|
||||
|
||||
@FXML private JFXButton btnWishlist;
|
||||
@FXML private JFXButton btnFavourite;
|
||||
@FXML private JFXButton btnHide;
|
||||
@FXML private JFXButton btnPlay;
|
||||
@FXML private JFXButton btnDirectory;
|
||||
|
||||
@FXML private ImageView wishlistIcon;
|
||||
@FXML private ImageView favoriteIcon;
|
||||
@FXML private ImageView imgPoster;
|
||||
|
||||
@FXML private Text textPlot;
|
||||
|
||||
private DBController dbController;
|
||||
private static final Logger LOGGER = LogManager.getLogger(FilmDetailView.class.getName());
|
||||
private String currentStreamURL;
|
||||
|
||||
public void initialize() {
|
||||
dbController = DBController.getInstance();
|
||||
filmDVPane.setStyle("-fx-background-color: rgba(89,89,89,0.9);");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnWishlistAction() {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnFavouriteAction() {
|
||||
dbController.toggleFavoriteState(currentStreamURL);
|
||||
|
||||
// update the favorite icon
|
||||
if(dbController.getFavoriteState(currentStreamURL) == 1) {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_black_48dp.png"));
|
||||
} else {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_border_black_48dp.png"));
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnHideAction() {
|
||||
hidePane();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnPlayAction() {
|
||||
playFilm();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnDirectoryAction() {
|
||||
File dest = new File(currentStreamURL).getParentFile();
|
||||
|
||||
if (!System.getProperty("os.name").contains("Linux")) {
|
||||
try {
|
||||
Desktop.getDesktop().open(dest);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the cached data of a stream to the FilmDetailView
|
||||
* @param streamURL URL of the stream
|
||||
*/
|
||||
public void setFilm(String streamURL) {
|
||||
currentStreamURL = streamURL;
|
||||
OMDbAPIResponseDataType cacheInfo = dbController.readCache(streamURL); // get the cache data from the database
|
||||
|
||||
// add the cache data to the GUI
|
||||
lblTitle.setText(cacheInfo.getTitle());
|
||||
lblYear.setText("(" + cacheInfo.getYear() + ")");
|
||||
lblScore.setText(XMLController.getLocalBundle().getString("score") + ": " + cacheInfo.getMetascore() + "%");
|
||||
|
||||
textPlot.setText(cacheInfo.getPlot());
|
||||
|
||||
lblDirectors.setText(cacheInfo.getDirector());
|
||||
lblWriters.setText(cacheInfo.getWriter());
|
||||
lblActors.setText(cacheInfo.getActors());
|
||||
|
||||
lblRuntime.setText(cacheInfo.getRuntime());
|
||||
lblLanguage.setText(cacheInfo.getLanguage());
|
||||
lblRevenue.setText(cacheInfo.getBoxOffice());
|
||||
lblRating.setText(cacheInfo.getRated());
|
||||
|
||||
try {
|
||||
if (new File(cacheInfo.getPoster()).isFile()) {
|
||||
imgPoster.setImage(new Image(new File(cacheInfo.getPoster()).toURI().toString()));
|
||||
} else {
|
||||
imgPoster.setImage(new Image(cacheInfo.getPoster()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
imgPoster.setImage(new Image("icons/Homeflix_Poster.png"));
|
||||
LOGGER.error("No Poster found, useing default.");
|
||||
}
|
||||
|
||||
// set the favorite correct icon
|
||||
if(dbController.getFavoriteState(streamURL) == 1) {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_black_48dp.png"));
|
||||
} else {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_border_black_48dp.png"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* update the text of all static GUI elements of FilmDeatilView
|
||||
*/
|
||||
public void updateGUILocal() {
|
||||
lblCrew.setText(XMLController.getLocalBundle().getString("crew"));
|
||||
lblDirectorsInfo.setText(XMLController.getLocalBundle().getString("directors"));
|
||||
lblWritersInfo.setText(XMLController.getLocalBundle().getString("writers"));
|
||||
lblActorsInfo.setText(XMLController.getLocalBundle().getString("actors"));
|
||||
|
||||
lblInfo.setText(XMLController.getLocalBundle().getString("info"));
|
||||
lblRuntimeInfo.setText(XMLController.getLocalBundle().getString("runtime"));
|
||||
lblLanguageInfo.setText(XMLController.getLocalBundle().getString("language"));
|
||||
lblRevenueInfo.setText(XMLController.getLocalBundle().getString("boxOffice"));
|
||||
lblRatingInfo.setText(XMLController.getLocalBundle().getString("rated"));
|
||||
}
|
||||
|
||||
/**
|
||||
* show the FilmDVpane
|
||||
*/
|
||||
public void showPane() {
|
||||
filmDVPane.setVisible(true);
|
||||
FadeTransition fadeIn = new FadeTransition(Duration.millis(300), filmDVPane);
|
||||
fadeIn.setFromValue(0.3);
|
||||
fadeIn.setToValue(1.0);
|
||||
fadeIn.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* hide the FilmDVpane
|
||||
*/
|
||||
private void hidePane() {
|
||||
FadeTransition fadeOut = new FadeTransition(Duration.millis(200), filmDVPane);
|
||||
fadeOut.setFromValue(1.0);
|
||||
fadeOut.setToValue(0.3);
|
||||
fadeOut.play();
|
||||
|
||||
filmDVPane.setVisible(false);
|
||||
|
||||
MainWindowController.getInstance().disableBlur(); // disable blur
|
||||
}
|
||||
|
||||
private void playFilm() {
|
||||
if(new File(currentStreamURL).isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
new Player(currentStreamURL);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.mosad.homeflix.application;
|
||||
|
||||
public class JavaFX11Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Main.main(args);
|
||||
}
|
||||
}
|
124
src/main/java/org/mosad/homeflix/application/Main.java
Normal file
124
src/main/java/org/mosad/homeflix/application/Main.java
Normal file
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Project-HomeFlix
|
||||
*
|
||||
* Copyright 2016-2019 <@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 org.mosad.homeflix.application;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.mosad.homeflix.controller.DBController;
|
||||
import org.mosad.homeflix.controller.XMLController;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
private Scene scene;
|
||||
private AnchorPane pane;
|
||||
private MainWindowController mainWindowController;
|
||||
private static XMLController xmlController;
|
||||
private static Logger LOGGER;
|
||||
public static final String version = "0.8.90";
|
||||
public static final String buildNumber = "175";
|
||||
public static final String versionName = "nimbly xlr8";
|
||||
|
||||
// TODO rename streamURL to mediaURL
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
|
||||
//initialize the mainWindowController and the primaryStage
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setLocation(getClass().getResource("/fxml/MainWindow.fxml"));
|
||||
pane = (AnchorPane) loader.load();
|
||||
primaryStage.setMinHeight(600.00 + 34); // 34 -> window decoration
|
||||
primaryStage.setMinWidth(1130.00);
|
||||
//primaryStage.setResizable(false);
|
||||
primaryStage.setTitle("Project HomeFlix");
|
||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); //adds application icon
|
||||
primaryStage.setOnCloseRequest(event -> {
|
||||
DBController.getInstance().closeDBConnection();
|
||||
System.exit(0);
|
||||
});
|
||||
|
||||
// generate window
|
||||
scene = new Scene(pane); // create new scene, append pane to scene
|
||||
scene.getStylesheets().add(getClass().getResource("/css/MainWindow.css").toExternalForm());
|
||||
primaryStage.setScene(scene); // append scene to stage
|
||||
primaryStage.show(); // show stage
|
||||
|
||||
mainWindowController = loader.getController(); //Link of FXMLController and controller class
|
||||
mainWindowController.init();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error while loading in Main", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
// Logger initialization
|
||||
String logPath = "";
|
||||
|
||||
if (System.getProperty("os.name").contains("Windows")) {
|
||||
logPath = System.getProperty("user.home") + "/Documents/HomeFlix/app.log";
|
||||
} else {
|
||||
logPath = System.getProperty("user.home") + "/HomeFlix/app.log";
|
||||
}
|
||||
|
||||
System.setProperty("logFilename", logPath);
|
||||
File logFile = new File(logPath);
|
||||
logFile.delete();
|
||||
LOGGER = LogManager.getLogger(Main.class.getName());
|
||||
|
||||
LOGGER.info("OS: " + XMLController.getOsName() + " " + XMLController.getOsVers() + " " + XMLController.getOsVers());
|
||||
LOGGER.info("Java: " + XMLController.getJavaVend() + " " + XMLController.getJavaVers());
|
||||
LOGGER.info("User: " + XMLController.getUserName() + " " + XMLController.getUserHome());
|
||||
|
||||
xmlController = new XMLController(); // Initialize the XMLController
|
||||
|
||||
// TODO run Migrations
|
||||
|
||||
if (!XMLController.getConfigFile().exists()) {
|
||||
xmlController.saveSettings(); // save the settings file with default values if it doesn't exist
|
||||
}
|
||||
|
||||
xmlController.loadSettings();
|
||||
|
||||
if (!XMLController.getPosterCache().exists()) {
|
||||
XMLController.getPosterCache().mkdir();
|
||||
}
|
||||
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,443 @@
|
||||
/**
|
||||
* Project-HomeFlix
|
||||
*
|
||||
* Copyright 2016-2019 <@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 org.mosad.homeflix.application;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.math.BigInteger;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kellerkinder.Alerts.JFX2BtnCancelAlert;
|
||||
import org.kellerkinder.Alerts.JFXInfoAlert;
|
||||
import org.mosad.homeflix.controller.DBController;
|
||||
import org.mosad.homeflix.controller.OMDbAPIController;
|
||||
import org.mosad.homeflix.controller.UpdateController;
|
||||
import org.mosad.homeflix.controller.XMLController;
|
||||
import org.mosad.homeflix.datatypes.FilmTabelDataType;
|
||||
import org.mosad.homeflix.datatypes.PosterModeElement;
|
||||
|
||||
import com.eclipsesource.json.Json;
|
||||
import com.eclipsesource.json.JsonArray;
|
||||
import com.eclipsesource.json.JsonObject;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXHamburger;
|
||||
import com.jfoenix.transitions.hamburger.HamburgerBackArrowBasicTransition;
|
||||
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
|
||||
import javafx.scene.effect.BoxBlur;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
|
||||
public class MainWindowController {
|
||||
|
||||
// general
|
||||
@FXML private AnchorPane mainAnchorPane;
|
||||
|
||||
@FXML private HBox topHBox;
|
||||
@FXML private VBox sideMenuVBox;
|
||||
|
||||
@FXML private JFXHamburger menuHam;
|
||||
|
||||
@FXML private JFXButton aboutBtn;
|
||||
@FXML private JFXButton settingsBtn;
|
||||
|
||||
// settings
|
||||
@FXML private SettingsView settingsViewController;
|
||||
|
||||
// poster-mode
|
||||
@FXML private ScrollPane posterModeScrollPane;
|
||||
@FXML private FlowPane posterModeFlowPane;
|
||||
|
||||
@FXML private FilmDetailView filmDetailViewController;
|
||||
@FXML private SeriesDetailView seriesDetailViewController;
|
||||
|
||||
private static MainWindowController instance = null;
|
||||
private DBController dbController;
|
||||
private XMLController xmlController;
|
||||
private Stage primaryStage;
|
||||
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
||||
|
||||
private boolean menuTrue = false;
|
||||
|
||||
private String btnStyle;
|
||||
|
||||
private ObservableList<PosterModeElement> posterEmenents = FXCollections.observableArrayList();
|
||||
private LocalDate lastValidCache = LocalDate.now().minusDays(30); // current date - 30 days is the last valid cache date
|
||||
|
||||
public MainWindowController() {
|
||||
// the constructor
|
||||
}
|
||||
|
||||
public static MainWindowController getInstance() {
|
||||
if (instance == null) {
|
||||
LOGGER.error("There was a fatal error: instance is null!");
|
||||
instance = new MainWindowController();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
instance = this;
|
||||
xmlController = new XMLController();
|
||||
dbController = DBController.getInstance();
|
||||
|
||||
if (!new File(XMLController.getDirHomeFlix() + "/sources.json").exists()) {
|
||||
XMLController.getDirHomeFlix().mkdir();
|
||||
LOGGER.warn("sources file not found");
|
||||
|
||||
addFirstSource();
|
||||
xmlController.saveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
LOGGER.info("Initializing Project-HomeFlix build " + Main.buildNumber);
|
||||
|
||||
// initialize the GUI and the DBController
|
||||
primaryStage = (Stage) mainAnchorPane.getScene().getWindow(); // set primary stage for dialogs
|
||||
posterModeScrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
|
||||
setLocalUI();
|
||||
applyColor(); // TODO only on first start
|
||||
|
||||
initActions();
|
||||
dbController.init();
|
||||
|
||||
// load data list in gui
|
||||
posterModeStartup();
|
||||
|
||||
checkAutoUpdate(); // TODO async
|
||||
}
|
||||
|
||||
// Initializing the actions
|
||||
private void initActions() {
|
||||
|
||||
// general actions
|
||||
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
|
||||
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e) -> {
|
||||
|
||||
if (menuTrue) {
|
||||
sideMenuSlideOut();
|
||||
burgerTask.setRate(-1.0);
|
||||
burgerTask.play();
|
||||
menuTrue = false;
|
||||
} else {
|
||||
sideMenuSlideIn();
|
||||
burgerTask.setRate(1.0);
|
||||
burgerTask.play();
|
||||
menuTrue = true;
|
||||
}
|
||||
|
||||
if (settingsViewController.isVisible()) {
|
||||
settingsViewController.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// general fxml actions
|
||||
@FXML
|
||||
private void aboutBtnAction() {
|
||||
String bodyText = "Project HomeFlix \nVersion: " + Main.version + " (Build: " + Main.buildNumber + ") \""
|
||||
+ Main.versionName + "\" \n" + XMLController.getLocalBundle().getString("infoText");
|
||||
JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, btnStyle, primaryStage);
|
||||
infoAlert.showAndWait();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void settingsBtnclicked() {
|
||||
settingsViewController.setVisible(!settingsViewController.isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 addFirstSource() {
|
||||
JFX2BtnCancelAlert selectFirstSource = new JFX2BtnCancelAlert(
|
||||
XMLController.getLocalBundle().getString("addSourceHeader"),
|
||||
XMLController.getLocalBundle().getString("addSourceBody"),
|
||||
"-fx-button-type: RAISED; -fx-background-color: #ee3523; -fx-text-fill: BLACK;",
|
||||
XMLController.getLocalBundle().getString("addDirectory"),
|
||||
XMLController.getLocalBundle().getString("addStreamSource"),
|
||||
XMLController.getLocalBundle().getString("cancelBtnText"), primaryStage);
|
||||
|
||||
// directory action
|
||||
selectFirstSource.setBtn1Action(e -> {
|
||||
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||
directoryChooser.setTitle(XMLController.getLocalBundle().getString("addDirectory"));
|
||||
File selectedFolder = directoryChooser.showDialog(primaryStage);
|
||||
if (selectedFolder != null && selectedFolder.exists()) {
|
||||
selectFirstSource.getAlert().close();
|
||||
writeSource(selectedFolder.getPath(), "local");
|
||||
settingsViewController.loadInitSources();
|
||||
} else {
|
||||
LOGGER.error("The selected folder dosen't exist!");
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// streaming action
|
||||
selectFirstSource.setBtn2Action(e -> {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle(XMLController.getLocalBundle().getString("addStreamSource"));
|
||||
File selectedFile = fileChooser.showOpenDialog(primaryStage);
|
||||
if (selectedFile != null && selectedFile.exists()) {
|
||||
selectFirstSource.getAlert().close();
|
||||
writeSource(selectedFile.getPath(), "stream");
|
||||
settingsViewController.loadInitSources();
|
||||
} else {
|
||||
LOGGER.error("The selected file dosen't exist!");
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
selectFirstSource.showAndWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* add a source to the sources file
|
||||
*
|
||||
* @param path to the source
|
||||
* @param mode of the source (local or streaming)
|
||||
*/
|
||||
void writeSource(String path, String mode) {
|
||||
JsonArray newsources = null;
|
||||
|
||||
try {
|
||||
// read old array
|
||||
File oldSources = new File(XMLController.getDirHomeFlix() + "/sources.json");
|
||||
newsources = oldSources.exists() ? Json.parse(new FileReader(XMLController.getDirHomeFlix() + "/sources.json")).asArray() : Json.array();
|
||||
|
||||
// add new source
|
||||
JsonObject source = Json.object().add("path", path).add("mode", mode);
|
||||
newsources.add(source);
|
||||
Writer writer = new FileWriter(XMLController.getDirHomeFlix() + "/sources.json");
|
||||
newsources.writeTo(writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error while writing sources file!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the color of the GUI-Elements if usedColor is less than checkColor set
|
||||
* text fill white, else black
|
||||
*/
|
||||
void applyColor() {
|
||||
String menuBtnStyle;
|
||||
BigInteger usedColor = new BigInteger(XMLController.getColor(), 16);
|
||||
BigInteger checkColor = new BigInteger("78909cff", 16);
|
||||
|
||||
menuHam.getStyleClass().clear();
|
||||
|
||||
if (usedColor.compareTo(checkColor) == -1) {
|
||||
btnStyle = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: WHITE;";
|
||||
menuBtnStyle = "-fx-text-fill: WHITE;";
|
||||
menuHam.getStyleClass().add("jfx-hamburgerW");
|
||||
} else {
|
||||
btnStyle = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: BLACK;";
|
||||
menuBtnStyle = "-fx-text-fill: BLACK;";
|
||||
menuHam.getStyleClass().add("jfx-hamburgerB");
|
||||
}
|
||||
|
||||
// boxes and TextFields
|
||||
sideMenuVBox.setStyle("-fx-background-color: #" + XMLController.getColor() + ";");
|
||||
topHBox.setStyle("-fx-background-color: #" + XMLController.getColor() + ";");
|
||||
|
||||
// menu buttons
|
||||
settingsBtn.setStyle(menuBtnStyle);
|
||||
aboutBtn.setStyle(menuBtnStyle);
|
||||
|
||||
settingsViewController.updateColor(btnStyle);
|
||||
}
|
||||
|
||||
// slide in in 400ms
|
||||
private void sideMenuSlideIn() {
|
||||
TranslateTransition translateTransition = new TranslateTransition(Duration.millis(400), sideMenuVBox);
|
||||
translateTransition.setFromX(0);
|
||||
translateTransition.setToX(150);
|
||||
translateTransition.play();
|
||||
}
|
||||
|
||||
// slide out in 400ms
|
||||
private void sideMenuSlideOut() {
|
||||
TranslateTransition translateTransition = new TranslateTransition(Duration.millis(400), sideMenuVBox);
|
||||
translateTransition.setFromX(150);
|
||||
translateTransition.setToX(0);
|
||||
translateTransition.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* set the local based on the languageChoisBox selection
|
||||
*/
|
||||
void setLocalUI() {
|
||||
// TODO switch expressions
|
||||
switch (XMLController.getUsrLocal()) {
|
||||
case "en_US":
|
||||
XMLController.setLocalBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // us_English
|
||||
break;
|
||||
case "de_DE":
|
||||
XMLController.setLocalBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN)); // German
|
||||
break;
|
||||
default:
|
||||
XMLController.setLocalBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // default local
|
||||
break;
|
||||
}
|
||||
|
||||
settingsViewController.updateGUILocal();
|
||||
filmDetailViewController.updateGUILocal();
|
||||
seriesDetailViewController.updateGUILocal();
|
||||
|
||||
aboutBtn.setText(XMLController.getLocalBundle().getString("info"));
|
||||
settingsBtn.setText(XMLController.getLocalBundle().getString("settings"));
|
||||
}
|
||||
|
||||
// if AutoUpdate, then check for updates
|
||||
private void checkAutoUpdate() {
|
||||
LOGGER.info("AutoUpdate: looking for updates on startup ...");
|
||||
|
||||
if (XMLController.isAutoUpdate() && UpdateController.isUpdateAvailable()) {
|
||||
UpdateController.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Poser Mode
|
||||
*/
|
||||
|
||||
private void posterModeStartup() {
|
||||
checkAllPosters();
|
||||
addAllPosters();
|
||||
checkCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if all posters are cached, if not cache the missing ones
|
||||
*/
|
||||
void checkAllPosters() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(5);
|
||||
|
||||
dbController.refreshDataBase(); // refreshes the database after a source path was added
|
||||
|
||||
// get all not cached entries
|
||||
for (FilmTabelDataType entry : dbController.getAllNotCachedEntries()) {
|
||||
Runnable OMDbAPIWorker = new OMDbAPIController(entry);
|
||||
executor.execute(OMDbAPIWorker);
|
||||
}
|
||||
executor.shutdown();
|
||||
|
||||
// TODO show loading screen
|
||||
|
||||
// wait for all OMDbAPI requests to finish
|
||||
try {
|
||||
executor.awaitTermination(1, TimeUnit.MINUTES);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
System.out.println("finished refresh");
|
||||
}
|
||||
|
||||
/**
|
||||
* add all cached films/series to the PosterMode GUI
|
||||
*/
|
||||
void addAllPosters() {
|
||||
// refresh the posterModeElements list
|
||||
posterEmenents.clear();
|
||||
posterEmenents = dbController.getPosterElementsList(); // returns a list of all PosterElements stored in the database
|
||||
|
||||
// add button onAction
|
||||
for (PosterModeElement element : posterEmenents) {
|
||||
element.getButton().addEventHandler(MouseEvent.MOUSE_CLICKED, (event) -> {
|
||||
enableBlur(); // blur the FlowPane
|
||||
|
||||
// if the selected element is a file it's a film, else a series
|
||||
if (new File(element.getStreamURL()).isFile() || element.getStreamURL().contains("http")) {
|
||||
filmDetailViewController.setFilm(element.getStreamURL());
|
||||
filmDetailViewController.showPane();
|
||||
} else {
|
||||
seriesDetailViewController.setSeries(element.getStreamURL());
|
||||
seriesDetailViewController.showPane();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
posterModeFlowPane.getChildren().clear(); // remove all GUIElements from the posterModeFlowPane
|
||||
posterModeFlowPane.getChildren().addAll(posterEmenents); // add all films/series as new GUIElements to the posterModeFlowPane
|
||||
|
||||
System.out.println("added gui elements");
|
||||
}
|
||||
|
||||
// TODO can this be done in dbController? with dbController.refreshDataBase();
|
||||
/**
|
||||
* check if the cache is to old, if so update asynchron
|
||||
*/
|
||||
private void checkCache() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(5);
|
||||
|
||||
for(FilmTabelDataType entry : dbController.getStreamsList()) {
|
||||
if (dbController.getCacheDate(entry.getStreamUrl()).isBefore(lastValidCache)) {
|
||||
// System.out.println(entry.getTitle() + " chached on: " + dbController.getCacheDate(entry.getStreamUrl()));
|
||||
Runnable OMDbAPIWorker = new OMDbAPIController(entry);
|
||||
executor.execute(OMDbAPIWorker);
|
||||
}
|
||||
}
|
||||
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
private void enableBlur() {
|
||||
BoxBlur boxBlur = new BoxBlur();
|
||||
boxBlur.setWidth(9);
|
||||
boxBlur.setHeight(7);
|
||||
boxBlur.setIterations(3);
|
||||
posterModeFlowPane.setEffect(boxBlur);
|
||||
}
|
||||
|
||||
public void disableBlur() {
|
||||
posterModeFlowPane.setEffect(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,240 @@
|
||||
/**
|
||||
* Project-HomeFlix
|
||||
*
|
||||
* Copyright 2016-2019 <@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 org.mosad.homeflix.application;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.mosad.homeflix.controller.DBController;
|
||||
import org.mosad.homeflix.controller.XMLController;
|
||||
import org.mosad.homeflix.datatypes.OMDbAPIResponseDataType;
|
||||
import org.mosad.homeflix.datatypes.SeriresDVEpisode;
|
||||
import org.mosad.homeflix.player.Player;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Duration;
|
||||
|
||||
public class SeriesDetailView {
|
||||
|
||||
@FXML private AnchorPane seriesDVPane;
|
||||
@FXML private ScrollPane scrollPaneEpisodes;
|
||||
|
||||
@FXML private HBox hBoxEpisodes;
|
||||
|
||||
@FXML private Label lblTitle;
|
||||
@FXML private Label lblYear;
|
||||
@FXML private Label lblScore;
|
||||
|
||||
@FXML private Label lblCrew;
|
||||
@FXML private Label lblDirectors;
|
||||
@FXML private Label lblDirectorsInfo;
|
||||
@FXML private Label lblWriters;
|
||||
@FXML private Label lblWritersInfo;
|
||||
@FXML private Label lblActors;
|
||||
@FXML private Label lblActorsInfo;
|
||||
|
||||
@FXML private JFXButton btnWishlist;
|
||||
@FXML private JFXButton btnFavourite;
|
||||
@FXML private JFXButton btnHide;
|
||||
@FXML private JFXButton btnPlay;
|
||||
@FXML private JFXButton btnDirectory;
|
||||
|
||||
@FXML private ImageView wishlistIcon;
|
||||
@FXML private ImageView favoriteIcon;
|
||||
@FXML private ImageView imgPoster;
|
||||
|
||||
@FXML private Text textPlot;
|
||||
|
||||
@FXML private ChoiceBox<String> cbSeason;
|
||||
|
||||
private DBController dbController;
|
||||
private static final Logger LOGGER = LogManager.getLogger(SeriesDetailView.class.getName());
|
||||
private String currentStreamURL;
|
||||
|
||||
public void initialize() {
|
||||
dbController = DBController.getInstance();
|
||||
seriesDVPane.setStyle("-fx-background-color: rgba(89,89,89,0.9);");
|
||||
scrollPaneEpisodes.setStyle("-fx-background-color: transparent;");
|
||||
scrollPaneEpisodes.setHbarPolicy(ScrollBarPolicy.ALWAYS);
|
||||
|
||||
cbSeason.getSelectionModel().selectedIndexProperty().addListener((e, oldValue, newValue) -> {
|
||||
addEpisodes(newValue.intValue() + 1);
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnWishlistAction() {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnFavouriteAction() {
|
||||
dbController.toggleFavoriteState(currentStreamURL);
|
||||
|
||||
// update the favorite icon
|
||||
if(dbController.getFavoriteState(currentStreamURL) == 1) {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_black_48dp.png"));
|
||||
} else {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_border_black_48dp.png"));
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnHideAction() {
|
||||
hidePane();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnPlayAction() {
|
||||
new Player(dbController.getLastWatchedEpisode(currentStreamURL));
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void btnDirectoryAction() {
|
||||
File dest = new File(currentStreamURL).getParentFile();
|
||||
|
||||
if (!System.getProperty("os.name").contains("Linux")) {
|
||||
try {
|
||||
Desktop.getDesktop().open(dest);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set the cached data of a series to the SeriesDetailView
|
||||
* @param streamURL URL of the series root directory
|
||||
*/
|
||||
public void setSeries(String streamURL) {
|
||||
currentStreamURL = streamURL;
|
||||
OMDbAPIResponseDataType cacheInfo = dbController.readCache(streamURL); // get the cache data from the database
|
||||
|
||||
// add the cache data to the GUI
|
||||
lblTitle.setText(cacheInfo.getTitle());
|
||||
lblYear.setText("(" + cacheInfo.getYear() + ")");
|
||||
lblScore.setText(XMLController.getLocalBundle().getString("score") + ": " + cacheInfo.getMetascore() + "%");
|
||||
|
||||
textPlot.setText(cacheInfo.getPlot());
|
||||
|
||||
lblDirectors.setText(cacheInfo.getDirector());
|
||||
lblWriters.setText(cacheInfo.getWriter());
|
||||
lblActors.setText(cacheInfo.getActors());
|
||||
|
||||
try {
|
||||
imgPoster.setImage(new Image(new File(cacheInfo.getPoster()).toURI().toString()));
|
||||
} catch (Exception e) {
|
||||
imgPoster.setImage(new Image("icons/Homeflix_Poster.png"));
|
||||
LOGGER.error("No Poster found, useing default.");
|
||||
}
|
||||
|
||||
// set the favorite correct icon
|
||||
if(dbController.getFavoriteState(streamURL) == 1) {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_black_48dp.png"));
|
||||
} else {
|
||||
favoriteIcon.setImage(new Image("icons/baseline_favorite_border_black_48dp.png"));
|
||||
}
|
||||
|
||||
// add all seasons to the ChoiceBox
|
||||
ObservableList<String> seasons = FXCollections.observableArrayList();
|
||||
for (int i = 1; i <= new File(currentStreamURL).listFiles().length; i++) {
|
||||
seasons.add("Season " + i);
|
||||
}
|
||||
cbSeason.getItems().clear();
|
||||
cbSeason.setItems(seasons);
|
||||
cbSeason.getSelectionModel().select(0);
|
||||
|
||||
// add all episodes for season 1
|
||||
addEpisodes(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* update the text of all static GUI elements of FilmDeatilView
|
||||
*/
|
||||
public void updateGUILocal() {
|
||||
lblCrew.setText(XMLController.getLocalBundle().getString("crew"));
|
||||
lblDirectorsInfo.setText(XMLController.getLocalBundle().getString("directors"));
|
||||
lblWritersInfo.setText(XMLController.getLocalBundle().getString("writers"));
|
||||
lblActorsInfo.setText(XMLController.getLocalBundle().getString("actors"));
|
||||
}
|
||||
|
||||
/**
|
||||
* show the FilmDVpane
|
||||
*/
|
||||
public void showPane() {
|
||||
seriesDVPane.setVisible(true);
|
||||
FadeTransition fadeIn = new FadeTransition(Duration.millis(300), seriesDVPane);
|
||||
fadeIn.setFromValue(0.3);
|
||||
fadeIn.setToValue(1.0);
|
||||
fadeIn.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* hide the FilmDVpane
|
||||
*/
|
||||
private void hidePane() {
|
||||
FadeTransition fadeOut = new FadeTransition(Duration.millis(200), seriesDVPane);
|
||||
fadeOut.setFromValue(1.0);
|
||||
fadeOut.setToValue(0.3);
|
||||
fadeOut.play();
|
||||
|
||||
seriesDVPane.setVisible(false);
|
||||
|
||||
MainWindowController.getInstance().disableBlur(); // disable blur
|
||||
}
|
||||
|
||||
/**
|
||||
* add all episodes of one season to the ScrollPane
|
||||
* @param season the season to add
|
||||
*/
|
||||
private void addEpisodes(int season) {
|
||||
hBoxEpisodes.getChildren().clear();
|
||||
for (String[] episodePoster : dbController.getEpisodes(new File(currentStreamURL).getName(), season)) {
|
||||
Image poster;
|
||||
try {
|
||||
poster = new Image(episodePoster[2].length() > 0 ? new File(episodePoster[2]).toURI().toString() : "icons/Homeflix_Poster.png");
|
||||
} catch (Exception e) {
|
||||
poster = new Image("icons/Homeflix_Poster.png");
|
||||
}
|
||||
hBoxEpisodes.getChildren().add(new SeriresDVEpisode(episodePoster[0], episodePoster[1], poster));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
304
src/main/java/org/mosad/homeflix/application/SettingsView.java
Normal file
304
src/main/java/org/mosad/homeflix/application/SettingsView.java
Normal file
@ -0,0 +1,304 @@
|
||||
/**
|
||||
* Project-HomeFlix
|
||||
*
|
||||
* Copyright 2016-2019 <@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 org.mosad.homeflix.application;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.mosad.homeflix.controller.DBController;
|
||||
import org.mosad.homeflix.controller.UpdateController;
|
||||
import org.mosad.homeflix.controller.XMLController;
|
||||
import org.mosad.homeflix.datatypes.SourceDataType;
|
||||
|
||||
import com.eclipsesource.json.Json;
|
||||
import com.eclipsesource.json.JsonArray;
|
||||
import com.eclipsesource.json.JsonObject;
|
||||
import com.eclipsesource.json.JsonValue;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXColorPicker;
|
||||
import com.jfoenix.controls.JFXSlider;
|
||||
import com.jfoenix.controls.JFXToggleButton;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.FileChooser;
|
||||
|
||||
public class SettingsView {
|
||||
|
||||
@FXML private ScrollPane settingsScrollPane;
|
||||
@FXML private AnchorPane settingsAnchorPane;
|
||||
|
||||
@FXML private Label homeflixSettingsLbl;
|
||||
@FXML private Label mainColorLbl;
|
||||
@FXML private Label fontsizeLbl;
|
||||
@FXML private Label languageLbl;
|
||||
@FXML private Label updateLbl;
|
||||
@FXML private Label branchLbl;
|
||||
@FXML private Label versionLbl;
|
||||
@FXML private Label PlayerLbl;
|
||||
@FXML private Label sourcesLbl;
|
||||
|
||||
@FXML private JFXColorPicker colorPicker;
|
||||
@FXML private JFXSlider fontsizeSlider;
|
||||
|
||||
@FXML private ChoiceBox<String> languageChoisBox;
|
||||
@FXML private ChoiceBox<String> branchChoisBox;
|
||||
|
||||
@FXML private JFXButton updateBtn;
|
||||
@FXML private JFXButton addStreamSourceBtn;
|
||||
@FXML private JFXButton addDirectoryBtn;
|
||||
|
||||
@FXML private JFXToggleButton autoUpdateToggleBtn;
|
||||
@FXML private JFXToggleButton autoplayToggleBtn;
|
||||
|
||||
@FXML private TableView<SourceDataType> sourcesTable;
|
||||
@FXML private TableColumn<SourceDataType, String> sourceColumn;
|
||||
@FXML private TableColumn<SourceDataType, String> modeColumn;
|
||||
|
||||
private XMLController xmlController;
|
||||
private static final Logger LOGGER = LogManager.getLogger(FilmDetailView.class.getName());
|
||||
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
|
||||
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
|
||||
private static ObservableList<SourceDataType> sourcesList = FXCollections.observableArrayList();
|
||||
|
||||
public void initialize() {
|
||||
xmlController = new XMLController();
|
||||
|
||||
// initialize the GUI elements
|
||||
settingsScrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
|
||||
versionLbl.setText("Version: " + Main.version + " (Build: " + Main.buildNumber + ")");
|
||||
fontsizeSlider.setValue(XMLController.getFontSize());
|
||||
colorPicker.setValue(Color.valueOf(XMLController.getColor()));
|
||||
|
||||
autoUpdateToggleBtn.setSelected(XMLController.isAutoUpdate());
|
||||
autoplayToggleBtn.setSelected(XMLController.isAutoplay());
|
||||
languageChoisBox.setItems(languages);
|
||||
branchChoisBox.setItems(branches);
|
||||
|
||||
branchChoisBox.getSelectionModel().select(XMLController.isUseBeta() ? 1 : 0);
|
||||
// TODO switch expressions
|
||||
switch (XMLController.getUsrLocal()) {
|
||||
case "en_US":
|
||||
languageChoisBox.getSelectionModel().select(0);
|
||||
break;
|
||||
case "de_DE":
|
||||
languageChoisBox.getSelectionModel().select(1);
|
||||
break;
|
||||
default:
|
||||
languageChoisBox.getSelectionModel().select(0);
|
||||
break;
|
||||
}
|
||||
|
||||
// initialize the sources table
|
||||
sourceColumn.setCellValueFactory(cellData -> cellData.getValue().pathProperty());
|
||||
modeColumn.setCellValueFactory(cellData -> cellData.getValue().modeProperty());
|
||||
sourcesTable.setItems(sourcesList);
|
||||
|
||||
initActions();
|
||||
loadInitSources();
|
||||
}
|
||||
|
||||
private void initActions() {
|
||||
languageChoisBox.getSelectionModel().selectedIndexProperty().addListener((e, oldValue, newValue) -> {
|
||||
String local = languageChoisBox.getItems().get((int) newValue).toString();
|
||||
local = local.substring(local.length() - 6, local.length() - 1); // reading only en_US from English (en_US)
|
||||
|
||||
XMLController.setUsrLocal(local);
|
||||
xmlController.saveSettings();
|
||||
MainWindowController.getInstance().setLocalUI();
|
||||
});
|
||||
|
||||
branchChoisBox.getSelectionModel().selectedIndexProperty().addListener((e, oldValue, newValue) -> {
|
||||
if (branchChoisBox.getItems().get((int) newValue).toString() == "beta") {
|
||||
XMLController.setUseBeta(true);
|
||||
} else {
|
||||
XMLController.setUseBeta(false);
|
||||
}
|
||||
xmlController.saveSettings();
|
||||
});
|
||||
|
||||
fontsizeSlider.valueProperty().addListener(e -> {
|
||||
XMLController.setFontSize(fontsizeSlider.getValue());
|
||||
xmlController.saveSettings();
|
||||
|
||||
// TODO add functionality for postermode
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addDirectoryBtnAction(ActionEvent event) {
|
||||
DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||
directoryChooser.setTitle(XMLController.getLocalBundle().getString("addDirectory"));
|
||||
File selectedFolder = directoryChooser.showDialog(settingsScrollPane.getScene().getWindow());
|
||||
if (selectedFolder != null && selectedFolder.exists()) {
|
||||
addSource(selectedFolder.getPath(), "local");
|
||||
} else {
|
||||
LOGGER.error("The selected folder dosen't exist!");
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addStreamSourceBtnAction(ActionEvent event) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle(XMLController.getLocalBundle().getString("addStreamSource"));
|
||||
File selectedFile = fileChooser.showOpenDialog(settingsScrollPane.getScene().getWindow());
|
||||
if (selectedFile != null && selectedFile.exists()) {
|
||||
addSource(selectedFile.getPath(), "stream");
|
||||
} else {
|
||||
LOGGER.error("The selected file dosen't exist!");
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void autoUpdateToggleBtnAction(ActionEvent event) {
|
||||
XMLController.setAutoUpdate(!XMLController.isAutoUpdate());
|
||||
xmlController.saveSettings();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void autoplayToggleBtnAction(ActionEvent event) {
|
||||
XMLController.setAutoplay(!XMLController.isAutoplay());
|
||||
xmlController.saveSettings();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void colorPickerAction(ActionEvent event) {
|
||||
XMLController.setColor(colorPicker.getValue().toString().substring(2, 10));
|
||||
xmlController.saveSettings();
|
||||
MainWindowController.getInstance().applyColor();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void updateBtnAction(ActionEvent event) {
|
||||
if (UpdateController.isUpdateAvailable()) {
|
||||
updateBtn.setText(XMLController.getLocalBundle().getString("updateBtnUpdateAvailable"));
|
||||
UpdateController.update();
|
||||
} else {
|
||||
updateBtn.setText(XMLController.getLocalBundle().getString("updateBtnNoUpdateAvailable"));
|
||||
}
|
||||
}
|
||||
|
||||
/** TODO can this be done async?
|
||||
* add a source to the sources file and load all new streams
|
||||
* @param path to the source
|
||||
* @param mode of the source (local or streaming)
|
||||
*/
|
||||
void addSource(String path, String mode) {
|
||||
JsonArray newsources = null;
|
||||
|
||||
try {settingsScrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
|
||||
// read old array
|
||||
File oldSources = new File(XMLController.getDirHomeFlix() + "/sources.json");
|
||||
newsources = oldSources.exists() ? Json.parse(new FileReader(XMLController.getDirHomeFlix() + "/sources.json")).asArray() : Json.array();
|
||||
|
||||
// add new source
|
||||
JsonObject source = Json.object().add("path", path).add("mode", mode);
|
||||
newsources.add(source);
|
||||
Writer writer = new FileWriter(XMLController.getDirHomeFlix() + "/sources.json");
|
||||
newsources.writeTo(writer);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
// update the sourcesTable
|
||||
sourcesList.add(new SourceDataType(path, mode));
|
||||
|
||||
DBController.getInstance().refreshDataBase(); // refreshes the database after a source path was added
|
||||
MainWindowController.getInstance().checkAllPosters(); // check if there is anything new to cache
|
||||
MainWindowController.getInstance().addAllPosters();
|
||||
}
|
||||
|
||||
// add a all elements of sourcesList to the sources table on the settings pane
|
||||
void loadInitSources() {
|
||||
if(new File(XMLController.getDirHomeFlix() + "/sources.json").exists()) {
|
||||
try {
|
||||
// create a JsonArray, containing all sources, add each source to the mwc, get all films from it
|
||||
JsonArray sources = Json.parse(new FileReader(XMLController.getDirHomeFlix() + "/sources.json")).asArray();
|
||||
for (JsonValue source : sources) {
|
||||
String path = source.asObject().getString("path", "");
|
||||
String mode = source.asObject().getString("mode", "");
|
||||
sourcesList.add(new SourceDataType(path, mode));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateColor(String btnStyle) {
|
||||
updateBtn.setStyle(btnStyle);
|
||||
addDirectoryBtn.setStyle(btnStyle);
|
||||
addStreamSourceBtn.setStyle(btnStyle);
|
||||
|
||||
autoUpdateToggleBtn.setToggleColor(Color.valueOf(XMLController.getColor()));
|
||||
autoUpdateToggleBtn.setToggleLineColor(Color.valueOf(XMLController.getColor()));
|
||||
autoplayToggleBtn.setToggleColor(Color.valueOf(XMLController.getColor()));
|
||||
autoplayToggleBtn.setToggleLineColor(Color.valueOf(XMLController.getColor()));
|
||||
}
|
||||
|
||||
public void updateGUILocal() {
|
||||
homeflixSettingsLbl.setText(XMLController.getLocalBundle().getString("homeflixSettingsLbl"));
|
||||
mainColorLbl.setText(XMLController.getLocalBundle().getString("mainColorLbl"));
|
||||
fontsizeLbl.setText(XMLController.getLocalBundle().getString("fontsizeLbl"));
|
||||
languageLbl.setText(XMLController.getLocalBundle().getString("languageLbl"));
|
||||
branchLbl.setText(XMLController.getLocalBundle().getString("branchLbl"));
|
||||
sourcesLbl.setText(XMLController.getLocalBundle().getString("sourcesLbl"));
|
||||
|
||||
updateBtn.setText(XMLController.getLocalBundle().getString("checkUpdates"));
|
||||
addDirectoryBtn.setText(XMLController.getLocalBundle().getString("addDirectory"));
|
||||
addStreamSourceBtn.setText(XMLController.getLocalBundle().getString("addStreamSource"));
|
||||
|
||||
autoUpdateToggleBtn.setText(XMLController.getLocalBundle().getString("autoUpdate"));
|
||||
autoplayToggleBtn.setText(XMLController.getLocalBundle().getString("autoplay"));
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
settingsScrollPane.setVisible(visible);
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return settingsScrollPane.isVisible();
|
||||
}
|
||||
|
||||
public JFXButton getUpdateBtn() {
|
||||
return updateBtn;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user