code cleanup

* renamed a few objects for improved their description
This commit is contained in:
Jannik 2018-03-07 23:51:02 +01:00
parent d23a3bbe4e
commit b6a1c38353
5 changed files with 58 additions and 61 deletions

View File

@ -132,7 +132,7 @@ public class Main extends Application {
// init here as it loads the games to the mwc and the gui, therefore the window must exist // init here as it loads the games to the mwc and the gui, therefore the window must exist
mainWindowController.init(); mainWindowController.init();
mainWindowController.dbController.init(); mainWindowController.getDbController().init();
} catch (IOException e) { } catch (IOException e) {
LOGGER.error(e); LOGGER.error(e);
} }

View File

@ -117,7 +117,7 @@ public class MainWindowController {
private VBox sideMenuVBox; private VBox sideMenuVBox;
@FXML @FXML
private TreeTableView<FilmTabelDataType> treeTableViewfilm; private TreeTableView<FilmTabelDataType> filmsTreeTable;
@FXML @FXML
private TableView<SourceDataType> sourcesTable; private TableView<SourceDataType> sourcesTable;
@ -201,25 +201,24 @@ public class MainWindowController {
private Label versionLbl; private Label versionLbl;
@FXML @FXML
private ImageView image1; private ImageView posterImageView;
private ImageView imv1; private ImageView imv1;
@FXML @FXML
private TreeItem<FilmTabelDataType> filmRoot = new TreeItem<>(new FilmTabelDataType("", "", 0, 0, 0, false, imv1)); private TreeItem<FilmTabelDataType> filmRoot = new TreeItem<>(new FilmTabelDataType("", "", 0, 0, 0, false, imv1));
@FXML @FXML
TreeTableColumn<FilmTabelDataType, ImageView> columnRating = new TreeTableColumn<>("Rating"); private TreeTableColumn<FilmTabelDataType, String> columnStreamUrl = new TreeTableColumn<>("File Name");
@FXML @FXML
TreeTableColumn<FilmTabelDataType, String> columnTitle = new TreeTableColumn<>("Title"); private TreeTableColumn<FilmTabelDataType, String> columnTitle = new TreeTableColumn<>("Title");
@FXML @FXML
TreeTableColumn<FilmTabelDataType, String> columnStreamUrl = new TreeTableColumn<>("File Name"); private TreeTableColumn<FilmTabelDataType, Integer> columnSeason = new TreeTableColumn<>("Season");
@FXML @FXML
TreeTableColumn<FilmTabelDataType, Integer> columnSeason = new TreeTableColumn<>("Season"); private TreeTableColumn<FilmTabelDataType, Integer> columnEpisode = new TreeTableColumn<>("Episode");
@FXML @FXML
TreeTableColumn<FilmTabelDataType, Integer> columnEpisode = new TreeTableColumn<>("Episode"); private TreeTableColumn<FilmTabelDataType, ImageView> columnRating = new TreeTableColumn<>("Rating");
@FXML @FXML
private TreeItem<SourceDataType> streamingRoot =new TreeItem<>(new SourceDataType("", "")); private TreeItem<SourceDataType> sourceRoot =new TreeItem<>(new SourceDataType("", ""));
@FXML @FXML
private TableColumn<SourceDataType, String> sourceColumn; private TableColumn<SourceDataType, String> sourceColumn;
@FXML @FXML
@ -255,10 +254,10 @@ public class MainWindowController {
private int next; private int next;
private ResourceBundle bundle; private ResourceBundle bundle;
private ObservableList<FilmTabelDataType> filterData = FXCollections.observableArrayList();
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)"); private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta"); private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
private ObservableList<FilmTabelDataType> localFilms = FXCollections.observableArrayList(); private ObservableList<FilmTabelDataType> filterData = FXCollections.observableArrayList();
private ObservableList<FilmTabelDataType> filmsList = FXCollections.observableArrayList();
private ObservableList<SourceDataType> sourcesList = FXCollections.observableArrayList(); private ObservableList<SourceDataType> sourcesList = FXCollections.observableArrayList();
private ImageView skip_previous_white = new ImageView(new Image("icons/ic_skip_previous_white_18dp_1x.png")); private ImageView skip_previous_white = new ImageView(new Image("icons/ic_skip_previous_white_18dp_1x.png"));
private ImageView skip_previous_black = new ImageView(new Image("icons/ic_skip_previous_black_18dp_1x.png")); private ImageView skip_previous_black = new ImageView(new Image("icons/ic_skip_previous_black_18dp_1x.png"));
@ -275,7 +274,7 @@ public class MainWindowController {
private Main main; private Main main;
private UpdateController updateController; private UpdateController updateController;
private apiQuery ApiQuery; private apiQuery ApiQuery;
DBController dbController; private DBController dbController;
/** /**
* "Main" Method called in Main.java main() when starting * "Main" Method called in Main.java main() when starting
@ -306,9 +305,9 @@ public class MainWindowController {
columnEpisode.setMaxWidth(64); columnEpisode.setMaxWidth(64);
columnRating.setStyle("-fx-alignment: CENTER;"); columnRating.setStyle("-fx-alignment: CENTER;");
treeTableViewfilm.setRoot(filmRoot); filmsTreeTable.setRoot(filmRoot);
treeTableViewfilm.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); filmsTreeTable.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
treeTableViewfilm.setShowRoot(false); filmsTreeTable.setShowRoot(false);
// write content into cell // write content into cell
columnTitle.setCellValueFactory(cellData -> cellData.getValue().getValue().titleProperty()); columnTitle.setCellValueFactory(cellData -> cellData.getValue().getValue().titleProperty());
@ -318,15 +317,15 @@ public class MainWindowController {
columnEpisode.setCellValueFactory(cellData -> cellData.getValue().getValue().episodeProperty().asObject()); columnEpisode.setCellValueFactory(cellData -> cellData.getValue().getValue().episodeProperty().asObject());
// add columns to treeTableViewfilm // add columns to treeTableViewfilm
treeTableViewfilm.getColumns().add(columnStreamUrl); filmsTreeTable.getColumns().add(columnStreamUrl);
treeTableViewfilm.getColumns().add(columnTitle); filmsTreeTable.getColumns().add(columnTitle);
treeTableViewfilm.getColumns().add(columnRating); filmsTreeTable.getColumns().add(columnRating);
treeTableViewfilm.getColumns().add(columnSeason); filmsTreeTable.getColumns().add(columnSeason);
treeTableViewfilm.getColumns().add(columnEpisode); filmsTreeTable.getColumns().add(columnEpisode);
treeTableViewfilm.getColumns().get(0).setVisible(false); //hide columnStreamUrl (column with file URL, important for opening a file/stream) filmsTreeTable.getColumns().get(0).setVisible(false); //hide columnStreamUrl (column with file URL, important for opening a file/stream)
// context menu for treeTableViewfilm // context menu for treeTableViewfilm
treeTableViewfilm.setContextMenu(menu); filmsTreeTable.setContextMenu(menu);
// sourcesTreeTable // sourcesTreeTable
sourceColumn.setCellValueFactory(cellData -> cellData.getValue().pathProperty()); sourceColumn.setCellValueFactory(cellData -> cellData.getValue().pathProperty());
@ -364,7 +363,7 @@ public class MainWindowController {
filterData.removeAll(filterData); filterData.removeAll(filterData);
filmRoot.getChildren().removeAll(filmRoot.getChildren()); filmRoot.getChildren().removeAll(filmRoot.getChildren());
helpData = localFilms; helpData = filmsList;
for (int i = 0; i < helpData.size(); i++) { for (int i = 0; i < helpData.size(); i++) {
@ -450,7 +449,7 @@ public class MainWindowController {
// treeTableViewfilm.getSelectionModel().clearSelection(selected); // treeTableViewfilm.getSelectionModel().clearSelection(selected);
filmRoot.getChildren().removeAll(filmRoot.getChildren()); filmRoot.getChildren().removeAll(filmRoot.getChildren());
helpData = localFilms; helpData = filmsList;
for (int i = 0; i < helpData.size(); i++) { for (int i = 0; i < helpData.size(); i++) {
if (helpData.get(i).getRating() == 1.0) { if (helpData.get(i).getRating() == 1.0) {
@ -486,17 +485,17 @@ public class MainWindowController {
}); });
// Change-listener for treeTableViewfilm // Change-listener for treeTableViewfilm
treeTableViewfilm.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() { filmsTreeTable.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) {
// last = selected; //for auto-play // last = selected; //for auto-play
selected = treeTableViewfilm.getSelectionModel().getSelectedIndex(); // get selected item selected = filmsTreeTable.getSelectionModel().getSelectedIndex(); // get selected item
last = selected - 1; last = selected - 1;
next = selected + 1; next = selected + 1;
title = columnTitle.getCellData(selected); // get name of selected item title = columnTitle.getCellData(selected); // get name of selected item
streamUrl = columnStreamUrl.getCellData(selected); // get file path of selected item streamUrl = columnStreamUrl.getCellData(selected); // get file path of selected item
if (localFilms.get(selected).getCached() == true) { if (filmsList.get(selected).getCached() == true) {
LOGGER.info("loading from cache: " + title); LOGGER.info("loading from cache: " + title);
dbController.readCache(streamUrl); dbController.readCache(streamUrl);
} else { } else {
@ -585,12 +584,12 @@ public class MainWindowController {
@FXML @FXML
private void returnBtnclicked(){ private void returnBtnclicked(){
treeTableViewfilm.getSelectionModel().select(last); filmsTreeTable.getSelectionModel().select(last);
} }
@FXML @FXML
private void forwardBtnclicked(){ private void forwardBtnclicked(){
treeTableViewfilm.getSelectionModel().select(next); filmsTreeTable.getSelectionModel().select(next);
} }
@FXML @FXML
@ -668,13 +667,15 @@ public class MainWindowController {
// refresh the selected child of the root node // refresh the selected child of the root node
private void refreshTable() { private void refreshTable() {
filmRoot.getChildren().get(selected).setValue(localFilms.get(selected)); filmRoot.getChildren().get(selected).setValue(filmsList.get(selected));
} }
// TODO rework /**
* add data from films-list to films-table
*/
public void addDataUI() { public void addDataUI() {
for (FilmTabelDataType element : localFilms) { for (FilmTabelDataType element : filmsList) {
if (element.getSeason() != 0) { if (element.getSeason() != 0) {
// System.out.println("Found Series: " + element.getTitle()); // System.out.println("Found Series: " + element.getTitle());
// check if there is a series node to add the item // check if there is a series node to add the item
@ -703,7 +704,7 @@ public class MainWindowController {
// add a source to the sources table on the settings pane // add a source to the sources table on the settings pane
public void addSourceToTable(String path, String mode) { public void addSourceToTable(String path, String mode) {
sourcesList.add(new SourceDataType(path, mode)); sourcesList.add(new SourceDataType(path, mode));
streamingRoot.getChildren().add(new TreeItem<SourceDataType>(sourcesList.get(sourcesList.size() - 1))); // adds data to root-node sourceRoot.getChildren().add(new TreeItem<SourceDataType>(sourcesList.get(sourcesList.size() - 1))); // adds data to root-node
} }
// add a source to the newsources list // add a source to the newsources list
@ -963,6 +964,10 @@ public class MainWindowController {
} }
// getter and setter // getter and setter
public DBController getDbController() {
return dbController;
}
public void setColor(String input) { public void setColor(String input) {
this.color = input; this.color = input;
} }
@ -1003,22 +1008,14 @@ public class MainWindowController {
return local; return local;
} }
public ObservableList<FilmTabelDataType> getLocalFilms() { public ObservableList<FilmTabelDataType> getFilmsList() {
return localFilms; return filmsList;
}
public void setLocalFilms(ObservableList<FilmTabelDataType> localFilms) {
this.localFilms = localFilms;
} }
public ObservableList<SourceDataType> getSourcesList() { public ObservableList<SourceDataType> getSourcesList() {
return sourcesList; return sourcesList;
} }
public void setSourcesList(ObservableList<SourceDataType> sourcesList) {
this.sourcesList = sourcesList;
}
public String getRatingSortType() { public String getRatingSortType() {
return ratingSortType; return ratingSortType;
} }
@ -1039,8 +1036,8 @@ public class MainWindowController {
return textFlow; return textFlow;
} }
public ImageView getImage1() { public ImageView getPosterImageView() {
return image1; return posterImageView;
} }
public JFXButton getUpdateBtn() { public JFXButton getUpdateBtn() {
@ -1051,7 +1048,7 @@ public class MainWindowController {
return filmRoot; return filmRoot;
} }
public TreeItem<SourceDataType> getStreamingRoot() { public TreeItem<SourceDataType> getSourceRoot() {
return streamingRoot; return sourceRoot;
} }
} }

View File

@ -135,7 +135,7 @@ public class DBController {
private void loadSources() { private void loadSources() {
// remove sources from table // remove sources from table
mainWindowController.getSourcesList().removeAll(mainWindowController.getSourcesList()); mainWindowController.getSourcesList().removeAll(mainWindowController.getSourcesList());
mainWindowController.getStreamingRoot().getChildren().removeAll(mainWindowController.getStreamingRoot().getChildren()); mainWindowController.getSourceRoot().getChildren().removeAll(mainWindowController.getSourceRoot().getChildren());
try { try {
JsonArray sources = Json.parse(new FileReader(main.getDirectory() + "/sources.json")).asArray(); JsonArray sources = Json.parse(new FileReader(main.getDirectory() + "/sources.json")).asArray();
@ -190,11 +190,11 @@ public class DBController {
ResultSet rs = stmt.executeQuery("SELECT * FROM films ORDER BY title"); ResultSet rs = stmt.executeQuery("SELECT * FROM films ORDER BY title");
while (rs.next()) { while (rs.next()) {
if (rs.getInt("rating") == 1) { if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().add(new FilmTabelDataType(rs.getString("streamUrl"), mainWindowController.getFilmsList().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black))); rs.getBoolean("cached"), new ImageView(favorite_black)));
} else { } else {
mainWindowController.getLocalFilms().add(new FilmTabelDataType(rs.getString("streamUrl"), mainWindowController.getFilmsList().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_border_black))); rs.getBoolean("cached"), new ImageView(favorite_border_black)));
} }
@ -221,11 +221,11 @@ public class DBController {
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\";"); ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\";");
if (rs.getInt("rating") == 1) { if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"), mainWindowController.getFilmsList().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black))); rs.getBoolean("cached"), new ImageView(favorite_black)));
} else { } else {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"), mainWindowController.getFilmsList().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_border_black))); rs.getBoolean("cached"), new ImageView(favorite_border_black)));
} }
@ -262,7 +262,7 @@ public class DBController {
} }
// remove all films from the mwc lists // remove all films from the mwc lists
mainWindowController.getLocalFilms().removeAll(mainWindowController.getLocalFilms()); mainWindowController.getFilmsList().removeAll(mainWindowController.getFilmsList());
mainWindowController.getFilmRoot().getChildren().removeAll(mainWindowController.getFilmRoot().getChildren()); mainWindowController.getFilmRoot().getChildren().removeAll(mainWindowController.getFilmRoot().getChildren());
loadDataToMWC(); // load the new data to the mwc loadDataToMWC(); // load the new data to the mwc
@ -347,7 +347,7 @@ public class DBController {
} }
} else { } else {
// if it's a streaming source check the file for new films // TODO implement series support // if it's a streaming source check the file for new films
for (String entry : filmsStreamURL) { for (String entry : filmsStreamURL) {
if (!filmsdbStreamURL.contains(entry)) { if (!filmsdbStreamURL.contains(entry)) {
JsonArray items = Json.parse(new FileReader(source.getPath())).asObject().get("entries").asArray(); JsonArray items = Json.parse(new FileReader(source.getPath())).asObject().get("entries").asArray();
@ -562,12 +562,12 @@ public class DBController {
} }
try { try {
mainWindowController.getImage1().setImage(im); mainWindowController.getPosterImageView().setImage(im);
} catch (Exception e) { } catch (Exception e) {
mainWindowController.getImage1().setImage(new Image("resources/icons/close_black_2048x2048.png")); mainWindowController.getPosterImageView().setImage(new Image("resources/icons/close_black_2048x2048.png"));
LOGGER.error(e); LOGGER.error(e);
} }
mainWindowController.getImage1().setImage(im); mainWindowController.getPosterImageView().setImage(im);
} catch (SQLException e) { } catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e); LOGGER.error("Ups! an error occured!", e);

View File

@ -164,7 +164,7 @@ public class apiQuery{
if (retdata.contains("\"Response\":\"False\"")) { // TODO + FIXME if (retdata.contains("\"Response\":\"False\"")) { // TODO + FIXME
mainWindowController.getTextFlow().getChildren().add(new Text(mainWindowController.getBundle().getString("noFilmFound"))); mainWindowController.getTextFlow().getChildren().add(new Text(mainWindowController.getBundle().getString("noFilmFound")));
im = new Image("resources/icons/close_black_2048x2048.png"); im = new Image("resources/icons/close_black_2048x2048.png");
mainWindowController.getImage1().setImage(im); mainWindowController.getPosterImageView().setImage(im);
} else { } else {
nameText.add(0, new Text(mainWindowController.getBundle().getString("title") + ": ")); nameText.add(0, new Text(mainWindowController.getBundle().getString("title") + ": "));
nameText.add(1, new Text(mainWindowController.getBundle().getString("year") + ": ")); nameText.add(1, new Text(mainWindowController.getBundle().getString("year") + ": "));
@ -200,7 +200,7 @@ public class apiQuery{
} else { } else {
im = new Image(responseString[18]); im = new Image(responseString[18]);
} }
mainWindowController.getImage1().setImage(im); mainWindowController.getPosterImageView().setImage(im);
} }
} }

View File

@ -29,7 +29,7 @@
<TextFlow fx:id="textFlow" accessibleRole="TEXT_AREA" maxHeight="544.0" maxWidth="320.0" visible="true" /> <TextFlow fx:id="textFlow" accessibleRole="TEXT_AREA" maxHeight="544.0" maxWidth="320.0" visible="true" />
</content> </content>
</ScrollPane> </ScrollPane>
<TreeTableView fx:id="treeTableViewfilm" layoutX="14.0" layoutY="88.0" prefHeight="500.0" prefWidth="375.0" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="12.0" AnchorPane.rightAnchor="568.0" AnchorPane.topAnchor="88.0" /> <TreeTableView fx:id="filmsTreeTable" layoutX="14.0" layoutY="88.0" prefHeight="500.0" prefWidth="375.0" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="12.0" AnchorPane.rightAnchor="568.0" AnchorPane.topAnchor="88.0" />
<JFXButton fx:id="playbtn" contentDisplay="CENTER" layoutX="690.0" layoutY="363.0" onAction="#playbtnclicked" prefHeight="25.0" prefWidth="198.0" AnchorPane.bottomAnchor="212.0" AnchorPane.rightAnchor="12.0"> <JFXButton fx:id="playbtn" contentDisplay="CENTER" layoutX="690.0" layoutY="363.0" onAction="#playbtnclicked" prefHeight="25.0" prefWidth="198.0" AnchorPane.bottomAnchor="212.0" AnchorPane.rightAnchor="12.0">
<font> <font>
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />