Browse Source

some clean up and first bits for poster mode GUI logic

pull/12/head
Jannik 3 years ago
parent
commit
7dbe0d46d8
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 6
      pom.xml
  2. 66
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  3. 57
      src/main/java/kellerkinder/HomeFlix/controller/DBController.java
  4. 4
      src/main/java/kellerkinder/HomeFlix/datatypes/DatabaseDataType.java
  5. 81
      src/main/java/kellerkinder/HomeFlix/datatypes/PosterModeElement.java

6
pom.xml

@ -27,19 +27,19 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12</version>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12</version>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>12</version>
<version>12.0.1</version>
</dependency>
<dependency>

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

@ -91,6 +91,7 @@ import kellerkinder.HomeFlix.controller.OMDbAPIController;
import kellerkinder.HomeFlix.controller.UpdateController;
import kellerkinder.HomeFlix.controller.XMLController;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
import kellerkinder.HomeFlix.datatypes.PosterModeElement;
import kellerkinder.HomeFlix.datatypes.SourceDataType;
import kellerkinder.HomeFlix.player.Player;
@ -157,8 +158,12 @@ public class MainWindowController {
@FXML private JFXButton forwardBtn;
// poster-mode
@FXML private AnchorPane posterModeAnchorPane;
@FXML private ScrollPane posterModeScrollPane;
@FXML private AnchorPane posterModeAnchorPane;
private int xPos = -200;
private int yPos = 17;
private int xNextElement = 0;
private DBController dbController;
private UpdateController updateController;
@ -184,6 +189,7 @@ public class MainWindowController {
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
private ObservableList<FilmTabelDataType> filterData = FXCollections.observableArrayList();
private ObservableList<FilmTabelDataType> filmsList = FXCollections.observableArrayList();
private ObservableList<PosterModeElement> posterEmenents = FXCollections.observableArrayList();
private static ObservableList<SourceDataType> sourcesList = FXCollections.observableArrayList();
private MenuItem like = new MenuItem("like");
private MenuItem dislike = new MenuItem("dislike"); // TODO one option (like or dislike)
@ -335,13 +341,13 @@ public class MainWindowController {
like.setOnAction(e -> {
dbController.like(getCurrentStreamUrl());
filmsList.set(indexList, dbController.getDatabaseFilm(getCurrentStreamUrl()));
filmsList.set(indexList, dbController.getStream(getCurrentStreamUrl()));
refreshTableElement();
});
dislike.setOnAction(e -> {
dbController.dislike(getCurrentStreamUrl());
filmsList.set(indexList, dbController.getDatabaseFilm(getCurrentStreamUrl()));
filmsList.set(indexList, dbController.getStream(getCurrentStreamUrl()));
refreshTableElement();
});
@ -571,10 +577,14 @@ public class MainWindowController {
*/
private void refreshAllFilms() {
filmsList.clear();
filmRoot.getChildren().clear();
dbController.refreshDataBase(); // refreshes the database after a source path was added
filmsList = dbController.getDatabaseFilmsList(); // returns a list of all films stored in the database
filmsList = dbController.getStreamsList(); // returns a list of all films stored in the database
// refresh filmRoot in filmsTreeTable
filmRoot.getChildren().clear();
addFilmsToTable(filmsList);
//
}
/**
@ -872,6 +882,7 @@ public class MainWindowController {
private void posterModeStartup() {
checkAllPosters();
addGUIElements();
}
/**
@ -890,10 +901,55 @@ public class MainWindowController {
executor.shutdown();
// TODO show loading screen
// executor.awaitTermination(1, TimeUnit.MINUTES); // we might need this as otherwise it would load before all tasks are finished
// update all elements from the database
refreshAllFilms();
System.out.println("finished refresh");
}
/**
* add all cached films/series to the PosterMode GUI
*/
private void addGUIElements() {
// refresh the posterModeElements list
posterEmenents.clear();
posterEmenents = dbController.getPosterElementsList(); // returns a list of all PosterElements stored in the database
posterModeAnchorPane.getChildren().clear(); // remove all GUIElements from the posterModeAnchorPane
// reset the position
xPos = -200;
yPos = 17;
xNextElement = 0;
// add all films/series as new GUIElements to the posterModeAnchorPane
for(PosterModeElement element : posterEmenents) {
generatePosition();
element.setLayoutX(xPos);
element.setLayoutY(yPos);
posterModeAnchorPane.getChildren().add(element);
}
}
/**
* xMaxElements based on window width -36
* calculates how many games can be displayed in one row
*/
private void generatePosition() {
int xMaxElements = (int) Math.floor((mainAnchorPane.getWidth() - 36) / 217);
if(xNextElement >= xMaxElements){
// oldXPosHelper = xNextElement; // only needed if window resizing is allowed
xPos = 17;
yPos = yPos + 345;
xNextElement = 1;
}else{
xPos = xPos + 217;
xNextElement++;
}
}
// getter and setter

57
src/main/java/kellerkinder/HomeFlix/controller/DBController.java

@ -21,6 +21,7 @@
package kellerkinder.HomeFlix.controller;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLConnection;
@ -44,6 +45,7 @@ import javafx.scene.image.ImageView;
import kellerkinder.HomeFlix.datatypes.DatabaseDataType;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
import kellerkinder.HomeFlix.datatypes.PosterModeElement;
public class DBController {
@ -149,11 +151,11 @@ public class DBController {
}
/**
* load the data from the database to a ObservableList
* load all streams from the database to a ObservableList,
* order entries by title
* @return a ObservableList that contains all films from the database
* @return a ObservableList that contains all streams from the database
*/
public ObservableList<FilmTabelDataType> getDatabaseFilmsList() {
public ObservableList<FilmTabelDataType> getStreamsList() {
ObservableList<FilmTabelDataType> filmsList = FXCollections.observableArrayList();
LOGGER.info("loading data from database ...");
try {
@ -177,11 +179,11 @@ public class DBController {
}
/**
* get one film from the database with streamUrl = ?
* @param streamUrl of the film
* @return a FilmTabelDataType Object of the film with the given streamUrl
* get one stream from the database with streamUrl = ?
* @param streamUrl of the stream
* @return a FilmTabelDataType Object of the stream with the given streamUrl
*/
public FilmTabelDataType getDatabaseFilm(String streamUrl) {
public FilmTabelDataType getStream(String streamUrl) {
FilmTabelDataType film = null;
LOGGER.info("refresh data for " + streamUrl);
try {
@ -204,6 +206,45 @@ public class DBController {
return film;
}
/**
* get all entries of the database as PosterModeElement
* @return a ObservableList of PosterModeElements
*/
public ObservableList<PosterModeElement> getPosterElementsList() {
ObservableList<PosterModeElement> posterElementsList = FXCollections.observableArrayList();
LOGGER.info("loading data from database ...");
try {
//load local Data
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films ORDER BY title");
while (rs.next()) {
// create the stream object
PosterModeElement posterElement = new PosterModeElement();
posterElement.setStreamURL(rs.getString("streamUrl"));
// get from the cache table
String[] cacheData = readCache(rs.getString("streamUrl"));
posterElement.getLabel().setText(cacheData[0]);
if(cacheData[20] != null) {
posterElement.getImageView().setImage(new Image(new File(cacheData[20]).toURI().toString()));
} else {
posterElement.getImageView().setImage(new Image("/icons/Homeflix_Poster.png"));
}
posterElementsList.add(posterElement);
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("An error occured while getting all PosterElements!", e);
}
return posterElementsList;
}
/**
* refresh database to contain all (new added) entries
*/
@ -217,7 +258,7 @@ public class DBController {
loadSources(); // reload all sources
loadDatabase(); // reload all films saved in the DB
LOGGER.info("filme in db: " + databaseStreams.size());
LOGGER.info("There are {} entries in the Database", databaseStreams.size());
try {
checkAddEntry();

4
src/main/java/kellerkinder/HomeFlix/datatypes/DatabaseDataType.java

@ -34,6 +34,10 @@ public class DatabaseDataType {
private Date cached;
private double currentTime;
public DatabaseDataType() {
// constructor stub
}
public DatabaseDataType(String streamUrl, String title, String season, String episode, int favorite, Date cached, double currentTime) {
this.streamUrl = streamUrl;
this.title = title;

81
src/main/java/kellerkinder/HomeFlix/datatypes/PosterModeElement.java

@ -0,0 +1,81 @@
/**
* Project-HomeFlix
*
* Copyright 2016-2019 <@Seil0>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
package kellerkinder.HomeFlix.datatypes;
import com.jfoenix.controls.JFXButton;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
public class PosterModeElement extends VBox{
private String streamURL;
private Label label = new Label();
private JFXButton button = new JFXButton();
private ImageView imageView = new ImageView();
public PosterModeElement() {
// constructor stub
}
public PosterModeElement(String streamURL, Label label, JFXButton button, ImageView imageView) {
this.streamURL = streamURL;
this.label = label;
this.button = button;
this.imageView = imageView;
}
public String getStreamURL() {
return streamURL;
}
public Label getLabel() {
return label;
}
public JFXButton getButton() {
return button;
}
public ImageView getImageView() {
return imageView;
}
public void setStreamURL(String streamURL) {
this.streamURL = streamURL;
}
public void setLabel(Label label) {
this.label = label;
}
public void setButton(JFXButton button) {
this.button = button;
}
public void setImageView(ImageView imageView) {
this.imageView = imageView;
}
}
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