Browse Source

code cleanup

pull/22/head
Jannik 4 years ago
parent
commit
5297c614d5
  1. 37
      src/main/java/kellerkinder/HomeFlix/application/Main.java
  2. 528
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  3. 2
      src/main/java/kellerkinder/HomeFlix/controller/apiQuery.java

37
src/main/java/kellerkinder/HomeFlix/application/Main.java

@ -55,8 +55,8 @@ public class Main extends Application {
private static String osVers = System.getProperty("os.version");
private static String javaVers = System.getProperty("java.version");
private static String javaVend= System.getProperty("java.vendor");
private String dirWin = System.getProperty("user.home") + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix
private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
private String dirWin = userHome + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix
private String dirLinux = userHome + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
private File directory;
private File configFile;
private File posterCache;
@ -94,14 +94,14 @@ public class Main extends Application {
// get OS and the specific paths
if (osName.equals("Linux")) {
directory = new File(dirLinux);
configFile = new File(dirLinux + "/config.xml");
posterCache = new File(dirLinux + "/posterCache");
} else {
if (osName.equals("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");
}
// startup checks
@ -143,7 +143,6 @@ public class Main extends Application {
// Method for first Start
private String firstStart(){
MainWindowController.firststart = true;
switch(System.getProperty("user.language")+"_"+System.getProperty("user.country")){
case "en_US": bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); //us_english
break;
@ -172,13 +171,13 @@ public class Main extends Application {
}
public static void main(String[] args) {
if(System.getProperty("os.name").equals("Linux")){
System.setProperty("logFilename", System.getProperty("user.home") + "/HomeFlix/app.log");
File logFile = new File(System.getProperty("user.home") + "/HomeFlix/app.log");
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();
}else{
System.setProperty("logFilename", System.getProperty("user.home") + "/Documents/HomeFlix/app.log");
File logFile = new File(System.getProperty("user.home") + "/Documents/HomeFlix/app.log");
System.setProperty("logFilename", userHome + "/HomeFlix/app.log");
File logFile = new File(userHome + "/HomeFlix/app.log");
logFile.delete();
}
LOGGER = LogManager.getLogger(Main.class.getName());
@ -200,12 +199,16 @@ public class Main extends Application {
public void setFONT_FAMILY(String FONT_FAMILY) {
this.FONT_FAMILY = FONT_FAMILY;
}
public File getDirectory() {
return directory;
}
public File getPosterCache() {
return posterCache;
public File getConfigFile() {
return configFile;
}
public void setPosterCache(File posterCache) {
this.posterCache = posterCache;
public File getPosterCache() {
return posterCache;
}
}

528
src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java

@ -171,22 +171,22 @@ public class MainWindowController {
private ImageView imv1;
@FXML
TreeItem<tableData> root = new TreeItem<>(new tableData(1, 1, 1, 5.0,"1", "filme","1", imv1, false));
@FXML
TreeTableColumn<tableData, ImageView> columnRating = new TreeTableColumn<>("Rating");
@FXML
TreeTableColumn<tableData, String> columnTitel = new TreeTableColumn<>("Titel");
@FXML
TreeTableColumn<tableData, String> columnStreamUrl = new TreeTableColumn<>("File Name");
@FXML
TreeTableColumn<tableData, String> columnResolution = new TreeTableColumn<>("Resolution");
@FXML
TreeTableColumn<tableData, Integer> columnYear = new TreeTableColumn<>("Year");
@FXML
TreeTableColumn<tableData, Integer> columnSeason = new TreeTableColumn<>("Season");
@FXML
TreeTableColumn<tableData, Integer> columnEpisode = new TreeTableColumn<>("Episode");
@FXML
TreeItem<tableData> root = new TreeItem<>(new tableData(1, 1, 1, 5.0, "1", "filme", "1", imv1, false));
@FXML
TreeTableColumn<tableData, ImageView> columnRating = new TreeTableColumn<>("Rating");
@FXML
TreeTableColumn<tableData, String> columnTitel = new TreeTableColumn<>("Titel");
@FXML
TreeTableColumn<tableData, String> columnStreamUrl = new TreeTableColumn<>("File Name");
@FXML
TreeTableColumn<tableData, String> columnResolution = new TreeTableColumn<>("Resolution");
@FXML
TreeTableColumn<tableData, Integer> columnYear = new TreeTableColumn<>("Year");
@FXML
TreeTableColumn<tableData, Integer> columnSeason = new TreeTableColumn<>("Season");
@FXML
TreeTableColumn<tableData, Integer> columnEpisode = new TreeTableColumn<>("Episode");
@FXML
private TreeItem<tableData> streamingRoot =new TreeItem<>(new tableData(1 ,1 ,1 ,1.0 ,"1" ,"filme" ,"1", imv1, false));
@ -195,25 +195,17 @@ public class MainWindowController {
@FXML
private TableColumn<tableData, String> dataNameEndColumn = new TableColumn<>("Datei Name mit Endung");
private boolean menuTrue = false; //saves the position of menuBtn (opened or closed)
private boolean menuTrue = false;
private boolean settingsTrue = false;
private boolean streamingSettingsTrue = false;
private boolean autoUpdate = false;
private boolean useBeta = false;
static boolean firststart = false;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
private int hashA = -647380320;
private String version = "0.5.2";
private String buildNumber = "131";
private String versionName = "solidify cow";
private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix");
private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix");
private File fileWin = new File(dirWin + "/config.xml");
private File fileLinux = new File(dirLinux + "/config.xml");
public String errorUpdateD;
public String errorUpdateV;
public String noFilmFound;
private String errorPlay;
private String errorOpenStream;
@ -258,231 +250,9 @@ public class MainWindowController {
private Main main;
private UpdateController updateController;
// private updater Updater;
private apiQuery ApiQuery;
DBController dbController;
@FXML
private void playbtnclicked(){
if (mode.equals("streaming")) {
if (Desktop.isDesktopSupported()) {
new Thread(() -> {
try {
Desktop.getDesktop().browse(new URI(datPath)); //open the streaming URL in browser
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
showErrorMsg(errorOpenStream, (IOException) e);
}
}).start();
} else {
LOGGER.info("Desktop not supported");
}
}else if (mode.equals("local")) {
if(System.getProperty("os.name").contains("Linux")){
String line;
String output = "";
Process p;
try {
p = Runtime.getRuntime().exec("which vlc");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output = line;
}
LOGGER.info(output);
input.close();
} catch (IOException e1) {
e1.printStackTrace();
}
if(output.contains("which: no vlc")||output == ""){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setHeaderText("");
alert.setTitle("Info");
alert.setContentText(vlcNotInstalled);
alert.showAndWait();
}else{
try {
Runtime.getRuntime().exec(new String[] { "vlc", getPath()+"/"+ datPath});
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
}
}else if(System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")){
try {
Desktop.getDesktop().open(new File(getPath()+"\\"+ datPath));
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
} else {
LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! ");
}
} else {
IOException e = new IOException("error");
showErrorMsg(errorMode, e);
}
}
@FXML
private void openfolderbtnclicked(){
try {
Desktop.getDesktop().open(new File(getPath())); //open path when button is clicked
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
private void returnBtnclicked(){
treeTableViewfilm.getSelectionModel().select(last);
}
@FXML
private void forwardBtnclicked(){
treeTableViewfilm.getSelectionModel().select(next);
}
@FXML
private void infoBtnclicked(){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Info");
alert.setHeaderText("Project HomeFlix");
alert.setContentText(infoText);
alert.initOwner(main.getPrimaryStage());
alert.showAndWait();
}
@FXML
private void settingsBtnclicked(){
if(settingsTrue == false){
if(streamingSettingsTrue == true){
streamingSettingsAnchor.setVisible(false);
streamingSettingsTrue = false;
}
settingsAnchor.setVisible(true);
settingsTrue = true;
}else{
settingsAnchor.setVisible(false);
setPath(tfPath.getText());
saveSettings();
settingsTrue = false;
}
}
/**
* TODO additional info about the "streaming.json"
*/
@FXML
private void streamingSettingsBtnclicked(){
if(streamingSettingsTrue == false){
if(settingsTrue == true){
settingsAnchor.setVisible(false);
settingsTrue = false;
}
streamingSettingsAnchor.setVisible(true);
streamingSettingsTrue = true;
}else{
streamingSettingsAnchor.setVisible(false);
streamingSettingsTrue = false;
}
}
@FXML
private void switchBtnclicked(){
if(mode.equals("local")){ //switch to streaming mode
setMode("streaming");
switchBtn.setText("local");
}else if(mode.equals("streaming")){ //switch to local mode
setMode("local");
switchBtn.setText("streaming");
}
saveSettings();
root.getChildren().remove(0,root.getChildren().size());
addDataUI();
settingsAnchor.setVisible(false);
streamingSettingsAnchor.setVisible(false);
sideMenuSlideOut(); //disables side-menu
menuTrue = false;
settingsTrue = false;
streamingSettingsTrue = false;
}
@FXML
private void debugBtnclicked(){
//for testing
}
@FXML
private void tfPathAction(){
setPath(tfPath.getText());
saveSettings();
}
@FXML
private void directoryBtnAction(){
selectedFolder = directoryChooser.showDialog(null);
if(selectedFolder == null){
LOGGER.warn("No Directory selected");
}else{
setPath(selectedFolder.getAbsolutePath());
saveSettings();
tfPath.setText(getPath());
try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {
LOGGER.error("error while restarting HomeFlix", e);
}
}
}
@FXML
private void mainColorAction(){
editColor(mainColor.getValue().toString());
applyColor();
}
@FXML
private void updateBtnAction(){
updateController = new UpdateController(this, buildNumber, useBeta);
Thread updateThread = new Thread(updateController);
updateThread.setName("Updater");
updateThread.start();
}
@FXML
private void autoUpdateToggleBtnAction(){
if (autoUpdate) {
setAutoUpdate(false);
} else {
setAutoUpdate(true);
}
saveSettings();
}
@FXML
private void tfStreamingPathAction(){
//
}
@FXML
private void streamingDirectoryBtnAction(){
selectedStreamingFolder = directoryChooser.showDialog(null);
if(selectedStreamingFolder == null){
LOGGER.warn("No Directory selected");
}else{
setStreamingPath(selectedStreamingFolder.getAbsolutePath());
saveSettings();
tfStreamingPath.setText(getStreamingPath());
try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {
LOGGER.error("error while restarting HomeFlix", e);
}
}
}
/**"Main" Method called in Main.java main() when starting
* Initialize other objects: Updater, dbController and ApiQuery
*/
@ -502,7 +272,7 @@ public class MainWindowController {
}
//Initialize the tables (treeTableViewfilm and tableViewStreamingdata)
void initTabel() {
private void initTabel() {
//film Table
columnRating.setMaxWidth(80);
@ -578,7 +348,7 @@ public class MainWindowController {
}
//Initializing the actions
void initActions(){
private void initActions(){
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
@ -755,7 +525,7 @@ public class MainWindowController {
}
// initialize UI elements
void initUI() {
private void initUI() {
LOGGER.info("Mode: " + mode); // TODO debugging
debugBtn.setDisable(true); // debugging button for tests
debugBtn.setVisible(false);
@ -772,6 +542,226 @@ public class MainWindowController {
applyColor();
}
@FXML
private void playbtnclicked(){
if (mode.equals("streaming")) {
if (Desktop.isDesktopSupported()) {
new Thread(() -> {
try {
Desktop.getDesktop().browse(new URI(datPath)); //open the streaming URL in browser
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
showErrorMsg(errorOpenStream, (IOException) e);
}
}).start();
} else {
LOGGER.info("Desktop not supported");
}
}else if (mode.equals("local")) {
if(System.getProperty("os.name").contains("Linux")){
String line;
String output = "";
Process p;
try {
p = Runtime.getRuntime().exec("which vlc");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output = line;
}
LOGGER.info(output);
input.close();
} catch (IOException e1) {
e1.printStackTrace();
}
if(output.contains("which: no vlc")||output == ""){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setHeaderText("");
alert.setTitle("Info");
alert.setContentText(vlcNotInstalled);
alert.showAndWait();
}else{
try {
Runtime.getRuntime().exec(new String[] { "vlc", getPath()+"/"+ datPath});
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
}
}else if(System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")){
try {
Desktop.getDesktop().open(new File(getPath()+"\\"+ datPath));
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
} else {
LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! ");
}
} else {
IOException e = new IOException("error");
showErrorMsg(errorMode, e);
}
}
@FXML
private void openfolderbtnclicked(){
try {
Desktop.getDesktop().open(new File(getPath())); //open path when button is clicked
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
private void returnBtnclicked(){
treeTableViewfilm.getSelectionModel().select(last);
}
@FXML
private void forwardBtnclicked(){
treeTableViewfilm.getSelectionModel().select(next);
}
@FXML
private void infoBtnclicked(){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Info");
alert.setHeaderText("Project HomeFlix");
alert.setContentText(infoText);
alert.initOwner(main.getPrimaryStage());
alert.showAndWait();
}
@FXML
private void settingsBtnclicked(){
if(settingsTrue == false){
if(streamingSettingsTrue == true){
streamingSettingsAnchor.setVisible(false);
streamingSettingsTrue = false;
}
settingsAnchor.setVisible(true);
settingsTrue = true;
}else{
settingsAnchor.setVisible(false);
setPath(tfPath.getText());
saveSettings();
settingsTrue = false;
}
}
/**
* TODO additional info about the "streaming.json"
*/
@FXML
private void streamingSettingsBtnclicked(){
if(streamingSettingsTrue == false){
if(settingsTrue == true){
settingsAnchor.setVisible(false);
settingsTrue = false;
}
streamingSettingsAnchor.setVisible(true);
streamingSettingsTrue = true;
}else{
streamingSettingsAnchor.setVisible(false);
streamingSettingsTrue = false;
}
}
@FXML
private void switchBtnclicked(){
if(mode.equals("local")){ //switch to streaming mode
setMode("streaming");
switchBtn.setText("local");
}else if(mode.equals("streaming")){ //switch to local mode
setMode("local");
switchBtn.setText("streaming");
}
saveSettings();
root.getChildren().remove(0,root.getChildren().size());
addDataUI();
settingsAnchor.setVisible(false);
streamingSettingsAnchor.setVisible(false);
sideMenuSlideOut(); //disables side-menu
menuTrue = false;
settingsTrue = false;
streamingSettingsTrue = false;
}
@FXML
private void debugBtnclicked(){
//for testing
}
@FXML
private void tfPathAction(){
setPath(tfPath.getText());
saveSettings();
}
@FXML
private void directoryBtnAction(){
selectedFolder = directoryChooser.showDialog(null);
if(selectedFolder == null){
LOGGER.warn("No Directory selected");
}else{
setPath(selectedFolder.getAbsolutePath());
saveSettings();
tfPath.setText(getPath());
try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {
LOGGER.error("error while restarting HomeFlix", e);
}
}
}
@FXML
private void mainColorAction(){
editColor(mainColor.getValue().toString());
applyColor();
}
@FXML
private void updateBtnAction(){
updateController = new UpdateController(this, buildNumber, useBeta);
Thread updateThread = new Thread(updateController);
updateThread.setName("Updater");
updateThread.start();
}
@FXML
private void autoUpdateToggleBtnAction(){
if (autoUpdate) {
setAutoUpdate(false);
} else {
setAutoUpdate(true);
}
saveSettings();
}
@FXML
private void tfStreamingPathAction(){
//
}
@FXML
private void streamingDirectoryBtnAction(){
selectedStreamingFolder = directoryChooser.showDialog(null);
if(selectedStreamingFolder == null){
LOGGER.warn("No Directory selected");
}else{
setStreamingPath(selectedStreamingFolder.getAbsolutePath());
saveSettings();
tfStreamingPath.setText(getStreamingPath());
try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {
LOGGER.error("error while restarting HomeFlix", e);
}
}
}
private void refreshTable(){
if(mode.equals("local")){
root.getChildren().set(selected, new TreeItem<tableData>(localFilms.get(selected)));
@ -837,7 +827,7 @@ public class MainWindowController {
}
//set color of UI-Elements
void applyColor() {
private void applyColor() {
String style = "-fx-background-color: #" + getColor() + ";";
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: BLACK;";
String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: WHITE;";
@ -961,14 +951,11 @@ public class MainWindowController {
columnResolution.setText(getBundle().getString("columnResolution"));
columnSeason.setText(getBundle().getString("columnSeason"));
columnYear.setText(getBundle().getString("columnYear"));
errorUpdateD = getBundle().getString("errorUpdateD");
errorUpdateV = getBundle().getString("errorUpdateV");
errorPlay = getBundle().getString("errorPlay");
errorOpenStream = getBundle().getString("errorOpenStream");
errorMode = getBundle().getString("errorMode");
errorLoad = getBundle().getString("errorLoad");
errorSave = getBundle().getString("errorSave");
noFilmFound = getBundle().getString("noFilmFound");
infoText = getBundle().getString("version") + " " + version + " (Build: " + buildNumber + ") " + versionName + getBundle().getString("infoText");
vlcNotInstalled = getBundle().getString("vlcNotInstalled");
}
@ -1005,10 +992,9 @@ public class MainWindowController {
LOGGER.error("An error occurred", exception);
}
// saves the Settings
// save settings
public void saveSettings() {
LOGGER.info("saving settings ...");
OutputStream outputStream; // new output-stream
try {
props.setProperty("path", getPath()); // writes path into property
props.setProperty("color", getColor());
@ -1018,31 +1004,21 @@ public class MainWindowController {
props.setProperty("streamingPath", getStreamingPath());
props.setProperty("mode", getMode());
props.setProperty("ratingSortType", columnRating.getSortType().toString());
if (System.getProperty("os.name").equals("Linux")) {
outputStream = new FileOutputStream(fileLinux);
} else {
outputStream = new FileOutputStream(fileWin);
}
OutputStream outputStream = new FileOutputStream(main.getConfigFile()); // new output-stream
props.storeToXML(outputStream, "Project HomeFlix settings"); // writes new .xml
outputStream.close();
} catch (IOException e) {
if (firststart == false) {
showErrorMsg(errorLoad, e);
e.printStackTrace();
}
LOGGER.error(errorLoad, e);
}
}
// loads the Settings
// load settings
public void loadSettings() {
LOGGER.info("loading settings ...");
InputStream inputStream;
try {
if (System.getProperty("os.name").equals("Linux")) {
inputStream = new FileInputStream(fileLinux);
} else {
inputStream = new FileInputStream(fileWin);
}
InputStream inputStream = new FileInputStream(main.getConfigFile());
props.loadFromXML(inputStream); // new input-stream from .xml
try {
@ -1113,11 +1089,7 @@ public class MainWindowController {
inputStream.close();
} catch (IOException e) {
if (firststart == false) {
LOGGER.error("faild to load settings", e);
showErrorMsg(errorSave, e);
}
// showErrorMsg(errorLoad, e); //TODO This should not be visible at first startup
LOGGER.error(errorSave, e);
}
}

2
src/main/java/kellerkinder/HomeFlix/controller/apiQuery.java

@ -158,7 +158,7 @@ public class apiQuery{
// if response == false then show mainWindowController.noFilmFound else create new Texts and add them to flowText
if (retdata.contains("\"Response\":\"False\"")) { // TODO + FIXME
mainWindowController.getTextFlow().getChildren().add(new Text(mainWindowController.noFilmFound));
mainWindowController.getTextFlow().getChildren().add(new Text(mainWindowController.getBundle().getString("noFilmFound")));
im = new Image("resources/icons/close_black_2048x2048.png");
mainWindowController.getImage1().setImage(im);
} else {

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close