code cleanup

This commit is contained in:
Jannik 2018-04-28 18:02:02 +02:00
parent 85a403a834
commit 391ef59f70
5 changed files with 101 additions and 147 deletions

View File

@ -80,6 +80,7 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<finalName>Project-HomeFlix</finalName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

View File

@ -40,7 +40,6 @@ import javafx.scene.layout.AnchorPane;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class Main extends Application {
@ -56,8 +55,7 @@ public class Main extends Application {
private static String javaVers = System.getProperty("java.version");
private static String javaVend = System.getProperty("java.vendor");
private static String local = System.getProperty("user.language") + "_" + System.getProperty("user.country");
private String dirWin = userHome + "/Documents/HomeFlix"; // Windows: C:/Users/"User"/Documents/HomeFlix
private String dirLinux = userHome + "/HomeFlix"; // Linux: /home/"User"/HomeFlix
private static String dirHomeFlix;
private File directory;
private File configFile;
private File posterCache;
@ -88,26 +86,14 @@ public class Main extends Application {
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(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
System.exit(1);
}
});
primaryStage.setOnCloseRequest(event -> System.exit(1));
mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.setMain(this); //call setMain
// get OS and the specific paths
if (osName.contains("Windows")) {
directory = new File(dirWin);
configFile = new File(dirWin + "/config.xml");
posterCache = new File(dirWin + "/posterCache");
} else {
directory = new File(dirLinux);
configFile = new File(dirLinux + "/config.xml");
posterCache = new File(dirLinux + "/posterCache");
}
directory = new File(dirHomeFlix);
configFile = new File(dirHomeFlix + "/config.xml");
posterCache = new File(dirHomeFlix + "/posterCache");
// generate window
scene = new Scene(pane); // create new scene, append pane to scene
@ -118,6 +104,7 @@ public class Main extends Application {
// startup checks
if (!configFile.exists()) {
directory.mkdir();
addFirstSource();
mainWindowController.setColor("ee3523");
mainWindowController.setFontSize(17.0);
@ -130,7 +117,7 @@ public class Main extends Application {
posterCache.mkdir();
}
// init here as it loads the games to the mwc and the gui, therefore the window must exist
// initialize here as it loads the games to the mwc and the GUI, therefore the window must exist
mainWindowController.init();
mainWindowController.getDbController().init();
} catch (IOException e) {
@ -148,7 +135,7 @@ public class Main extends Application {
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english
break;
case "de_DE":
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN); // German
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN); // de_german
break;
default:
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // default local
@ -200,20 +187,20 @@ public class Main extends Application {
}
/**
* set the log file location and initialize the logger
* launch the GUI
* 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");
File logFile = new File(userHome + "/Documents/HomeFlix/app.log");
logFile.delete();
if (osName.contains("Windows")) {
dirHomeFlix = userHome + "/Documents/HomeFlix";
} else {
System.setProperty("logFilename", userHome + "/HomeFlix/app.log");
File logFile = new File(userHome + "/HomeFlix/app.log");
logFile.delete();
dirHomeFlix = userHome + "/HomeFlix";
}
System.setProperty("logFilename", dirHomeFlix + "/app.log");
File logFile = new File(dirHomeFlix + "/app.log");
logFile.delete();
LOGGER = LogManager.getLogger(Main.class.getName());
launch(args);
}

View File

@ -201,29 +201,29 @@ public class MainWindowController {
@FXML
private TableColumn<SourceDataType, String> modeColumn;
private Main main;
private MainWindowController mainWindowController;
private UpdateController updateController;
private OMDbAPIController omdbAPIController;
private DBController dbController;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
private boolean menuTrue = false;
private boolean settingsTrue = false;
private boolean autoUpdate = false;
private boolean useBeta = false;
private boolean autoplay = false;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
private int hashA = -647380320;
private final String version = "0.7.0";
private final String buildNumber = "151";
private final String versionName = "toothless dragon";
private String dialogBtnStyle;
private String btnStyle;
private String color;
private String local;
private String omdbAPIKey;
// text strings
private String errorLoad;
private String errorSave;
private String infoText;
private String vlcNotInstalled;
private double fontSize;
private final int hashA = -647380320;
private int last;
private int indexTable;
private int indexList;
@ -247,12 +247,6 @@ public class MainWindowController {
private ContextMenu menu = new ContextMenu(like, dislike);
private Properties props = new Properties();
private Main main;
private MainWindowController mainWindowController;
private UpdateController updateController;
private OMDbAPIController omdbAPIController;
private DBController dbController;
/**
* "Main" Method called in Main.java main() when starting
* Initialize other objects: Updater, dbController and ApiQuery
@ -274,6 +268,28 @@ public class MainWindowController {
initActions();
}
// Initialize UI elements
private void initUI() {
versionLbl.setText("Version: " + version + " (Build: " + buildNumber + ")");
fontsizeSlider.setValue(getFontSize());
colorPicker.setValue(Color.valueOf(getColor()));
updateBtn.setFont(Font.font("System", 12));
autoUpdateToggleBtn.setSelected(isAutoUpdate());
autoplayToggleBtn.setSelected(isAutoplay());
languageChoisBox.setItems(languages);
branchChoisBox.setItems(branches);
if (isUseBeta()) {
branchChoisBox.getSelectionModel().select(1);
} else {
branchChoisBox.getSelectionModel().select(0);
}
setLocalUI();
applyColor();
}
// Initialize the tables (treeTableViewfilm and sourcesTable)
private void initTabel() {
@ -402,7 +418,7 @@ public class MainWindowController {
public void handle(ActionEvent event) {
dbController.like(getCurrentStreamUrl());
dbController.refresh(getCurrentStreamUrl(), indexList);
refreshTable();
refreshTableElement();
}
});
@ -411,7 +427,7 @@ public class MainWindowController {
public void handle(ActionEvent event) {
dbController.dislike(getCurrentStreamUrl());
dbController.refresh(getCurrentStreamUrl(), indexList);
refreshTable();
refreshTableElement();
}
});
@ -479,28 +495,6 @@ public class MainWindowController {
});
}
// initialize UI elements
private void initUI() {
versionLbl.setText("Version: " + version + " (Build: " + buildNumber + ")");
fontsizeSlider.setValue(getFontSize());
colorPicker.setValue(Color.valueOf(getColor()));
updateBtn.setFont(Font.font("System", 12));
autoUpdateToggleBtn.setSelected(isAutoUpdate());
autoplayToggleBtn.setSelected(isAutoplay());
languageChoisBox.setItems(languages);
branchChoisBox.setItems(branches);
if (isUseBeta()) {
branchChoisBox.getSelectionModel().select(1);
} else {
branchChoisBox.getSelectionModel().select(0);
}
setLocalUI();
applyColor();
}
@FXML
private void playbtnclicked() {
if (currentTableFilm.getStreamUrl().contains("_rootNode")) {
@ -528,7 +522,7 @@ public class MainWindowController {
e1.printStackTrace();
}
if (output.contains("which: no vlc") || output == "") {
JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", vlcNotInstalled, dialogBtnStyle, main.getPrimaryStage());
JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", getBundle().getString("vlcNotInstalled"), btnStyle, main.getPrimaryStage());
vlcInfoAlert.showAndWait();
} else {
try {
@ -575,8 +569,8 @@ public class MainWindowController {
@FXML
private void aboutBtnAction() {
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (Build: " + buildNumber + ") \""
+ versionName + "\" \n" + infoText;
JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, dialogBtnStyle, main.getPrimaryStage());
+ versionName + "\" \n" + getBundle().getString("infoText");
JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, btnStyle, main.getPrimaryStage());
infoAlert.showAndWait();
}
@ -634,26 +628,18 @@ public class MainWindowController {
@FXML
private void autoUpdateToggleBtnAction(){
if (isAutoUpdate()) {
setAutoUpdate(false);
} else {
setAutoUpdate(true);
}
autoUpdate = isAutoUpdate() ? false : true;
saveSettings();
}
@FXML
private void autoplayToggleBtnAction(){
if (isAutoplay()) {
setAutoplay(false);
} else {
setAutoplay(true);
}
autoplay = isAutoplay() ? false : true;
saveSettings();
}
// refresh the selected child of the root node
private void refreshTable() {
private void refreshTableElement() {
filmRoot.getChildren().get(indexTable).setValue(filmsList.get(indexList));
}
@ -726,27 +712,15 @@ public class MainWindowController {
* if usedColor is less than checkColor set text fill white, else black
*/
private void applyColor() {
String style = "-fx-background-color: #" + getColor() + ";";
String menuBtnStyle;
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 usedColor = new BigInteger(getColor(), 16);
BigInteger checkColor = new BigInteger("78909cff", 16);
sideMenuVBox.setStyle(style);
topHBox.setStyle(style);
searchTextField.setFocusColor(Color.valueOf(getColor()));
if (usedColor.compareTo(checkColor) == -1) {
dialogBtnStyle = btnStyleWhite;
settingsBtn.setStyle("-fx-text-fill: WHITE;");
aboutBtn.setStyle("-fx-text-fill: WHITE;");
addDirectoryBtn.setStyle(btnStyleWhite);
addStreamSourceBtn.setStyle(btnStyleWhite);
updateBtn.setStyle(btnStyleWhite);
playbtn.setStyle(btnStyleWhite);
openfolderbtn.setStyle(btnStyleWhite);
returnBtn.setStyle(btnStyleWhite);
forwardBtn.setStyle(btnStyleWhite);
btnStyle = btnStyleWhite;
menuBtnStyle = "-fx-text-fill: WHITE;";
playbtn.setGraphic(play_arrow_white);
returnBtn.setGraphic(skip_previous_white);
@ -755,16 +729,8 @@ public class MainWindowController {
menuHam.getStyleClass().clear();
menuHam.getStyleClass().add("jfx-hamburgerW");
} else {
dialogBtnStyle = btnStyleBlack;
settingsBtn.setStyle("-fx-text-fill: BLACK;");
aboutBtn.setStyle("-fx-text-fill: BLACK;");
addDirectoryBtn.setStyle(btnStyleBlack);
addStreamSourceBtn.setStyle(btnStyleBlack);
updateBtn.setStyle(btnStyleBlack);
playbtn.setStyle(btnStyleBlack);
openfolderbtn.setStyle(btnStyleBlack);
returnBtn.setStyle(btnStyleBlack);
forwardBtn.setStyle(btnStyleBlack);
btnStyle = btnStyleBlack;
menuBtnStyle = "-fx-text-fill: BLACK;";
playbtn.setGraphic(play_arrow_black);
returnBtn.setGraphic(skip_previous_black);
@ -773,6 +739,24 @@ public class MainWindowController {
menuHam.getStyleClass().clear();
menuHam.getStyleClass().add("jfx-hamburgerB");
}
// boxes and TextFields
sideMenuVBox.setStyle("-fx-background-color: #" + getColor() + ";");
topHBox.setStyle("-fx-background-color: #" + getColor() + ";");
searchTextField.setFocusColor(Color.valueOf(getColor()));
// normal buttons
addDirectoryBtn.setStyle(btnStyle);
addStreamSourceBtn.setStyle(btnStyle);
updateBtn.setStyle(btnStyle);
playbtn.setStyle(btnStyle);
openfolderbtn.setStyle(btnStyle);
returnBtn.setStyle(btnStyle);
forwardBtn.setStyle(btnStyle);
// menu buttons
settingsBtn.setStyle(menuBtnStyle);
aboutBtn.setStyle(menuBtnStyle);
}
// slide in in 400ms
@ -829,10 +813,6 @@ public class MainWindowController {
columnSeason.setText(getBundle().getString("columnSeason"));
columnEpisode.setText(getBundle().getString("columnEpisode"));
columnFavorite.setText(getBundle().getString("columnFavorite"));
errorLoad = getBundle().getString("errorLoad");
errorSave = getBundle().getString("errorSave");
infoText = getBundle().getString("infoText");
vlcNotInstalled = getBundle().getString("vlcNotInstalled");
}
/**
@ -853,7 +833,7 @@ public class MainWindowController {
props.storeToXML(outputStream, "Project HomeFlix settings"); // write new .xml
outputStream.close();
} catch (IOException e) {
LOGGER.error(errorLoad, e);
LOGGER.error("An error occurred while saving the settings!", e);
}
}
@ -872,7 +852,7 @@ public class MainWindowController {
setColor(props.getProperty("color"));
} catch (Exception e) {
LOGGER.error("cloud not load color", e);
setColor("");
setColor("00a8cc");
}
try {
@ -912,7 +892,7 @@ public class MainWindowController {
inputStream.close();
} catch (IOException e) {
LOGGER.error(errorSave, e);
LOGGER.error("An error occurred while loading the settings!", e);
}
// try loading the omdbAPI key
@ -966,14 +946,14 @@ public class MainWindowController {
return dbController;
}
public void setColor(String input) {
this.color = input;
}
public String getColor() {
return color;
}
public void setColor(String input) {
this.color = input;
}
public FilmTabelDataType getCurrentTableFilm() {
return currentTableFilm;
}
@ -986,14 +966,14 @@ public class MainWindowController {
return currentTableFilm.getStreamUrl();
}
public void setFontSize(Double input) {
this.fontSize = input;
}
public Double getFontSize() {
return fontSize;
}
public void setFontSize(Double input) {
this.fontSize = input;
}
public int getIndexTable() {
return indexTable;
}
@ -1002,14 +982,14 @@ public class MainWindowController {
return indexList;
}
public void setAutoUpdate(boolean input) {
this.autoUpdate = input;
}
public boolean isAutoUpdate() {
return autoUpdate;
}
public void setAutoUpdate(boolean input) {
this.autoUpdate = input;
}
public boolean isUseBeta() {
return useBeta;
}
@ -1026,14 +1006,14 @@ public class MainWindowController {
this.autoplay = autoplay;
}
public void setLocal(String input) {
this.local = input;
}
public String getLocal() {
return local;
}
public void setLocal(String input) {
this.local = input;
}
public String getOmdbAPIKey() {
return omdbAPIKey;
}

View File

@ -31,13 +31,6 @@ columnEpisode = Episode
columnFavorite = Favorit
#error translations
errorUpdateV = Beim ausf\u00FChren des Updates ist ein Fehler aufgetreten! \nError: could not check update version (nvc)\nWeitere Hilfe erhalten sie unter www.kellerkinder.xyz \noder wenden sie sich an support@kellerkinder.xyz
errorUpdateD = Beim ausf\u00FChren des Updates ist ein Fehler aufgetreten! \nError: could not download update files (ndf)\nWeitere Hilfe erhalten sie unter www.kellerkinder.xyz \noder wenden sie sich an support@kellerkinder.xyz
errorMode = Oh, da lief etwas falsch! Da hat jemand einen falschen Modus verwendet. \nError: mode unknow (muk)\nWeitere Hilfe erhalten sie unter www.kellerkinder.xyz \noder wenden sie sich an support@kellerkinder.xyz
errorOpenStream = Beim \u00F6ffnen des Streams ist ein Fehler aufgetreten!
errorLoad = Beim laden der Einstellungen ist ein Fehler aufgetreten!
errorSave = Beim speichern der Einstellungen ist ein Fehler aufgetreten!
noFilmFound = Kein Film mit diesem Titel gefunden!
vlcNotInstalled = Um einen Film abspielen wird der VLC Media Player ben\u00F6tigt!
infoText = \nAutoren: \n \u2022 seil0@kellerkinder.xyz \n \u2022 hendrik.schutter@coptersicht.de \n(c) 2016-2018 Kellerkinder www.kellerkinder.xyz

View File

@ -31,13 +31,6 @@ columnEpisode = Episode
columnFavorite = Favorite
#error translations
errorUpdateV = An error has occurred during update! \nError: could not check update version (nvc) \nTo get help, visit www.kellerkinder.xyz \nor contcat support@kellerkinder.xyz
errorUpdateD = An error has occurred during update! \nError: could not download update files (ndf) \nTo get help, visit www.kellerkinder.xyz \nor contcat support@kellerkinder.xyz
errorMode = Oh, something went wrong! It seems someone has used a wrong mode. \nError: mode unknow (muk) \nTo get help, visit www.kellerkinder.xyz \nor contcat support@kellerkinder.xyz
errorOpenStream = An error has occurred during opening the stream!
errorLoad = An error occurred while loading the settings!
errorSave = An error occurred while saving the settings!
noFilmFound = No film with this title found!
vlcNotInstalled = VLC Media Player is required to play a movie!
infoText = \nMaintainers: \n \u2022 seil0@kellerkinder.xyz \n \u2022 hendrik.schutter@coptersicht.de \n(c) 2016-2018 Kellerkinder www.kellerkinder.xyz