PosterMode now has posters, UI optimizations

* the settings page is now re-sizable
* the postermode now shows actual posters
* the series root- folder is now treated as root node
This commit is contained in:
Jannik 2019-06-15 18:44:35 +02:00
parent 4d503546ff
commit bb8bcd460a
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
8 changed files with 200 additions and 68 deletions

View File

@ -73,8 +73,8 @@ public class Main extends Application {
loader.setLocation(getClass().getResource("/fxml/MainWindow.fxml"));
pane = (AnchorPane) loader.load();
primaryStage.setMinHeight(600.00);
primaryStage.setMinWidth(1000.00);
primaryStage.setResizable(false);
primaryStage.setMinWidth(1130.00);
//primaryStage.setResizable(false);
primaryStage.setTitle("Project HomeFlix");
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); //adds application icon
primaryStage.setOnCloseRequest(event -> System.exit(0));

View File

@ -37,6 +37,7 @@ import java.util.Locale;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
@ -71,6 +72,7 @@ import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableColumn.SortType;
import javafx.scene.control.TreeTableView;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
@ -225,6 +227,10 @@ public class MainWindowController {
// Initialize general UI elements
private void initUI() {
//JFXScrollPane.smoothScrolling(posterModeScrollPane);
posterModeScrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
settingsScrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
versionLbl.setText("Version: " + version + " (Build: " + buildNumber + ")");
fontsizeSlider.setValue(XMLController.getFontSize());
colorPicker.setValue(Color.valueOf(XMLController.getColor()));
@ -899,7 +905,12 @@ 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
// we might need this as otherwise it would load before all tasks are finished
try {
executor.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
LOGGER.error(e);
}
// update all elements from the database
refreshAllFilms();
@ -916,6 +927,8 @@ public class MainWindowController {
posterModeFlowPane.getChildren().clear(); // remove all GUIElements from the posterModeFlowPane
posterModeFlowPane.getChildren().addAll(posterEmenents); // add all films/series as new GUIElements to the posterModeFlowPane
System.out.println("added gui elements");
}
// getter and setter

View File

@ -204,7 +204,7 @@ public class DBController {
}
/**
* get all entries of the database as PosterModeElement
* get entries which have no season and episode eg. root or movie of the database as PosterModeElement
* @return a ObservableList of PosterModeElements
*/
public ObservableList<PosterModeElement> getPosterElementsList() {
@ -214,24 +214,20 @@ public class DBController {
try {
//load local Data
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films ORDER BY title");
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE season = '' OR season = '0' ORDER BY title");
while (rs.next()) {
// create the stream object
PosterModeElement posterElement = new PosterModeElement();
posterElement.setStreamURL(rs.getString("streamUrl"));
String[] cacheData = readCache(rs.getString("streamUrl")); // get from the cache table
// get from the cache table
String[] cacheData = readCache(rs.getString("streamUrl"));
posterElement.getLabel().setText(cacheData[0]);
System.out.println(rs.getString("streamUrl"));
System.out.println(":" + cacheData[20] + ":");
if(cacheData[20] != null) {
posterElement.getImageView().setImage(new Image(new File(cacheData[20]).toURI().toString()));
if(cacheData[20] != null && cacheData[20].length() > 0) {
posterElementsList.add(new PosterModeElement(rs.getString("streamUrl"), cacheData[0], new Image(new File(cacheData[20]).toURI().toString())));
} else {
posterElement.getImageView().setImage(new Image("/icons/Homeflix_Poster.png"));
System.out.println("adding default");
posterElementsList.add(new PosterModeElement(rs.getString("streamUrl"), cacheData[0], new Image("icons/Homeflix_Poster.png")));
}
posterElementsList.add(posterElement);
}
stmt.close();
rs.close();

View File

@ -46,7 +46,6 @@ public class OMDbAPIController implements Runnable {
private FilmTabelDataType currentTableFilm;
private String omdbAPIKey;
private String URL = "https://www.omdbapi.com/?apikey=";
private boolean useEpisode = true;
private static final Logger LOGGER = LogManager.getLogger(OMDbAPIController.class.getName());
/**
@ -66,7 +65,13 @@ public class OMDbAPIController implements Runnable {
public void run() {
LOGGER.info("Querying omdbAPI ...");
JsonObject object;
object = getByTitle(currentTableFilm.getTitle());
if (currentTableFilm.getSeason() != null && Integer.parseInt(currentTableFilm.getSeason() + 0) > 0) {
object = getByTitle(currentTableFilm.getTitle(), true);
} else {
object = getByTitle(currentTableFilm.getTitle(), false);
}
if (object == null) {
LOGGER.error("Fatal error while querying omdbAPI!");
return;
@ -76,13 +81,11 @@ public class OMDbAPIController implements Runnable {
if (object.getString("Error", "").contains("not found!")) {
String title = searchByTitle(currentTableFilm.getTitle());
if (title.length() > 0) {
// we have at least on answer, get info by title now
object = getByTitle(title);
// if we still have nothing found, get info by title without episode
if(object.getString("Error", "").contains("Series or episode not found!")) {
useEpisode = false;
object = getByTitle(title);
// we have at least one answer, get info by search title now
if (currentTableFilm.getSeason() != null && Integer.parseInt(currentTableFilm.getSeason() + 0) > 0) {
object = getByTitle(title, true);
} else {
object = getByTitle(title, false);
}
} else {
// add default poster and cache
@ -91,7 +94,6 @@ public class OMDbAPIController implements Runnable {
omdbResponse.setTitle(currentTableFilm.getTitle());
omdbResponse.setSeason(currentTableFilm.getSeason());
omdbResponse.setEpisode(currentTableFilm.getEpisode());
omdbResponse.setPoster("icons/Homeflix_Poster.png");
synchronized (this) {
// adding to cache
@ -131,22 +133,16 @@ public class OMDbAPIController implements Runnable {
omdbResponse.setResponse(object.getString("Response", ""));
// if a poster exist try resizing it to fit in the posterImageView and add it to the cache, else use the default
if (omdbResponse.getPoster() != null) {
try {
BufferedImage originalImage = ImageIO.read(new URL(object.getString("Poster", "")));
// change path to where file is located
omdbResponse.setPoster(XMLController.getPosterCache() + "/" + omdbResponse.getTitle() + ".png");
ImageIO.write(originalImage, "png", new File(omdbResponse.getPoster()));
LOGGER.info("adding poster to cache: " + omdbResponse.getPoster());
} catch (Exception e) {
LOGGER.error(e);
}
} else {
omdbResponse.setPoster("icons/Homeflix_Poster.png");
try {
BufferedImage originalImage = ImageIO.read(new URL(object.getString("Poster", "")));
// change path to where file is located
omdbResponse.setPoster(XMLController.getPosterCache() + "/" + omdbResponse.getTitle() + ".png");
ImageIO.write(originalImage, "png", new File(omdbResponse.getPoster()));
LOGGER.info("adding poster to cache: " + omdbResponse.getPoster());
} catch (Exception e) {
LOGGER.warn("could not load poster, seting null -> using default");
}
synchronized (this) {
// adding to cache
dbController.addCache(currentTableFilm.getStreamUrl(), omdbResponse);
@ -161,11 +157,11 @@ public class OMDbAPIController implements Runnable {
* @param title of the movie/series
* @return a jsonObject of the API answer
*/
private JsonObject getByTitle(String title) {
private JsonObject getByTitle(String title, boolean useEpisode) {
String output = null;
URL apiUrl;
try {
if (currentTableFilm.getSeason().length() > 0 && useEpisode) {
try {
if (useEpisode) {
apiUrl = new URL(URL + omdbAPIKey + "&t="
+ title.replace(" ", "%20")
+ "&Season=" + currentTableFilm.getSeason()

View File

@ -89,8 +89,9 @@ public class SourcesController {
// if it's valid file add it to the sourceStreams
if (isValidFile(file)) {
sourceStreams.add(new DatabaseDataType(file.getPath(), cutOffEnd(file.getName()), "", "", 0, 0.0));
} else if(file.isDirectory()) {
} else if(isValidSeriesRoot(file)) {
// get all directories (series), root and season must be directories
sourceStreams.add(new DatabaseDataType(file.getPath(), file.getName(), "0", "0", 0, 0.0)); // add the series root node
int sn = 1;
for (File season : file.listFiles()) {
if (season.isDirectory()) {
@ -150,6 +151,25 @@ public class SourcesController {
return false;
}
/**
*
* @param file the root file you want to check
* @return true if it's a valid series root, else false
*/
private boolean isValidSeriesRoot(File file) {
if(file.isDirectory()) {
for (File season : file.listFiles()) {
if (season.isDirectory()) {
return true;
} else {
return false; // the root directory not only folders
}
}
}
return false;
}
// removes the ending
private String cutOffEnd(String str) {

View File

@ -24,31 +24,53 @@ package kellerkinder.HomeFlix.datatypes;
import com.jfoenix.controls.JFXButton;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
public class PosterModeElement extends VBox{
private String streamURL;
private String title;
private Label label = new Label();
private JFXButton button = new JFXButton();
private ImageView imageView = new ImageView();
public PosterModeElement() {
// constructor stub
super.getChildren().addAll(label, button);
label.setMaxWidth(200);
label.setPadding(new Insets(0,0,0,8));
label.setFont(Font.font("System", FontWeight.BOLD, 14));
imageView.setFitHeight(300);
imageView.setFitWidth(200);
button.setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 3); ");
button.setGraphic(imageView);
}
public PosterModeElement(String streamURL, Label label, JFXButton button, ImageView imageView) {
public PosterModeElement(String streamURL, String title, Image poster) {
this();
this.streamURL = streamURL;
this.label = label;
this.button = button;
this.imageView = imageView;
this.title = title;
label.setText(title);
imageView.setImage(poster);
}
public String getStreamURL() {
return streamURL;
}
public String getTitle() {
return title;
}
public Label getLabel() {
return label;
@ -65,6 +87,10 @@ public class PosterModeElement extends VBox{
public void setStreamURL(String streamURL) {
this.streamURL = streamURL;
}
public void setTitle(String title) {
this.title = title;
}
public void setLabel(Label label) {
this.label = label;

View File

@ -1,6 +1,8 @@
/*
* HAMBURGER CSS
*/
/*******************************************************************************
* *
* Hamburger Menu *
* *
******************************************************************************/
.jfx-hamburgerW StackPane {
-fx-background-color: white;
@ -12,9 +14,12 @@
-fx-background-radius: 5px;
}
/*
* TREE TABLE CSS
*/
/*******************************************************************************
* *
* TreeTable *
* *
******************************************************************************/
.tree-table-view {
-fx-tree-table-color: rgba(0, 168, 204, 0.2);
@ -84,9 +89,11 @@
-fx-padding: 1; /* 0.083333em; */
}
/*
* ChoiceBox
*/
/*******************************************************************************
* *
* ChoiceBox *
* *
******************************************************************************/
.choice-box {
-fx-background-color: transparent;
@ -106,4 +113,78 @@
.menu-item:focused {
-fx-background-color: #EE3523;
}
/*******************************************************************************
* *
* ScrollBar *
* *
******************************************************************************/
.scroll-bar:vertical > .track-background, .scroll-bar:horizontal > .track-background {
-fx-background-color: #F1F1F1;
-fx-background-insets: 0.0;
}
.scroll-bar:vertical > .thumb, .scroll-bar:horizontal > .thumb {
-fx-background-color: #BCBCBC;
-fx-background-insets: 0.0;
-fx-background-radius: 1.0;
}
/* Up- and Down-Button Padding */
.scroll-bar:vertical > .increment-button, .scroll-bar:vertical > .decrement-button {
-fx-padding: 5 2 5 2;
}
/* Left- and Right-Button Padding */
.scroll-bar:horizontal > .increment-button, .scroll-bar:horizontal > .decrement-button {
-fx-padding: 2 5 2 5;
}
.scroll-bar > .increment-button, .scroll-bar > .decrement-button, .scroll-bar:hover > .increment-button, .scroll-bar:hover > .decrement-button {
-fx-background-color: transparent;
}
.scroll-bar > .increment-button > .increment-arrow, .scroll-bar > .decrement-button > .decrement-arrow {
-fx-background-color: rgb(150.0, 150.0, 150.0);
}
/* Up Arrow */
.scroll-bar:vertical > .increment-button > .increment-arrow {
-fx-shape: "M298 426h428l-214 214z";
}
/* Down Arrow */
.scroll-bar:vertical > .decrement-button > .decrement-arrow {
-fx-shape: "M298 598l214-214 214 214h-428z";
}
/* Right Arrow */
.scroll-bar:horizontal > .increment-button > .increment-arrow {
-fx-shape: "M0 428l0 -428l214 214l-214 214z";
}
/* Left Arrow */
.scroll-bar:horizontal > .decrement-button > .decrement-arrow {
-fx-shape: "M214 0l0 428l-214 -214l214 -214z";
}
/*******************************************************************************
* *
* ScrollPane *
* *
******************************************************************************/
.scroll-pane {
-fx-background-insets: 0;
-fx-padding: 0;
}
.scroll-pane:focused {
-fx-background-insets: 0;
}
.scroll-pane .corner {
-fx-background-insets: 0;
}

View File

@ -24,7 +24,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?>
<AnchorPane fx:id="mainAnchorPane" prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kellerkinder.HomeFlix.application.MainWindowController">
<AnchorPane fx:id="mainAnchorPane" prefHeight="600.0" prefWidth="1130.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kellerkinder.HomeFlix.application.MainWindowController">
<children>
<AnchorPane fx:id="tableModeAnchorPane" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0">
<children>
@ -36,10 +36,10 @@
<TreeTableView fx:id="filmsTreeTable" prefHeight="500.0" prefWidth="420.0" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="12.0" AnchorPane.rightAnchor="568.0" AnchorPane.topAnchor="56.0">
<columns>
<TreeTableColumn fx:id="columnStreamUrl" editable="false" prefWidth="75.0" resizable="false" text="Stream URL" visible="false" />
<TreeTableColumn fx:id="columnTitle" maxWidth="182.0" minWidth="182.0" prefWidth="182.0" resizable="false" text="Title" />
<TreeTableColumn fx:id="columnFavorite" maxWidth="80.0" minWidth="80.0" resizable="false" style="-fx-alignment: CENTER;" text="Favorite" />
<TreeTableColumn fx:id="columnSeason" maxWidth="70.0" minWidth="70.0" prefWidth="70.0" resizable="false" text="Season" />
<TreeTableColumn fx:id="columnEpisode" maxWidth="70.0" minWidth="70.0" prefWidth="70.0" resizable="false" text="Episode" />
<TreeTableColumn fx:id="columnTitle" maxWidth="276.0" minWidth="276.0" prefWidth="276.0" resizable="false" text="Title" />
<TreeTableColumn fx:id="columnFavorite" maxWidth="100.0" minWidth="100.0" prefWidth="100.0" resizable="false" style="-fx-alignment: CENTER;" text="Favorite" />
<TreeTableColumn fx:id="columnSeason" maxWidth="80.0" minWidth="80.0" resizable="false" text="Season" />
<TreeTableColumn fx:id="columnEpisode" maxWidth="80.0" minWidth="80.0" resizable="false" text="Episode" />
</columns></TreeTableView>
<ScrollPane fx:id="textScrollPane" fitToWidth="true" prefHeight="544.0" prefWidth="320.0" AnchorPane.bottomAnchor="12.0" AnchorPane.rightAnchor="222.0" AnchorPane.topAnchor="12.0">
<content>
@ -65,18 +65,18 @@
<JFXButton fx:id="forwardBtn" contentDisplay="CENTER" onAction="#forwardBtnclicked" prefHeight="25.0" prefWidth="90.0" AnchorPane.bottomAnchor="132.0" AnchorPane.rightAnchor="12.0" />
</children>
</AnchorPane>
<ScrollPane fx:id="posterModeScrollPane" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0">
<ScrollPane fx:id="posterModeScrollPane" fitToWidth="true" layoutX="10.0" layoutY="48.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0">
<content>
<FlowPane fx:id="posterModeFlowPane" hgap="3.0" vgap="7.0">
<padding>
<Insets bottom="17.0" />
<Insets bottom="17.0" left="3.0" right="3.0" />
</padding>
</FlowPane>
</content>
</ScrollPane>
<ScrollPane fx:id="settingsScrollPane" prefHeight="568.0" prefWidth="800.0" style="-fx-background: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0">
<ScrollPane fx:id="settingsScrollPane" fitToHeight="true" fitToWidth="true" prefHeight="568.0" prefWidth="800.0" style="-fx-background: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0">
<content>
<AnchorPane fx:id="settingsAnchorPane" prefWidth="832.0" style="-fx-background-color: white;">
<AnchorPane fx:id="settingsAnchorPane" style="-fx-background-color: white;">
<children>
<VBox spacing="30.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<padding>
@ -166,7 +166,7 @@
<JFXButton fx:id="addDirectoryBtn" onAction="#addDirectoryBtnAction" prefHeight="32.0" text="add directory" />
</children>
</HBox>
<TableView fx:id="sourcesTable" maxWidth="430.0" minHeight="100.0" prefHeight="100.0" prefWidth="430.0">
<TableView fx:id="sourcesTable" maxWidth="-Infinity" minHeight="150.0" minWidth="-Infinity" prefWidth="443.0">
<columns>
<TableColumn fx:id="sourceColumn" prefWidth="290.0" resizable="false" text="Sources" />
<TableColumn fx:id="modeColumn" minWidth="130.0" prefWidth="138.0" resizable="false" text="Mode" />