code cleanup and general improvements

This commit is contained in:
Seil0 2017-02-09 20:39:43 +01:00
parent 9316bd9982
commit 03debb4180
17 changed files with 159 additions and 213 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -45,3 +45,5 @@ awards = Auszeichnungen
metascore = Metascore metascore = Metascore
imdbRating = IMDB-Bewertung imdbRating = IMDB-Bewertung
type = Type type = Type
firstStartHeader = Es ist kein Stammverzeichnis f\u00FCr Filme angegeben!
firstStartContent = Stammverzeichniss angeben?

View File

@ -45,3 +45,5 @@ awards = Awards
metascore = Metascore metascore = Metascore
imdbRating = IMDB-Rating imdbRating = IMDB-Rating
type = Type type = Type
firstStartHeader = There is no root directory for movies!
firstStartContent = Specify a root directory?

View File

@ -223,9 +223,9 @@ public class DBController {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local"); ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
while (rs.next()) { while (rs.next()) {
if(rs.getString(4).equals("favorite_black")){ if(rs.getString(4).equals("favorite_black")){
mainWindowController.newDaten.add( new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black))); mainWindowController.newData.add( new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black)));
}else{ }else{
mainWindowController.newDaten.add( new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black))); mainWindowController.newData.add( new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black)));
} }
} }
stmt.close(); stmt.close();
@ -259,9 +259,9 @@ public class DBController {
stmt = connection.createStatement(); stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = '"+name+"';" ); ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = '"+name+"';" );
if(rs.getString(4).equals("favorite_black")){ if(rs.getString(4).equals("favorite_black")){
mainWindowController.newDaten.set(i, new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black))); mainWindowController.newData.set(i, new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black)));
}else{ }else{
mainWindowController.newDaten.set(i, new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black))); mainWindowController.newData.set(i, new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black)));
} }
stmt.close(); stmt.close();
rs.close(); rs.close();
@ -359,7 +359,7 @@ public class DBController {
} }
void ausgeben(){ void ausgeben(){
System.out.println("Eintr<EFBFBD>ge ausgeben ... \n"); System.out.println("Eintraege ausgeben ... \n");
try { try {
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local"); ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
@ -461,7 +461,7 @@ public class DBController {
} }
} }
//entfernt die Endung //removes the ending
private String cutOffEnd (String str) { private String cutOffEnd (String str) {
if (str == null) return null; if (str == null) return null;

View File

@ -1,7 +1,7 @@
/** /**
* Project HomeFlix * Project HomeFlix
* *
* Copyright 2016 <admin@kellerkinder> * Copyright 2016-2017 <admin@kellerkinder>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -22,9 +22,7 @@
package application; package application;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import java.util.Properties; import java.util.Properties;
@ -38,7 +36,6 @@ import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.DirectoryChooser; import javafx.stage.DirectoryChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -46,21 +43,20 @@ public class Main extends Application {
public Stage primaryStage; public Stage primaryStage;
private String path; private String path;
private InputStream inputStream;
private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix"; private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix";
private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix"; private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix";
private String color = "ee3523"; private String color = "ee3523";
private String autoUpdate = "0"; private String autoUpdate = "0";
private String mode = "local"; //local or streaming private String mode = "local"; //local or streaming
private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country");
private double size = 12; private double size = 12;
private int local = 0;
private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); //Windows: C:/Users/"User"/Documents/HomeFlix
private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix");
private File fileWin = new File(dirWin + "/config.xml"); //Windows: C:/Users/"User"/Documents/HomeFlix/config.xml
private File fileLinux = new File(dirLinux + "/config.xml");
Properties props = new Properties();
private ResourceBundle bundle; private ResourceBundle bundle;
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); //Windows: C:/Users/"User"/Documents/HomeFlix
private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix"); //Linux: /home/"User"/HomeFlix
private File fileWin = new File(dirWin + "/config.xml"); //Windows: C:/Users/"User"/Documents/HomeFlix/config.xml
private File fileLinux = new File(dirLinux + "/config.xml"); //Linux: /home/"User"/HomeFlix/config.xml
Properties props = new Properties();
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
@ -80,78 +76,50 @@ public class Main extends Application {
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon
mainWindowController = loader.getController(); //Link of FXMLController and controller class mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.setAutoUpdate(autoUpdate); //set autoupdate mainWindowController.setAutoUpdate(autoUpdate); //set auto-update
mainWindowController.setMain(this); //call setMain mainWindowController.setMain(this); //call setMain
//dir exists -> check config.xml //Linux if directory exists -> check config.xml
if(System.getProperty("os.name").equals("Linux")){ if(System.getProperty("os.name").equals("Linux")){
if(dirLinux.exists() == true){ if(dirLinux.exists() != true){
if (fileLinux.exists() != true) { dirLinux.mkdir();
mainWindowController.setPath(firstStart()); }else if(fileLinux.exists() != true){
if(System.getProperty("os.name").equals("Linux")){ mainWindowController.setPath(firstStart());
mainWindowController.setStreamingPath(streamingPathLinux); mainWindowController.setStreamingPath(streamingPathLinux);
}else{ mainWindowController.setColor(color);
mainWindowController.setStreamingPath(streamingPathWin); mainWindowController.setSize(size);
} mainWindowController.setAutoUpdate(autoUpdate);
mainWindowController.setColor(color); mainWindowController.setLocal(local);
mainWindowController.setSize(size); mainWindowController.setMode(mode);
mainWindowController.setAutoUpdate(autoUpdate); mainWindowController.saveSettings("l");
mainWindowController.setLoaclUI(local); Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
mainWindowController.setMode(mode); System.exit(0); //finishes itself
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
}else{
loadSettings();
}
}else{
dirLinux.mkdir();
mainWindowController.setPath(firstStart());
mainWindowController.setStreamingPath(streamingPathLinux);
mainWindowController.setColor(color);
mainWindowController.setSize(size);
mainWindowController.setAutoUpdate(autoUpdate);
mainWindowController.setLoaclUI(local);
mainWindowController.setMode(mode);
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
} }
//windows
}else{ }else{
if(dirWin.exists() == true){ if(dirWin.exists() != true){
if (fileWin.exists() != true) { dirWin.mkdir();
mainWindowController.setPath(firstStart()); }else if(fileWin.exists() != true){
mainWindowController.setStreamingPath(streamingPathWin); mainWindowController.setPath(firstStart());
mainWindowController.setColor(color); mainWindowController.setStreamingPath(streamingPathWin);
mainWindowController.setSize(size); mainWindowController.setColor(color);
mainWindowController.setAutoUpdate(autoUpdate); mainWindowController.setSize(size);
mainWindowController.setLoaclUI(local); mainWindowController.setAutoUpdate(autoUpdate);
mainWindowController.setMode(mode); mainWindowController.setLocal(local);
mainWindowController.saveSettings(); mainWindowController.setMode(mode);
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs) mainWindowController.saveSettings("k");
System.exit(0); //finishes itself Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
}else{ System.exit(0); //finishes itself
loadSettings(); }
}
}else{
dirWin.mkdir();
mainWindowController.setPath(firstStart());
mainWindowController.setStreamingPath(streamingPathWin);
mainWindowController.setColor(color);
mainWindowController.setSize(size);
mainWindowController.setAutoUpdate(autoUpdate);
mainWindowController.setLoaclUI(local);
mainWindowController.setMode(mode);
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
}
} }
mainWindowController.loadSettings();
mainWindowController.loadStreamingSettings(); mainWindowController.loadStreamingSettings();
mainWindowController.initUI();
mainWindowController.initActions();
mainWindowController.initTabel();
mainWindowController.setLocalUI();
mainWindowController.applyColor(); //set theme color mainWindowController.applyColor(); //set theme color
mainWindowController.cbLocal.getSelectionModel().select(mainWindowController.getLocal()); //set local
mainWindowController.mainColor.setValue(Color.valueOf(mainWindowController.getColor()));
mainWindowController.dbController.main(); //initialize database controller mainWindowController.dbController.main(); //initialize database controller
mainWindowController.dbController.createDatabase(); //creating the database mainWindowController.dbController.createDatabase(); //creating the database
@ -165,12 +133,11 @@ public class Main extends Application {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println(System.getProperty("user.language")+"_"+System.getProperty("user.country"));
} }
//Method for first Start //Method for first Start
private String firstStart(){ private String firstStart(){
System.out.println(System.getProperty("user.language")+"_"+System.getProperty("user.country")); MainWindowController.firststart = true;
switch(System.getProperty("user.language")+"_"+System.getProperty("user.country")){ switch(System.getProperty("user.language")+"_"+System.getProperty("user.country")){
case "en_US": bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.US); //us_english case "en_US": bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.US); //us_english
break; break;
@ -197,34 +164,7 @@ public class Main extends Application {
} }
return path; return path;
} }
//lädt die einstellungen aus der XML
public void loadSettings(){
try {
if(System.getProperty("os.name").equals("Linux")){
inputStream = new FileInputStream(fileLinux);
}else{
inputStream = new FileInputStream(fileWin);
}
props.loadFromXML(inputStream);
path = props.getProperty("path"); //setzt Propselement in Pfad
if(System.getProperty("os.name").equals("Linux")){
streamingPathLinux = props.getProperty("streamingPath");
}else{
streamingPathWin = props.getProperty("streamingPath");
}
color = props.getProperty("color");
size = Double.parseDouble(props.getProperty("size"));
autoUpdate = props.getProperty("autoUpdate");
local = Integer.parseInt(props.getProperty("local"));
mode = props.getProperty("mode");
inputStream.close();
} catch (IOException e) {
System.out.println("An error has occurred!");
e.printStackTrace();
}
}
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }

View File

@ -1,7 +1,7 @@
/** /**
* Project HomeFlix * Project HomeFlix
* *
* Copyright 2016 <admin@kellerkinder> * Copyright 2016-2017 <admin@kellerkinder>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -85,6 +85,8 @@ import javafx.stage.DirectoryChooser;
import javafx.util.Duration; import javafx.util.Duration;
public class MainWindowController { public class MainWindowController {
private ObservableList<String> locals = FXCollections.observableArrayList("english (en_US)", "deutsch (de_DE)");
@FXML @FXML
private AnchorPane anpane; private AnchorPane anpane;
@FXML @FXML
@ -138,7 +140,7 @@ public class MainWindowController {
@FXML @FXML
public JFXColorPicker mainColor; public JFXColorPicker mainColor;
@FXML @FXML
public ChoiceBox<String> cbLocal; public ChoiceBox<String> cbLocal = new ChoiceBox<>(locals);
@FXML @FXML
public JFXSlider sliderFontSize; public JFXSlider sliderFontSize;
@FXML @FXML
@ -182,9 +184,10 @@ public class MainWindowController {
private boolean menutrue = false; //saves the position of menubtn (opened or closed) private boolean menutrue = false; //saves the position of menubtn (opened or closed)
private boolean settingstrue = false; private boolean settingstrue = false;
private boolean streamingSettingsTrue = false; private boolean streamingSettingsTrue = false;
static boolean firststart = false;
private int hashA = -2055934614; private int hashA = -2055934614;
private String version = "0.4.99"; private String version = "0.4.99";
private String buildNumber = "112"; private String buildNumber = "114";
private String versionName = "plasma cow (pre Release)"; private String versionName = "plasma cow (pre Release)";
private String buildURL = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/buildNumber.txt"; private String buildURL = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/buildNumber.txt";
private String downloadLink = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/downloadLink.txt"; private String downloadLink = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/downloadLink.txt";
@ -198,7 +201,6 @@ public class MainWindowController {
private String errorPlay; private String errorPlay;
private String errorOpenStream; private String errorOpenStream;
private String errorMode; private String errorMode;
@SuppressWarnings("unused")
private String errorLoad; private String errorLoad;
private String errorSave; private String errorSave;
String noFilmFound; String noFilmFound;
@ -215,6 +217,7 @@ public class MainWindowController {
private String mode; private String mode;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private String ratingSortType; private String ratingSortType;
private String local;
String title; String title;
String year; String year;
String rating; String rating;
@ -235,14 +238,12 @@ public class MainWindowController {
private int last; private int last;
private int selected; private int selected;
private int next; private int next;
private int local;
private File selectedFolder; private File selectedFolder;
private File selectedStreamingFolder; private File selectedStreamingFolder;
ResourceBundle bundle; ResourceBundle bundle;
private ObservableList<streamUiData> filterData = FXCollections.observableArrayList(); private ObservableList<streamUiData> filterData = FXCollections.observableArrayList();
private ObservableList<String> locals = FXCollections.observableArrayList("english", "deutsch"); ObservableList<streamUiData> newData = FXCollections.observableArrayList();
ObservableList<streamUiData> newDaten = FXCollections.observableArrayList();
ObservableList<streamUiData> streamData = FXCollections.observableArrayList(); ObservableList<streamUiData> streamData = FXCollections.observableArrayList();
ObservableList<streamUiData> streamingData = FXCollections.observableArrayList(); ObservableList<streamUiData> streamingData = FXCollections.observableArrayList();
private ImageView menu_icon_black = new ImageView(new Image("recources/icons/menu_icon_black.png")); private ImageView menu_icon_black = new ImageView(new Image("recources/icons/menu_icon_black.png"));
@ -254,9 +255,9 @@ public class MainWindowController {
private ImageView play_arrow_white = new ImageView(new Image("recources/icons/ic_play_arrow_white_18dp_1x.png")); private ImageView play_arrow_white = new ImageView(new Image("recources/icons/ic_play_arrow_white_18dp_1x.png"));
private ImageView play_arrow_black = new ImageView(new Image("recources/icons/ic_play_arrow_black_18dp_1x.png")); private ImageView play_arrow_black = new ImageView(new Image("recources/icons/ic_play_arrow_black_18dp_1x.png"));
private DirectoryChooser directoryChooser = new DirectoryChooser(); private DirectoryChooser directoryChooser = new DirectoryChooser();
private ContextMenu menu = new ContextMenu();
private MenuItem like = new MenuItem("like"); private MenuItem like = new MenuItem("like");
private MenuItem dislike = new MenuItem("dislike"); //TODO one option (like or dislike) private MenuItem dislike = new MenuItem("dislike"); //TODO one option (like or dislike)
private ContextMenu menu = new ContextMenu(like, dislike);
Properties props = new Properties(); Properties props = new Properties();
private updater Updater; private updater Updater;
@ -278,7 +279,7 @@ public class MainWindowController {
if(settingstrue == true){ if(settingstrue == true){
settingsAnchor.setVisible(false); settingsAnchor.setVisible(false);
setPath(tfPath.getText()); setPath(tfPath.getText());
saveSettings(); saveSettings("a");
settingstrue = false; settingstrue = false;
} }
if(streamingSettingsTrue == true){ if(streamingSettingsTrue == true){
@ -334,7 +335,7 @@ public class MainWindowController {
} }
}else if(mode.equals("streaming")){ }else if(mode.equals("streaming")){
try { try {
Desktop.getDesktop().browse(new URI(datPath)); //opens the streaming url in browser (TODO other option?) Desktop.getDesktop().browse(new URI(datPath)); //open the streaming Url in browser (TODO other option?)
} catch (URISyntaxException | IOException e) { } catch (URISyntaxException | IOException e) {
showErrorMsg(errorOpenStream, (IOException) e); showErrorMsg(errorOpenStream, (IOException) e);
} }
@ -386,7 +387,7 @@ public class MainWindowController {
}else{ }else{
settingsAnchor.setVisible(false); settingsAnchor.setVisible(false);
setPath(tfPath.getText()); setPath(tfPath.getText());
saveSettings(); saveSettings("b");
settingstrue = false; settingstrue = false;
} }
} }
@ -418,7 +419,7 @@ public class MainWindowController {
setMode("local"); setMode("local");
switchBtn.setText("streaming"); switchBtn.setText("streaming");
} }
saveSettings(); saveSettings("c");
root.getChildren().remove(0,root.getChildren().size()); root.getChildren().remove(0,root.getChildren().size());
addDataUI(); addDataUI();
settingsAnchor.setVisible(false); settingsAnchor.setVisible(false);
@ -438,7 +439,7 @@ public class MainWindowController {
@FXML @FXML
private void tfPathAction(){ private void tfPathAction(){
setPath(tfPath.getText()); setPath(tfPath.getText());
saveSettings(); saveSettings("d");
} }
@FXML @FXML
@ -448,7 +449,7 @@ public class MainWindowController {
System.out.println("No Directory selected"); System.out.println("No Directory selected");
}else{ }else{
setPath(selectedFolder.getAbsolutePath()); setPath(selectedFolder.getAbsolutePath());
saveSettings(); saveSettings("e");
tfPath.setText(getPath()); tfPath.setText(getPath());
try { try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
@ -478,7 +479,7 @@ public class MainWindowController {
}else{ }else{
setAutoUpdate("0"); setAutoUpdate("0");
} }
saveSettings(); saveSettings("f");
} }
@FXML @FXML
@ -493,7 +494,7 @@ public class MainWindowController {
System.out.println("No Directory selected"); System.out.println("No Directory selected");
}else{ }else{
setStreamingPath(selectedStreamingFolder.getAbsolutePath()); setStreamingPath(selectedStreamingFolder.getAbsolutePath());
saveSettings(); saveSettings("g");
tfStreamingPath.setText(getStreamingPath()); tfStreamingPath.setText(getStreamingPath());
try { try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
@ -506,54 +507,18 @@ public class MainWindowController {
} }
//"Main" Method called in Main.java main() when starting, initialize some UI elements //"Main" Method called in Main.java main() when starting
public void setMain(Main main) { public void setMain(Main main) {
Updater = new updater(this); Updater = new updater(this);
ApiQuery = new apiQuery(this); ApiQuery = new apiQuery(this);
dbController = new DBController(this); dbController = new DBController(this);
loadSettings();
initTabel();
initActions();
System.out.println("Mode: "+mode); //TODO debugging
//TODO implement sort for rating and alphabetical sort for name after new title was added
// if(ratingSortType == "DESCENDING"){
// columnRating.setSortType(TreeTableColumn.SortType.DESCENDING);
// }else{
// columnRating.setSortType(TreeTableColumn.SortType.ASCENDING);
// }
debugBtn.setDisable(true); //debugging btn for tests
debugBtn.setVisible(false);
tfPath.setText(getPath());
sliderFontSize.setValue(getSize());
cbLocal.setItems(locals);
menu.getItems().addAll(like,dislike);
updateBtn.setFont(Font.font("System", 12));
if(autoUpdate.equals("1")){
autoupdateBtn.setSelected(true);
Updater.update(buildURL, downloadLink, aktBuildNumber, buildNumber);
}else{
autoupdateBtn.setSelected(false);
}
ta1.setWrapText(true);
ta1.setEditable(false);
ta1.setFont(Font.font("System", getSize()));
} }
//Initialize the tables (treeTableViewfilm and tableViewStreamingdata) //Initialize the tables (treeTableViewfilm and tableViewStreamingdata)
@SuppressWarnings({ "unchecked"}) @SuppressWarnings({ "unchecked"}) //TODO
private void initTabel(){ void initTabel(){
//filmtabelle //film Table
columnRating.setMaxWidth(80); columnRating.setMaxWidth(80);
columnTitel.setMaxWidth(260); columnTitel.setMaxWidth(260);
columnStreamUrl.setMaxWidth(0); columnStreamUrl.setMaxWidth(0);
@ -577,7 +542,7 @@ public class MainWindowController {
treeTableViewfilm.getColumns().addAll(columnTitel, columnRating, columnStreamUrl, columnResolution, columnYear, columnSeason, columnEpisode); treeTableViewfilm.getColumns().addAll(columnTitel, columnRating, columnStreamUrl, columnResolution, columnYear, columnSeason, columnEpisode);
treeTableViewfilm.getColumns().get(2).setVisible(false); //hide columnStreamUrl (column with file path important for the player) treeTableViewfilm.getColumns().get(2).setVisible(false); //hide columnStreamUrl (column with file path important for the player)
//Changelistener for TreeTable //Change-listener for TreeTable
treeTableViewfilm.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() { treeTableViewfilm.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {
@Override @Override
public void changed(ObservableValue<?> observable, Object oldVal, Object newVal) { public void changed(ObservableValue<?> observable, Object oldVal, Object newVal) {
@ -596,34 +561,33 @@ public class MainWindowController {
//context menu for treetableview //context menu for treetableview
treeTableViewfilm.setContextMenu(menu); treeTableViewfilm.setContextMenu(menu);
//Streaming-Settings Tabelle //Streaming-Settings Table
dataNameColumn.setCellValueFactory(cellData -> cellData.getValue().titelProperty()); dataNameColumn.setCellValueFactory(cellData -> cellData.getValue().titelProperty());
dataNameEndColumn.setCellValueFactory(cellData -> cellData.getValue().streamUrlProperty()); dataNameEndColumn.setCellValueFactory(cellData -> cellData.getValue().streamUrlProperty());
tableViewStreamingdata.getColumns().addAll(dataNameColumn, dataNameEndColumn); tableViewStreamingdata.getColumns().addAll(dataNameColumn, dataNameEndColumn);
tableViewStreamingdata.setItems(streamingData); tableViewStreamingdata.setItems(streamingData);
} }
//Initializing the actions //Initializing the actions
@SuppressWarnings("unchecked") void initActions(){
private void initActions(){
//TODO unterscheiden zwischen streaming und local //TODO unterscheiden zwischen streaming und local
tfsearch.textProperty().addListener(new ChangeListener<String>() { tfsearch.textProperty().addListener(new ChangeListener<String>() {
@Override @Override
public void changed(ObservableValue<? extends String> observable,String oldValue, String newValue) { public void changed(ObservableValue<? extends String> observable,String oldValue, String newValue) {
int counter = newDaten.size(); int counter = newData.size();
filterData.removeAll(filterData); filterData.removeAll(filterData);
root.getChildren().remove(0,root.getChildren().size()); root.getChildren().remove(0,root.getChildren().size());
for(int i = 0; i < counter; i++){ for(int i = 0; i < counter; i++){
if(newDaten.get(i).getTitel().toLowerCase().contains(tfsearch.getText().toLowerCase())){ if(newData.get(i).getTitel().toLowerCase().contains(tfsearch.getText().toLowerCase())){
filterData.add(newDaten.get(i)); filterData.add(newData.get(i)); //add data from newDaten to filteredData where title contains search input
} }
} }
for(int i = 0; i < filterData.size(); i++){ for(int i = 0; i < filterData.size(); i++){
root.getChildren().addAll(new TreeItem<streamUiData>(filterData.get(i))); //fügt daten zur Rootnode hinzu root.getChildren().add(new TreeItem<streamUiData>(filterData.get(i))); //add filtered data to root node after search
} }
if(tfsearch.getText().hashCode() == hashA){ if(tfsearch.getText().hashCode() == hashA){
setColor("000000"); setColor("000000");
@ -632,12 +596,13 @@ public class MainWindowController {
} }
}); });
cbLocal.getSelectionModel().selectedIndexProperty() cbLocal.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
.addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) { String local = cbLocal.getItems().get((int) new_value).toString();
setLocal(new_value.intValue()); local = local.substring(local.length()-6,local.length()-1);
setLoaclUI(local); setLocal(local);
saveSettings(); setLocalUI();
saveSettings("h");
} }
}); });
@ -646,7 +611,7 @@ public class MainWindowController {
public void changed(ObservableValue<? extends Number> ov,Number old_val, Number new_val) { public void changed(ObservableValue<? extends Number> ov,Number old_val, Number new_val) {
setSize(sliderFontSize.getValue()); setSize(sliderFontSize.getValue());
ta1.setFont(Font.font("System", size)); ta1.setFont(Font.font("System", size));
saveSettings(); saveSettings("i");
} }
}); });
@ -656,7 +621,7 @@ public class MainWindowController {
if(mode.equals("streaming")){ if(mode.equals("streaming")){
dbController.like(Name,streamData.get(selected).getStreamUrl()); dbController.like(Name,streamData.get(selected).getStreamUrl());
}else{ }else{
dbController.like(Name,newDaten.get(selected).getStreamUrl()); dbController.like(Name,newData.get(selected).getStreamUrl());
} }
dbController.getFavStatus(Name); dbController.getFavStatus(Name);
try { try {
@ -678,7 +643,7 @@ public class MainWindowController {
if(mode.equals("streaming")){ if(mode.equals("streaming")){
dbController.dislike(Name,streamData.get(selected).getStreamUrl()); dbController.dislike(Name,streamData.get(selected).getStreamUrl());
}else{ }else{
dbController.dislike(Name,newDaten.get(selected).getStreamUrl()); dbController.dislike(Name,newData.get(selected).getStreamUrl());
} }
dbController.getFavStatus(Name); dbController.getFavStatus(Name);
try { try {
@ -695,9 +660,34 @@ public class MainWindowController {
}); });
} }
//initialize UI elements
void initUI(){
System.out.println("Mode: "+mode); //TODO debugging
debugBtn.setDisable(true); //debugging button for tests
debugBtn.setVisible(false);
tfPath.setText(getPath());
sliderFontSize.setValue(getSize());
mainColor.setValue(Color.valueOf(getColor()));
updateBtn.setFont(Font.font("System", 12));
//TODO rework!
if(autoUpdate.equals("1")){
autoupdateBtn.setSelected(true);
Updater.update(buildURL, downloadLink, aktBuildNumber, buildNumber);
}else{
autoupdateBtn.setSelected(false);
}
ta1.setWrapText(true);
ta1.setEditable(false);
ta1.setFont(Font.font("System", getSize()));
}
private void refreshTable(){ private void refreshTable(){
if(mode.equals("local")){ if(mode.equals("local")){
root.getChildren().set(selected, new TreeItem<streamUiData>(newDaten.get(selected))); root.getChildren().set(selected, new TreeItem<streamUiData>(newData.get(selected)));
}else if(mode.equals("streaming")){ }else if(mode.equals("streaming")){
root.getChildren().set(selected, new TreeItem<streamUiData>(streamData.get(selected))); root.getChildren().set(selected, new TreeItem<streamUiData>(streamData.get(selected)));
} }
@ -705,8 +695,8 @@ public class MainWindowController {
void addDataUI(){ void addDataUI(){
if(mode.equals("local")){ if(mode.equals("local")){
for(int i = 0; i < newDaten.size(); i++){ for(int i = 0; i < newData.size(); i++){
root.getChildren().add(new TreeItem<streamUiData>(newDaten.get(i))); //add data to root-node root.getChildren().add(new TreeItem<streamUiData>(newData.get(i))); //add data to root-node
} }
columnRating.setMaxWidth(90); columnRating.setMaxWidth(90);
columnTitel.setMaxWidth(290); columnTitel.setMaxWidth(290);
@ -748,7 +738,7 @@ public class MainWindowController {
} }
} }
} }
//entfernt die Endung vom String //removes the ending
private String ohneEndung (String str) { private String ohneEndung (String str) {
if (str == null) return null; if (str == null) return null;
int pos = str.lastIndexOf("."); int pos = str.lastIndexOf(".");
@ -756,7 +746,7 @@ public class MainWindowController {
return str.substring(0, pos); return str.substring(0, pos);
} }
//setzt die Farben für die UI-Elemente //set color of UI-Elements
void applyColor(){ void applyColor(){
String style = "-fx-background-color: #"+getColor()+";"; String style = "-fx-background-color: #"+getColor()+";";
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: BLACK;"; String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: BLACK;";
@ -805,7 +795,6 @@ public class MainWindowController {
menubtn.setGraphic(menu_icon_black); menubtn.setGraphic(menu_icon_black);
} }
//das solte weg kann aber hier bleiben wicht ist dass es zum selben zeitpunkt wie aply color ausgeführt wird
if(mode.equals("local")){ if(mode.equals("local")){
switchBtn.setText("streaming"); switchBtn.setText("streaming");
}else if(mode.equals("streaming")){ }else if(mode.equals("streaming")){
@ -845,14 +834,20 @@ public class MainWindowController {
parallelTransition.play(); parallelTransition.play();
} }
public void setLoaclUI(int local){ public void setLocalUI(){
switch(local){ switch(getLocal()){
case 0: bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.US); //us_english case "en_US":
break; bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.US); //us_english
case 1: bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.GERMAN); //german cbLocal.getSelectionModel().select(0);
break; break;
default:bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.US); //default local case "de_DE":
break; bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.GERMAN); //German
cbLocal.getSelectionModel().select(1);
break;
default:
bundle = ResourceBundle.getBundle("recources.HomeFlix-Local", Locale.US); //default local
cbLocal.getSelectionModel().select(0);
break;
} }
infoBtn.setText(bundle.getString("info")); infoBtn.setText(bundle.getString("info"));
settingsBtn.setText(bundle.getString("settings")); settingsBtn.setText(bundle.getString("settings"));
@ -937,14 +932,15 @@ public class MainWindowController {
} }
//saves the Settings //saves the Settings
public void saveSettings(){ public void saveSettings(String a){
OutputStream outputStream; //new outputstream System.out.println("saving, "+a);
OutputStream outputStream; //new output-stream
try { try {
props.setProperty("path", getPath()); //writes path into property props.setProperty("path", getPath()); //writes path into property
props.setProperty("color", getColor()); props.setProperty("color", getColor());
props.setProperty("autoUpdate", getAutoUpdate()); props.setProperty("autoUpdate", getAutoUpdate());
props.setProperty("size", getSize().toString()); props.setProperty("size", getSize().toString());
props.setProperty("local", Integer.toString(getLocal())); props.setProperty("local", getLocal());
props.setProperty("streamingPath", getStreamingPath()); props.setProperty("streamingPath", getStreamingPath());
props.setProperty("mode", getMode()); props.setProperty("mode", getMode());
props.setProperty("ratingSortType", columnRating.getSortType().toString()); props.setProperty("ratingSortType", columnRating.getSortType().toString());
@ -956,13 +952,16 @@ public class MainWindowController {
props.storeToXML(outputStream, "Project HomeFlix settings"); //writes new .xml props.storeToXML(outputStream, "Project HomeFlix settings"); //writes new .xml
outputStream.close(); outputStream.close();
} catch (IOException e) { } catch (IOException e) {
showErrorMsg(errorSave, e); if(firststart == false){
e.printStackTrace(); showErrorMsg(errorLoad, e);
e.printStackTrace();
}
} }
} }
//loads the Settings //loads the Settings
public void loadSettings(){ public void loadSettings(){
System.out.println("loading settings ...");
InputStream inputStream; InputStream inputStream;
try { try {
if(System.getProperty("os.name").equals("Linux")){ if(System.getProperty("os.name").equals("Linux")){
@ -970,28 +969,31 @@ public class MainWindowController {
}else{ }else{
inputStream = new FileInputStream(fileWin); inputStream = new FileInputStream(fileWin);
} }
props.loadFromXML(inputStream); //new inputstream from .xml props.loadFromXML(inputStream); //new input-stream from .xml
path = props.getProperty("path"); //reads path from property path = props.getProperty("path"); //reads path from property
streamingPath = props.getProperty("streamingPath"); streamingPath = props.getProperty("streamingPath");
color = props.getProperty("color"); color = props.getProperty("color");
size = Double.parseDouble(props.getProperty("size")); size = Double.parseDouble(props.getProperty("size"));
autoUpdate = props.getProperty("autoUpdate"); autoUpdate = props.getProperty("autoUpdate");
local = Integer.parseInt(props.getProperty("local")); local = props.getProperty("local");
mode = props.getProperty("mode"); mode = props.getProperty("mode");
ratingSortType = props.getProperty("ratingSortType"); ratingSortType = props.getProperty("ratingSortType");
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {
if(firststart == false){
showErrorMsg(errorSave, e);
e.printStackTrace();
}
// showErrorMsg(errorLoad, e); //TODO das soll beim ersten start nicht erscheinen // showErrorMsg(errorLoad, e); //TODO das soll beim ersten start nicht erscheinen
e.printStackTrace();
} }
} }
//cuts 0x of the Colorpickers return value //cuts 0x of the Color-pickers return value
private void editColor(String input){ private void editColor(String input){
StringBuilder sb = new StringBuilder(input); StringBuilder sb = new StringBuilder(input);
sb.delete(0, 2); sb.delete(0, 2);
this.color = sb.toString(); this.color = sb.toString();
saveSettings(); saveSettings("j");
} }
//getter and setter //getter and setter
@ -1035,11 +1037,11 @@ public class MainWindowController {
return autoUpdate; return autoUpdate;
} }
public void setLocal(int input){ public void setLocal(String input){
this.local = input; this.local = input;
} }
public int getLocal(){ public String getLocal(){
return local; return local;
} }

View File

@ -25,7 +25,7 @@ public class apiQuery{
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
private Image im; private Image im;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") //TODO
void startQuery(String input){ void startQuery(String input){
URL url = null; URL url = null;
Scanner sc = null; Scanner sc = null;

View File

@ -16,7 +16,7 @@ public class streamUiData {
private final IntegerProperty episode = new SimpleIntegerProperty(); private final IntegerProperty episode = new SimpleIntegerProperty();
private final DoubleProperty rating = new SimpleDoubleProperty(); private final DoubleProperty rating = new SimpleDoubleProperty();
private final StringProperty resolution = new SimpleStringProperty(); private final StringProperty resolution = new SimpleStringProperty();
private final StringProperty titel = new SimpleStringProperty(); final StringProperty titel = new SimpleStringProperty();
private final StringProperty streamUrl = new SimpleStringProperty(); private final StringProperty streamUrl = new SimpleStringProperty();
private final SimpleObjectProperty<ImageView> image = new SimpleObjectProperty<>(); private final SimpleObjectProperty<ImageView> image = new SimpleObjectProperty<>();