2016-08-14 15:17:14 +02:00
/ * *
2018-03-01 15:42:47 +01:00
* Project - HomeFlix
2018-04-06 20:33:56 +02:00
*
2019-01-08 17:10:33 +01:00
* Copyright 2016 - 2019 < @Seil0 >
2016-08-14 15:17:14 +02:00
*
* 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 .
*
* /
2018-11-17 13:02:41 +01:00
2018-03-01 15:42:47 +01:00
package kellerkinder.HomeFlix.application ;
2016-08-14 15:17:14 +02:00
import java.io.File ;
2018-03-04 20:07:43 +01:00
import java.io.FileReader ;
import java.io.FileWriter ;
2016-08-14 15:17:14 +02:00
import java.io.IOException ;
2018-03-04 20:07:43 +01:00
import java.io.Writer ;
2016-08-14 15:17:14 +02:00
import java.math.BigInteger ;
2019-01-22 17:29:56 +01:00
import java.time.LocalDate ;
2016-08-14 15:17:14 +02:00
import java.util.Locale ;
import java.util.ResourceBundle ;
2018-12-08 23:44:17 +01:00
import java.util.concurrent.ExecutorService ;
import java.util.concurrent.Executors ;
2019-06-15 18:44:35 +02:00
import java.util.concurrent.TimeUnit ;
2017-09-16 18:22:46 +02:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2019-06-21 21:16:53 +02:00
import org.kellerkinder.Alerts.JFX2BtnCancelAlert ;
2018-03-29 18:15:57 +02:00
import org.kellerkinder.Alerts.JFXInfoAlert ;
2017-09-16 18:22:46 +02:00
2018-03-04 20:07:43 +01:00
import com.eclipsesource.json.Json ;
import com.eclipsesource.json.JsonArray ;
import com.eclipsesource.json.JsonObject ;
2016-08-14 15:17:14 +02:00
import com.jfoenix.controls.JFXButton ;
2017-06-07 01:42:18 +02:00
import com.jfoenix.controls.JFXHamburger ;
import com.jfoenix.transitions.hamburger.HamburgerBackArrowBasicTransition ;
2016-08-14 15:17:14 +02:00
2016-10-10 16:55:26 +02:00
import javafx.animation.TranslateTransition ;
2016-08-14 15:17:14 +02:00
import javafx.collections.FXCollections ;
import javafx.collections.ObservableList ;
import javafx.fxml.FXML ;
2017-03-05 18:29:24 +01:00
import javafx.scene.control.ScrollPane ;
2019-06-15 18:44:35 +02:00
import javafx.scene.control.ScrollPane.ScrollBarPolicy ;
2019-06-27 13:30:44 +02:00
import javafx.scene.effect.BoxBlur ;
2017-06-07 01:42:18 +02:00
import javafx.scene.input.MouseEvent ;
2016-08-14 15:17:14 +02:00
import javafx.scene.layout.AnchorPane ;
2019-06-15 11:09:59 +02:00
import javafx.scene.layout.FlowPane ;
2016-10-09 16:05:44 +02:00
import javafx.scene.layout.HBox ;
2016-08-14 15:17:14 +02:00
import javafx.scene.layout.VBox ;
import javafx.stage.DirectoryChooser ;
2018-03-04 20:07:43 +01:00
import javafx.stage.FileChooser ;
2019-01-08 19:02:00 +01:00
import javafx.stage.Stage ;
2016-10-10 16:55:26 +02:00
import javafx.util.Duration ;
2018-03-01 15:42:47 +01:00
import kellerkinder.HomeFlix.controller.DBController ;
2018-03-08 17:59:28 +01:00
import kellerkinder.HomeFlix.controller.OMDbAPIController ;
2018-03-01 15:42:47 +01:00
import kellerkinder.HomeFlix.controller.UpdateController ;
2019-01-08 17:10:33 +01:00
import kellerkinder.HomeFlix.controller.XMLController ;
2019-01-14 20:45:49 +01:00
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType ;
2019-05-15 17:14:15 +02:00
import kellerkinder.HomeFlix.datatypes.PosterModeElement ;
2016-08-14 15:17:14 +02:00
2017-03-05 18:29:24 +01:00
public class MainWindowController {
2018-03-01 23:18:40 +01:00
2019-06-19 16:31:49 +02:00
// general
2018-07-24 14:14:34 +02:00
@FXML private AnchorPane mainAnchorPane ;
2018-04-07 17:14:35 +02:00
2018-07-24 14:14:34 +02:00
@FXML private HBox topHBox ;
@FXML private VBox sideMenuVBox ;
2019-06-19 16:31:49 +02:00
@FXML private JFXHamburger menuHam ;
2018-03-01 23:18:40 +01:00
2018-07-24 14:14:34 +02:00
@FXML private JFXButton aboutBtn ;
@FXML private JFXButton settingsBtn ;
2019-06-19 16:31:49 +02:00
// settings
2019-06-21 21:16:53 +02:00
@FXML private SettingsView settingsViewController ;
2018-03-01 23:18:40 +01:00
2018-07-24 14:14:34 +02:00
// poster-mode
2019-01-22 18:12:30 +01:00
@FXML private ScrollPane posterModeScrollPane ;
2019-06-15 11:09:59 +02:00
@FXML private FlowPane posterModeFlowPane ;
2019-06-16 13:00:29 +02:00
@FXML private FilmDetailView filmDetailViewController ;
2019-06-18 01:25:46 +02:00
@FXML private SeriesDetailView seriesDetailViewController ;
2018-04-28 18:02:02 +02:00
2019-06-16 21:44:42 +02:00
private static MainWindowController instance = null ;
2019-01-14 20:45:49 +01:00
private DBController dbController ;
2019-01-08 17:10:33 +01:00
private XMLController xmlController ;
2019-01-08 19:02:00 +01:00
private Stage primaryStage ;
2018-04-28 18:02:02 +02:00
private static final Logger LOGGER = LogManager . getLogger ( MainWindowController . class . getName ( ) ) ;
2019-05-06 00:50:27 +02:00
2018-03-01 16:10:37 +01:00
private boolean menuTrue = false ;
2018-04-08 13:30:55 +02:00
2018-04-28 18:02:02 +02:00
private String btnStyle ;
2019-05-06 00:50:27 +02:00
2019-05-15 17:14:15 +02:00
private ObservableList < PosterModeElement > posterEmenents = FXCollections . observableArrayList ( ) ;
2019-01-22 17:29:56 +01:00
private LocalDate lastValidCache = LocalDate . now ( ) . minusDays ( 30 ) ; // current date - 30 days is the last valid cache date
2018-05-17 18:58:54 +02:00
2019-01-08 19:02:00 +01:00
public MainWindowController ( ) {
// the constructor
}
2019-06-16 21:44:42 +02:00
public static MainWindowController getInstance ( ) {
if ( instance = = null ) {
LOGGER . error ( " There was a fatal error: instance is null! " ) ;
instance = new MainWindowController ( ) ;
}
return instance ;
}
2019-05-06 00:50:27 +02:00
2019-01-08 19:02:00 +01:00
public void initialize ( ) {
2019-06-16 21:44:42 +02:00
instance = this ;
2019-01-08 19:02:00 +01:00
xmlController = new XMLController ( ) ;
2019-01-14 18:44:36 +01:00
dbController = DBController . getInstance ( ) ;
2019-06-21 21:16:53 +02:00
if ( ! new File ( XMLController . getDirHomeFlix ( ) + " /sources.json " ) . exists ( ) ) {
XMLController . getDirHomeFlix ( ) . mkdir ( ) ;
LOGGER . warn ( " sources file not found " ) ;
addFirstSource ( ) ;
xmlController . saveSettings ( ) ;
}
2016-08-14 15:17:14 +02:00
}
2019-05-06 00:50:27 +02:00
public void init ( ) {
2019-06-21 21:16:53 +02:00
LOGGER . info ( " Initializing Project-HomeFlix build " + Main . buildNumber ) ;
2019-05-06 00:50:27 +02:00
2018-05-17 18:58:54 +02:00
// initialize the GUI and the DBController
2019-01-08 19:02:00 +01:00
primaryStage = ( Stage ) mainAnchorPane . getScene ( ) . getWindow ( ) ; // set primary stage for dialogs
2019-06-21 21:16:53 +02:00
posterModeScrollPane . setVbarPolicy ( ScrollBarPolicy . ALWAYS ) ;
setLocalUI ( ) ;
applyColor ( ) ; // TODO only on first start
2018-04-06 20:33:56 +02:00
initActions ( ) ;
2018-05-17 18:58:54 +02:00
dbController . init ( ) ;
2019-05-06 00:50:27 +02:00
2019-06-19 16:31:49 +02:00
// load data list in gui
posterModeStartup ( ) ;
2019-06-15 18:44:35 +02:00
2019-06-21 21:16:53 +02:00
checkAutoUpdate ( ) ; // TODO async
2016-09-09 20:41:20 +02:00
}
2018-04-08 13:30:55 +02:00
// Initializing the actions
2018-03-04 20:07:43 +01:00
private void initActions ( ) {
2018-07-22 23:30:52 +02:00
// general actions
2017-06-07 01:42:18 +02:00
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition ( menuHam ) ;
2018-03-04 20:07:43 +01:00
menuHam . addEventHandler ( MouseEvent . MOUSE_PRESSED , ( e ) - > {
2019-06-23 15:23:03 +02:00
2018-05-17 18:58:54 +02:00
if ( menuTrue ) {
2017-06-07 01:42:18 +02:00
sideMenuSlideOut ( ) ;
burgerTask . setRate ( - 1 . 0 ) ;
burgerTask . play ( ) ;
menuTrue = false ;
2018-05-17 18:58:54 +02:00
} else {
sideMenuSlideIn ( ) ;
burgerTask . setRate ( 1 . 0 ) ;
burgerTask . play ( ) ;
menuTrue = true ;
2017-06-07 01:42:18 +02:00
}
2019-06-19 16:31:49 +02:00
2019-06-21 21:16:53 +02:00
if ( settingsViewController . isVisible ( ) ) {
settingsViewController . setVisible ( false ) ;
}
2019-06-23 15:23:03 +02:00
} ) ;
2016-09-09 20:41:20 +02:00
}
2019-05-06 00:50:27 +02:00
2018-07-22 23:30:52 +02:00
// general fxml actions
2018-03-01 16:10:37 +01:00
@FXML
2018-03-02 13:50:21 +01:00
private void aboutBtnAction ( ) {
2019-06-21 21:16:53 +02:00
String bodyText = " Project HomeFlix \ nVersion: " + Main . version + " (Build: " + Main . buildNumber + " ) \" "
+ Main . versionName + " \" \ n " + XMLController . getLocalBundle ( ) . getString ( " infoText " ) ;
2019-01-08 19:02:00 +01:00
JFXInfoAlert infoAlert = new JFXInfoAlert ( " Project HomeFlix " , bodyText , btnStyle , primaryStage ) ;
2018-03-29 18:15:57 +02:00
infoAlert . showAndWait ( ) ;
2018-03-01 16:10:37 +01:00
}
2019-05-06 00:50:27 +02:00
2018-03-01 16:10:37 +01:00
@FXML
2018-05-17 18:58:54 +02:00
private void settingsBtnclicked ( ) {
2019-06-21 21:16:53 +02:00
settingsViewController . setVisible ( ! settingsViewController . isVisible ( ) ) ;
2018-03-01 16:10:37 +01:00
}
2019-06-21 21:16:53 +02:00
2019-01-14 18:44:36 +01:00
/ * *
2019-06-21 21:16:53 +02:00
* we need to get the path for the first source from the user and add it to
* sources . json , if the user ends the file - / directory - chooser the program will exit
2019-01-14 18:44:36 +01:00
* /
2019-06-21 21:16:53 +02:00
private void addFirstSource ( ) {
JFX2BtnCancelAlert selectFirstSource = new JFX2BtnCancelAlert (
XMLController . getLocalBundle ( ) . getString ( " addSourceHeader " ) ,
XMLController . getLocalBundle ( ) . getString ( " addSourceBody " ) ,
" -fx-button-type: RAISED; -fx-background-color: #ee3523; -fx-text-fill: BLACK; " ,
XMLController . getLocalBundle ( ) . getString ( " addDirectory " ) ,
XMLController . getLocalBundle ( ) . getString ( " addStreamSource " ) ,
XMLController . getLocalBundle ( ) . getString ( " cancelBtnText " ) , primaryStage ) ;
// directory action
selectFirstSource . setBtn1Action ( e - > {
DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
directoryChooser . setTitle ( XMLController . getLocalBundle ( ) . getString ( " addDirectory " ) ) ;
File selectedFolder = directoryChooser . showDialog ( primaryStage ) ;
if ( selectedFolder ! = null & & selectedFolder . exists ( ) ) {
selectFirstSource . getAlert ( ) . close ( ) ;
writeSource ( selectedFolder . getPath ( ) , " local " ) ;
2019-06-22 21:04:43 +02:00
settingsViewController . loadInitSources ( ) ;
2019-06-21 21:16:53 +02:00
} else {
LOGGER . error ( " The selected folder dosen't exist! " ) ;
System . exit ( 1 ) ;
}
} ) ;
2019-05-06 00:50:27 +02:00
2019-06-21 21:16:53 +02:00
// streaming action
selectFirstSource . setBtn2Action ( e - > {
FileChooser fileChooser = new FileChooser ( ) ;
fileChooser . setTitle ( XMLController . getLocalBundle ( ) . getString ( " addStreamSource " ) ) ;
File selectedFile = fileChooser . showOpenDialog ( primaryStage ) ;
if ( selectedFile ! = null & & selectedFile . exists ( ) ) {
selectFirstSource . getAlert ( ) . close ( ) ;
writeSource ( selectedFile . getPath ( ) , " stream " ) ;
2019-06-22 21:04:43 +02:00
settingsViewController . loadInitSources ( ) ;
2019-06-21 21:16:53 +02:00
} else {
LOGGER . error ( " The selected file dosen't exist! " ) ;
System . exit ( 1 ) ;
}
} ) ;
selectFirstSource . showAndWait ( ) ;
2016-09-09 20:41:20 +02:00
}
2019-05-06 00:50:27 +02:00
2018-07-22 23:30:52 +02:00
/ * *
2019-06-21 21:16:53 +02:00
* add a source to the sources file
2019-05-06 00:50:27 +02:00
*
2018-07-22 23:30:52 +02:00
* @param path to the source
* @param mode of the source ( local or streaming )
* /
2019-06-21 21:16:53 +02:00
void writeSource ( String path , String mode ) {
2018-03-04 20:07:43 +01:00
JsonArray newsources = null ;
2019-06-21 21:16:53 +02:00
2018-03-04 20:07:43 +01:00
try {
// read old array
2019-01-08 17:10:33 +01:00
File oldSources = new File ( XMLController . getDirHomeFlix ( ) + " /sources.json " ) ;
2019-06-21 21:16:53 +02:00
newsources = oldSources . exists ( ) ? Json . parse ( new FileReader ( XMLController . getDirHomeFlix ( ) + " /sources.json " ) ) . asArray ( ) : Json . array ( ) ;
2018-03-04 20:07:43 +01:00
// add new source
2019-05-06 00:50:27 +02:00
JsonObject source = Json . object ( ) . add ( " path " , path ) . add ( " mode " , mode ) ;
2018-03-04 20:07:43 +01:00
newsources . add ( source ) ;
2019-01-08 17:10:33 +01:00
Writer writer = new FileWriter ( XMLController . getDirHomeFlix ( ) + " /sources.json " ) ;
2018-03-04 20:07:43 +01:00
newsources . writeTo ( writer ) ;
writer . close ( ) ;
} catch ( IOException e ) {
2019-06-21 21:16:53 +02:00
LOGGER . error ( " Error while writing sources file! " , e ) ;
2018-03-04 20:07:43 +01:00
}
2016-08-14 15:17:14 +02:00
}
2019-05-06 00:50:27 +02:00
2018-04-02 18:29:59 +02:00
/ * *
2019-05-06 00:50:27 +02:00
* set the color of the GUI - Elements if usedColor is less than checkColor set
* text fill white , else black
2018-04-02 18:29:59 +02:00
* /
2019-06-21 21:16:53 +02:00
void applyColor ( ) {
2018-04-28 18:02:02 +02:00
String menuBtnStyle ;
2019-01-08 17:10:33 +01:00
BigInteger usedColor = new BigInteger ( XMLController . getColor ( ) , 16 ) ;
2018-04-02 18:29:59 +02:00
BigInteger checkColor = new BigInteger ( " 78909cff " , 16 ) ;
2018-02-24 17:13:52 +01:00
2019-06-21 21:16:53 +02:00
menuHam . getStyleClass ( ) . clear ( ) ;
2018-04-02 18:29:59 +02:00
if ( usedColor . compareTo ( checkColor ) = = - 1 ) {
2019-05-06 17:26:19 +02:00
btnStyle = " -fx-button-type: RAISED; -fx-background-color: # " + XMLController . getColor ( ) + " ; -fx-text-fill: WHITE; " ;
2018-04-28 18:02:02 +02:00
menuBtnStyle = " -fx-text-fill: WHITE; " ;
2017-06-07 01:42:18 +02:00
menuHam . getStyleClass ( ) . add ( " jfx-hamburgerW " ) ;
2018-02-24 17:13:52 +01:00
} else {
2019-05-06 17:26:19 +02:00
btnStyle = " -fx-button-type: RAISED; -fx-background-color: # " + XMLController . getColor ( ) + " ; -fx-text-fill: BLACK; " ;
2018-04-28 18:02:02 +02:00
menuBtnStyle = " -fx-text-fill: BLACK; " ;
2017-06-07 01:42:18 +02:00
menuHam . getStyleClass ( ) . add ( " jfx-hamburgerB " ) ;
2016-08-14 15:17:14 +02:00
}
2019-05-06 00:50:27 +02:00
2018-04-28 18:02:02 +02:00
// boxes and TextFields
2019-01-08 17:10:33 +01:00
sideMenuVBox . setStyle ( " -fx-background-color: # " + XMLController . getColor ( ) + " ; " ) ;
topHBox . setStyle ( " -fx-background-color: # " + XMLController . getColor ( ) + " ; " ) ;
2019-05-06 00:50:27 +02:00
2018-04-28 18:02:02 +02:00
// menu buttons
settingsBtn . setStyle ( menuBtnStyle ) ;
aboutBtn . setStyle ( menuBtnStyle ) ;
2019-06-21 21:16:53 +02:00
settingsViewController . updateColor ( btnStyle ) ;
2016-08-14 15:17:14 +02:00
}
2019-05-06 00:50:27 +02:00
2018-03-04 20:07:43 +01:00
// slide in in 400ms
2018-02-24 17:13:52 +01:00
private void sideMenuSlideIn ( ) {
2016-10-10 16:55:26 +02:00
TranslateTransition translateTransition = new TranslateTransition ( Duration . millis ( 400 ) , sideMenuVBox ) ;
2019-06-23 15:26:05 +02:00
translateTransition . setFromX ( 0 ) ;
translateTransition . setToX ( 150 ) ;
2018-03-04 20:07:43 +01:00
translateTransition . play ( ) ;
2016-10-10 16:55:26 +02:00
}
2019-05-06 00:50:27 +02:00
2018-03-04 20:07:43 +01:00
// slide out in 400ms
2018-02-24 17:13:52 +01:00
private void sideMenuSlideOut ( ) {
2016-10-10 16:55:26 +02:00
TranslateTransition translateTransition = new TranslateTransition ( Duration . millis ( 400 ) , sideMenuVBox ) ;
2019-06-23 15:26:05 +02:00
translateTransition . setFromX ( 150 ) ;
translateTransition . setToX ( 0 ) ;
2018-03-04 20:07:43 +01:00
translateTransition . play ( ) ;
2016-10-10 16:55:26 +02:00
}
2019-05-06 00:50:27 +02:00
2018-04-02 18:29:59 +02:00
/ * *
* set the local based on the languageChoisBox selection
* /
2019-06-21 21:16:53 +02:00
void setLocalUI ( ) {
// TODO switch expressions
2019-01-08 17:10:33 +01:00
switch ( XMLController . getUsrLocal ( ) ) {
2018-02-24 17:13:52 +01:00
case " en_US " :
2019-01-09 22:36:50 +01:00
XMLController . setLocalBundle ( ResourceBundle . getBundle ( " locals.HomeFlix-Local " , Locale . US ) ) ; // us_English
2017-02-09 20:39:43 +01:00
break ;
2018-02-24 17:13:52 +01:00
case " de_DE " :
2019-01-09 22:36:50 +01:00
XMLController . setLocalBundle ( ResourceBundle . getBundle ( " locals.HomeFlix-Local " , Locale . GERMAN ) ) ; // German
2017-02-09 20:39:43 +01:00
break ;
2018-02-24 17:13:52 +01:00
default :
2019-01-09 22:36:50 +01:00
XMLController . setLocalBundle ( ResourceBundle . getBundle ( " locals.HomeFlix-Local " , Locale . US ) ) ; // default local
2017-02-09 20:39:43 +01:00
break ;
2018-02-24 17:13:52 +01:00
}
2019-06-16 21:44:42 +02:00
2019-06-21 21:16:53 +02:00
settingsViewController . updateGUILocal ( ) ;
2019-06-16 21:44:42 +02:00
filmDetailViewController . updateGUILocal ( ) ;
2019-06-18 01:25:46 +02:00
seriesDetailViewController . updateGUILocal ( ) ;
2019-06-16 21:44:42 +02:00
2019-01-09 22:36:50 +01:00
aboutBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " info " ) ) ;
settingsBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " settings " ) ) ;
2019-01-14 18:44:36 +01:00
}
2019-05-06 00:50:27 +02:00
2018-03-01 15:42:47 +01:00
// if AutoUpdate, then check for updates
private void checkAutoUpdate ( ) {
2019-06-27 13:30:44 +02:00
LOGGER . info ( " AutoUpdate: looking for updates on startup ... " ) ;
2018-03-01 15:42:47 +01:00
2019-06-27 13:30:44 +02:00
if ( XMLController . isAutoUpdate ( ) & & UpdateController . isUpdateAvailable ( ) ) {
UpdateController . update ( ) ;
2018-03-01 15:42:47 +01:00
}
}
2019-05-06 00:50:27 +02:00
2019-01-22 18:12:30 +01:00
/ * *
2019-06-22 21:04:43 +02:00
* Poser Mode
2019-01-22 18:12:30 +01:00
* /
2019-05-06 00:50:27 +02:00
2018-08-13 23:56:16 +02:00
private void posterModeStartup ( ) {
checkAllPosters ( ) ;
2019-06-19 16:31:49 +02:00
addAllPosters ( ) ;
checkCache ( ) ;
2018-08-13 23:56:16 +02:00
}
2019-05-06 00:50:27 +02:00
2018-08-13 23:56:16 +02:00
/ * *
* check if all posters are cached , if not cache the missing ones
* /
2019-06-21 21:16:53 +02:00
void checkAllPosters ( ) {
2019-06-22 21:04:43 +02:00
dbController . refreshDataBase ( ) ; // refreshes the database after a source path was added
2018-08-13 23:56:16 +02:00
// get all not cached entries, none of them should have a cached poster
2018-12-08 23:44:17 +01:00
ExecutorService executor = Executors . newFixedThreadPool ( 5 ) ;
2019-05-06 00:50:27 +02:00
2018-08-13 23:56:16 +02:00
for ( FilmTabelDataType entry : dbController . getAllNotCachedEntries ( ) ) {
2019-06-23 15:23:03 +02:00
// System.out.println(entry.getStreamUrl() + " is NOT cached!");
2019-05-06 00:50:27 +02:00
2019-06-22 21:04:43 +02:00
Runnable OMDbAPIWorker = new OMDbAPIController ( entry ) ;
2018-12-08 23:44:17 +01:00
executor . execute ( OMDbAPIWorker ) ;
2018-08-13 23:56:16 +02:00
}
2018-12-08 23:44:17 +01:00
executor . shutdown ( ) ;
2019-05-06 00:50:27 +02:00
2018-12-08 23:44:17 +01:00
// TODO show loading screen
2019-06-16 21:44:42 +02:00
2019-06-15 18:44:35 +02:00
// 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 ) ;
}
2019-06-22 21:04:43 +02:00
2019-05-15 17:14:15 +02:00
System . out . println ( " finished refresh " ) ;
2018-08-13 23:56:16 +02:00
}
2019-05-15 17:14:15 +02:00
/ * *
* add all cached films / series to the PosterMode GUI
* /
2019-06-21 21:16:53 +02:00
void addAllPosters ( ) {
2019-05-15 17:14:15 +02:00
// refresh the posterModeElements list
posterEmenents . clear ( ) ;
posterEmenents = dbController . getPosterElementsList ( ) ; // returns a list of all PosterElements stored in the database
2019-06-16 21:44:42 +02:00
// add button onAction
for ( PosterModeElement element : posterEmenents ) {
element . getButton ( ) . addEventHandler ( MouseEvent . MOUSE_CLICKED , ( event ) - > {
enableBlur ( ) ; // blur the FlowPane
// if the selected element is a file it's a film, else a series
2019-06-19 16:31:49 +02:00
if ( new File ( element . getStreamURL ( ) ) . isFile ( ) | | element . getStreamURL ( ) . contains ( " http " ) ) {
2019-06-16 21:44:42 +02:00
filmDetailViewController . setFilm ( element . getStreamURL ( ) ) ;
filmDetailViewController . showPane ( ) ;
} else {
2019-06-18 01:25:46 +02:00
seriesDetailViewController . setSeries ( element . getStreamURL ( ) ) ;
seriesDetailViewController . showPane ( ) ;
2019-06-16 21:44:42 +02:00
}
} ) ;
}
2019-06-15 11:09:59 +02:00
posterModeFlowPane . getChildren ( ) . clear ( ) ; // remove all GUIElements from the posterModeFlowPane
posterModeFlowPane . getChildren ( ) . addAll ( posterEmenents ) ; // add all films/series as new GUIElements to the posterModeFlowPane
2019-06-15 18:44:35 +02:00
System . out . println ( " added gui elements " ) ;
2019-05-15 17:14:15 +02:00
}
2019-06-16 21:44:42 +02:00
2019-06-21 21:16:53 +02:00
// TODO can this be done in dbController? with dbController.refreshDataBase();
2019-06-19 16:31:49 +02:00
/ * *
* check if the cache is to old , if so update asynchron
* /
private void checkCache ( ) {
ExecutorService executor = Executors . newFixedThreadPool ( 5 ) ;
2019-06-21 21:16:53 +02:00
for ( FilmTabelDataType entry : dbController . getStreamsList ( ) ) {
2019-06-19 16:31:49 +02:00
if ( dbController . getCacheDate ( entry . getStreamUrl ( ) ) . isBefore ( lastValidCache ) ) {
2019-06-23 15:23:03 +02:00
// System.out.println(entry.getTitle() + " chached on: " + dbController.getCacheDate(entry.getStreamUrl()));
2019-06-22 21:04:43 +02:00
Runnable OMDbAPIWorker = new OMDbAPIController ( entry ) ;
2019-06-19 16:31:49 +02:00
executor . execute ( OMDbAPIWorker ) ;
}
}
executor . shutdown ( ) ;
}
2019-06-16 21:44:42 +02:00
private void enableBlur ( ) {
BoxBlur boxBlur = new BoxBlur ( ) ;
boxBlur . setWidth ( 9 ) ;
boxBlur . setHeight ( 7 ) ;
boxBlur . setIterations ( 3 ) ;
posterModeFlowPane . setEffect ( boxBlur ) ;
}
public void disableBlur ( ) {
posterModeFlowPane . setEffect ( null ) ;
}
2017-01-26 16:32:47 +01:00
}