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.awt.Desktop ;
import java.io.BufferedReader ;
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 ;
import java.io.InputStreamReader ;
2018-03-04 20:07:43 +01:00
import java.io.Writer ;
2016-08-14 15:17:14 +02:00
import java.math.BigInteger ;
2018-04-05 12:09:39 +02:00
import java.net.URLConnection ;
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 ;
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 ;
import com.jfoenix.controls.JFXColorPicker ;
2017-06-07 01:42:18 +02:00
import com.jfoenix.controls.JFXHamburger ;
2016-08-14 15:17:14 +02:00
import com.jfoenix.controls.JFXSlider ;
import com.jfoenix.controls.JFXToggleButton ;
2017-06-07 01:42:18 +02:00
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 ;
import javafx.scene.control.ChoiceBox ;
import javafx.scene.control.Label ;
2017-03-05 18:29:24 +01:00
import javafx.scene.control.ScrollPane ;
2016-09-09 20:41:20 +02:00
import javafx.scene.control.TableColumn ;
import javafx.scene.control.TableView ;
2016-08-14 15:17:14 +02:00
import javafx.scene.control.TreeItem ;
2019-06-16 15:23:17 +02:00
import javafx.scene.effect.BoxBlur ;
2019-06-15 18:44:35 +02:00
import javafx.scene.control.ScrollPane.ScrollBarPolicy ;
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.scene.paint.Color ;
import javafx.scene.text.Font ;
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 ;
2018-03-05 22:37:32 +01:00
import kellerkinder.HomeFlix.datatypes.SourceDataType ;
2018-04-01 23:24:49 +02:00
import kellerkinder.HomeFlix.player.Player ;
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
@FXML private ScrollPane settingsScrollPane ;
2018-07-24 14:14:34 +02:00
@FXML private JFXButton updateBtn ;
@FXML private JFXButton addDirectoryBtn ;
@FXML private JFXButton addStreamSourceBtn ;
@FXML private JFXToggleButton autoUpdateToggleBtn ;
@FXML private JFXToggleButton autoplayToggleBtn ;
2018-03-01 23:18:40 +01:00
2018-07-24 14:14:34 +02:00
@FXML private JFXColorPicker colorPicker ;
2018-03-01 23:18:40 +01:00
2018-07-24 14:14:34 +02:00
@FXML private ChoiceBox < String > languageChoisBox = new ChoiceBox < > ( ) ;
@FXML private ChoiceBox < String > branchChoisBox = new ChoiceBox < > ( ) ;
2018-03-04 20:07:43 +01:00
2018-07-24 14:14:34 +02:00
@FXML private JFXSlider fontsizeSlider ;
2019-06-19 16:31:49 +02:00
2018-07-24 14:14:34 +02:00
@FXML private Label homeflixSettingsLbl ;
@FXML private Label mainColorLbl ;
@FXML private Label fontsizeLbl ;
@FXML private Label languageLbl ;
@FXML private Label updateLbl ;
@FXML private Label branchLbl ;
@FXML private Label sourcesLbl ;
@FXML private Label versionLbl ;
2018-04-13 11:11:25 +02:00
2019-06-19 16:31:49 +02:00
@FXML private TableView < SourceDataType > sourcesTable ;
2018-07-24 14:14:34 +02:00
@FXML private TreeItem < SourceDataType > sourceRoot = new TreeItem < > ( new SourceDataType ( " " , " " ) ) ;
@FXML private TableColumn < SourceDataType , String > sourceColumn ;
@FXML private TableColumn < SourceDataType , String > modeColumn ;
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 ;
2018-04-28 18:02:02 +02:00
private UpdateController updateController ;
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
2019-06-19 16:31:49 +02:00
private final String version = " 0.7.90 " ;
private final String buildNumber = " 171 " ;
2018-04-27 15:06:40 +02:00
private final String versionName = " toothless dragon " ;
2018-04-28 18:02:02 +02:00
private String btnStyle ;
2019-05-06 00:50:27 +02:00
2019-06-15 12:09:31 +02:00
private FilmTabelDataType currentTableFilm = new FilmTabelDataType ( " " , " " , " " , " " , false , null ) ;
2019-05-06 00:50:27 +02:00
2018-03-01 23:18:40 +01:00
private ObservableList < String > languages = FXCollections . observableArrayList ( " English (en_US) " , " Deutsch (de_DE) " ) ;
private ObservableList < String > branches = FXCollections . observableArrayList ( " stable " , " beta " ) ;
2018-03-07 23:51:02 +01:00
private ObservableList < FilmTabelDataType > filmsList = FXCollections . observableArrayList ( ) ;
2019-05-15 17:14:15 +02:00
private ObservableList < PosterModeElement > posterEmenents = FXCollections . observableArrayList ( ) ;
2019-01-12 23:07:25 +01:00
private static ObservableList < SourceDataType > sourcesList = 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
@FXML
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 ( ) ;
2016-08-14 15:17:14 +02:00
}
2019-05-06 00:50:27 +02:00
public void init ( ) {
2018-04-18 21:04:14 +02:00
LOGGER . info ( " Initializing Project-HomeFlix build " + buildNumber ) ;
2019-05-06 00:50:27 +02:00
2019-01-08 17:10:33 +01:00
xmlController . loadSettings ( ) ; // load settings
2018-03-01 15:42:47 +01:00
checkAutoUpdate ( ) ;
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
2018-03-01 15:42:47 +01:00
initTabel ( ) ;
2018-03-04 20:07:43 +01:00
initUI ( ) ;
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
2019-01-12 23:07:25 +01:00
addSourceToTable ( ) ;
2019-06-19 16:31:49 +02:00
posterModeStartup ( ) ;
2018-10-11 12:29:26 +02:00
}
2019-05-06 00:50:27 +02:00
2018-07-22 23:30:52 +02:00
// Initialize general UI elements
2018-04-28 18:02:02 +02:00
private void initUI ( ) {
2019-06-15 18:44:35 +02:00
//JFXScrollPane.smoothScrolling(posterModeScrollPane);
posterModeScrollPane . setVbarPolicy ( ScrollBarPolicy . ALWAYS ) ;
settingsScrollPane . setVbarPolicy ( ScrollBarPolicy . ALWAYS ) ;
2018-04-28 18:02:02 +02:00
versionLbl . setText ( " Version: " + version + " (Build: " + buildNumber + " ) " ) ;
2019-01-08 17:10:33 +01:00
fontsizeSlider . setValue ( XMLController . getFontSize ( ) ) ;
colorPicker . setValue ( Color . valueOf ( XMLController . getColor ( ) ) ) ;
2018-04-28 18:02:02 +02:00
updateBtn . setFont ( Font . font ( " System " , 12 ) ) ;
2019-01-08 17:10:33 +01:00
autoUpdateToggleBtn . setSelected ( XMLController . isAutoUpdate ( ) ) ;
autoplayToggleBtn . setSelected ( XMLController . isAutoplay ( ) ) ;
2018-04-28 18:02:02 +02:00
languageChoisBox . setItems ( languages ) ;
branchChoisBox . setItems ( branches ) ;
2019-05-06 00:50:27 +02:00
2019-01-08 17:10:33 +01:00
if ( XMLController . isUseBeta ( ) ) {
2018-04-28 18:02:02 +02:00
branchChoisBox . getSelectionModel ( ) . select ( 1 ) ;
} else {
branchChoisBox . getSelectionModel ( ) . select ( 0 ) ;
}
2019-05-06 00:50:27 +02:00
2018-04-28 18:02:02 +02:00
setLocalUI ( ) ;
applyColor ( ) ;
}
2019-05-06 00:50:27 +02:00
2018-07-22 23:30:52 +02:00
/ * *
2019-05-06 00:50:27 +02:00
* Initialize the tables ( treeTableViewfilm and sourcesTable ) only needed for
* Tabel - Mode
2018-07-22 23:30:52 +02:00
* /
2018-03-01 16:10:37 +01:00
private void initTabel ( ) {
2018-04-08 13:30:55 +02:00
// sourcesTreeTable
sourceColumn . setCellValueFactory ( cellData - > cellData . getValue ( ) . pathProperty ( ) ) ;
modeColumn . setCellValueFactory ( cellData - > cellData . getValue ( ) . modeProperty ( ) ) ;
sourcesTable . setItems ( sourcesList ) ;
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 ) - > {
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-01-14 20:45:49 +01:00
if ( settingsScrollPane . isVisible ( ) ) {
2018-03-01 23:18:40 +01:00
settingsScrollPane . setVisible ( false ) ;
2017-06-07 01:42:18 +02:00
}
} ) ;
2019-05-06 00:50:27 +02:00
languageChoisBox . getSelectionModel ( ) . selectedIndexProperty ( ) . addListener ( ( e , oldValue , newValue ) - > {
String local = languageChoisBox . getItems ( ) . get ( ( int ) newValue ) . toString ( ) ;
local = local . substring ( local . length ( ) - 6 , local . length ( ) - 1 ) ; // reading only en_US from English (en_US)
XMLController . setUsrLocal ( local ) ;
setLocalUI ( ) ;
xmlController . saveSettings ( ) ;
2018-03-04 20:07:43 +01:00
} ) ;
2019-05-06 00:50:27 +02:00
branchChoisBox . getSelectionModel ( ) . selectedIndexProperty ( ) . addListener ( ( e , oldValue , newValue ) - > {
if ( branchChoisBox . getItems ( ) . get ( ( int ) newValue ) . toString ( ) = = " beta " ) {
XMLController . setUseBeta ( true ) ;
} else {
XMLController . setUseBeta ( false ) ;
2018-03-01 23:18:40 +01:00
}
2019-05-06 00:50:27 +02:00
xmlController . saveSettings ( ) ;
2018-03-01 23:18:40 +01:00
} ) ;
2019-05-06 00:50:27 +02:00
fontsizeSlider . valueProperty ( ) . addListener ( e - > {
XMLController . setFontSize ( fontsizeSlider . getValue ( ) ) ;
2019-06-19 16:31:49 +02:00
// TODO add functionality for postermode
xmlController . saveSettings ( ) ;
2018-03-04 20:07:43 +01:00
} ) ;
2019-05-06 00:50:27 +02:00
2018-07-22 23:30:52 +02:00
// Poster-Mode actions
2016-09-09 20:41:20 +02:00
}
2019-05-06 00:50:27 +02:00
2018-07-22 23:30:52 +02:00
// Table-Mode fxml actions
2018-03-01 16:10:37 +01:00
@FXML
2018-04-14 16:14:10 +02:00
private void playbtnclicked ( ) {
2019-01-22 18:12:30 +01:00
if ( currentTableFilm . getStreamUrl ( ) . length ( ) > 0 ) {
if ( currentTableFilm . getStreamUrl ( ) . contains ( " _rootNode " ) ) {
LOGGER . info ( " rootNode found, getting last watched episode " ) ;
currentTableFilm = dbController . getLastWatchedEpisode ( currentTableFilm . getTitle ( ) ) ;
}
2019-05-06 00:50:27 +02:00
2019-01-22 18:12:30 +01:00
if ( isSupportedFormat ( currentTableFilm ) ) {
2019-06-17 00:44:44 +02:00
new Player ( getCurrentStreamUrl ( ) ) ;
2019-01-22 18:12:30 +01:00
} else {
LOGGER . error ( " using fallback player! " ) ;
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 ( " which vlc: " + output ) ;
input . close ( ) ;
} catch ( IOException e1 ) {
e1 . printStackTrace ( ) ;
2018-04-01 23:24:49 +02:00
}
2019-01-22 18:12:30 +01:00
if ( output . contains ( " which: no vlc " ) | | output = = " " ) {
JFXInfoAlert vlcInfoAlert = new JFXInfoAlert ( " Info " ,
2019-05-06 00:50:27 +02:00
XMLController . getLocalBundle ( ) . getString ( " vlcNotInstalled " ) , btnStyle , primaryStage ) ;
2019-01-22 18:12:30 +01:00
vlcInfoAlert . showAndWait ( ) ;
} else {
try {
new ProcessBuilder ( " vlc " , getCurrentStreamUrl ( ) ) . start ( ) ;
} catch ( IOException e ) {
LOGGER . warn ( " An error has occurred while opening the file! " , e ) ;
}
}
} else if ( System . getProperty ( " os.name " ) . contains ( " Windows " ) | | System . getProperty ( " os.name " ) . contains ( " Mac OS X " ) ) {
2018-04-01 23:24:49 +02:00
try {
2019-01-22 18:12:30 +01:00
Desktop . getDesktop ( ) . open ( new File ( getCurrentStreamUrl ( ) ) ) ;
2018-04-19 12:13:18 +02:00
} catch ( IOException e ) {
LOGGER . warn ( " An error has occurred while opening the file! " , e ) ;
2018-04-01 23:24:49 +02:00
}
2019-01-22 18:12:30 +01:00
} else {
LOGGER . error ( System . getProperty ( " os.name " ) + " , OS is not supported, please contact a developer! " ) ;
2018-04-01 23:24:49 +02:00
}
2018-03-07 00:20:14 +01:00
}
2018-04-03 18:03:43 +02:00
}
}
2019-06-16 21:44:42 +02:00
2018-03-01 16:10:37 +01:00
@FXML
2018-03-04 20:19:46 +01:00
private void openfolderbtnclicked ( ) {
2019-01-14 20:45:49 +01:00
File dest = new File ( getCurrentStreamUrl ( ) ) . getParentFile ( ) ;
2019-05-06 00:50:27 +02:00
2018-03-04 20:19:46 +01:00
if ( ! System . getProperty ( " os.name " ) . contains ( " Linux " ) ) {
try {
2019-01-14 20:45:49 +01:00
Desktop . getDesktop ( ) . open ( dest ) ;
2018-03-04 20:19:46 +01:00
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
2018-03-01 16:10:37 +01: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-05-06 00:50:27 +02:00
String bodyText = " Project HomeFlix \ nVersion: " + version + " (Build: " + buildNumber + " ) \" " + 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-05-06 17:26:19 +02:00
settingsScrollPane . setVisible ( ! settingsScrollPane . isVisible ( ) ) ;
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
2019-05-06 00:50:27 +02:00
private void addDirectoryBtnAction ( ) {
2018-03-29 11:26:20 +02:00
DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
2019-01-09 22:36:50 +01:00
directoryChooser . setTitle ( XMLController . getLocalBundle ( ) . getString ( " addDirectory " ) ) ;
2019-01-08 19:02:00 +01:00
File selectedFolder = directoryChooser . showDialog ( primaryStage ) ;
2018-03-04 20:07:43 +01:00
if ( selectedFolder ! = null & & selectedFolder . exists ( ) ) {
2018-12-04 22:31:11 +01:00
addSource ( selectedFolder . getPath ( ) , " local " ) ;
2018-03-04 20:07:43 +01:00
} else {
LOGGER . error ( " The selected folder dosen't exist! " ) ;
}
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
2019-05-06 00:50:27 +02:00
private void addStreamSourceBtnAction ( ) {
2018-03-04 20:07:43 +01:00
FileChooser fileChooser = new FileChooser ( ) ;
2019-01-09 22:36:50 +01:00
fileChooser . setTitle ( XMLController . getLocalBundle ( ) . getString ( " addStreamSource " ) ) ;
2019-01-08 19:02:00 +01:00
File selectedFile = fileChooser . showOpenDialog ( primaryStage ) ;
2018-03-04 20:07:43 +01:00
if ( selectedFile ! = null & & selectedFile . exists ( ) ) {
2018-03-05 12:14:54 +01:00
addSource ( selectedFile . getPath ( ) , " stream " ) ;
2018-03-04 20:07:43 +01:00
} else {
LOGGER . error ( " The selected file dosen't exist! " ) ;
}
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-04-28 12:53:44 +02:00
private void colorPickerAction ( ) {
2019-01-08 17:10:33 +01:00
XMLController . setColor ( colorPicker . getValue ( ) . toString ( ) . substring ( 2 , 10 ) ) ;
xmlController . saveSettings ( ) ;
2018-03-01 16:10:37 +01:00
applyColor ( ) ;
}
2019-05-06 00:50:27 +02:00
2018-03-01 16:10:37 +01:00
@FXML
2018-04-28 12:53:44 +02:00
private void updateBtnAction ( ) {
2019-01-08 17:10:33 +01:00
updateController = new UpdateController ( this , buildNumber , XMLController . isUseBeta ( ) ) ;
2018-03-01 16:10:37 +01:00
Thread updateThread = new Thread ( updateController ) ;
updateThread . setName ( " Updater " ) ;
2019-05-06 00:50:27 +02:00
updateThread . start ( ) ;
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
2019-01-08 17:10:33 +01:00
private void autoUpdateToggleBtnAction ( ) {
XMLController . setAutoUpdate ( ! XMLController . isAutoUpdate ( ) ) ;
xmlController . saveSettings ( ) ;
2018-03-01 16:10:37 +01:00
}
2019-05-06 00:50:27 +02:00
2018-04-07 17:14:35 +02:00
@FXML
2019-05-06 00:50:27 +02:00
private void autoplayToggleBtnAction ( ) {
2019-01-08 17:10:33 +01:00
XMLController . setAutoplay ( ! XMLController . isAutoplay ( ) ) ;
xmlController . saveSettings ( ) ;
2018-04-07 17:14:35 +02:00
}
2019-05-06 00:50:27 +02:00
2019-01-14 18:44:36 +01:00
/ * *
2019-05-06 00:50:27 +02:00
* refresh all films in filmsList and in filmsTable clear the FilmsList and
* FilmRoot children , then update the database
2019-01-14 18:44:36 +01:00
* /
private void refreshAllFilms ( ) {
2019-01-14 20:45:49 +01:00
filmsList . clear ( ) ;
2019-01-14 18:44:36 +01:00
dbController . refreshDataBase ( ) ; // refreshes the database after a source path was added
2019-05-15 17:14:15 +02:00
filmsList = dbController . getStreamsList ( ) ; // returns a list of all films stored in the database
2016-08-14 15:17:14 +02:00
}
2019-05-06 00:50:27 +02:00
2019-01-12 23:07:25 +01:00
// add a all elements of sourcesList to the sources table on the settings pane
public void addSourceToTable ( ) {
2019-05-06 00:50:27 +02:00
for ( SourceDataType source : sourcesList ) {
sourceRoot . getChildren ( ) . add ( new TreeItem < SourceDataType > ( source ) ) ; // add data to root-node
2019-01-12 23:07:25 +01: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
/ * *
* add a source to the newsources list
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 )
* /
2018-03-04 20:07:43 +01:00
public void addSource ( String path , String mode ) {
JsonArray newsources = null ;
try {
// read old array
2019-01-08 17:10:33 +01:00
File oldSources = new File ( XMLController . getDirHomeFlix ( ) + " /sources.json " ) ;
2018-03-13 18:08:30 +01:00
if ( oldSources . exists ( ) ) {
2019-01-08 17:10:33 +01:00
newsources = Json . parse ( new FileReader ( XMLController . getDirHomeFlix ( ) + " /sources.json " ) ) . asArray ( ) ;
2018-03-13 18:08:30 +01:00
} else {
newsources = 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 ) {
LOGGER . error ( e ) ;
}
2019-05-06 00:50:27 +02:00
2018-12-04 22:31:11 +01:00
// clear old sources list/table
getSourcesList ( ) . clear ( ) ;
2019-01-14 20:45:49 +01:00
sourceRoot . getChildren ( ) . clear ( ) ;
2019-05-06 00:50:27 +02:00
refreshAllFilms ( ) ; // refresh the FilmsList
2019-01-09 22:36:50 +01:00
checkAllPosters ( ) ; // check if there is anything to cache
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
* /
2018-03-01 16:10:37 +01:00
private 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
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; " ;
2019-05-06 00:50:27 +02:00
2018-04-28 12:53:44 +02:00
menuHam . getStyleClass ( ) . clear ( ) ;
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; " ;
2019-05-06 00:50:27 +02:00
2018-04-28 12:53:44 +02:00
menuHam . getStyleClass ( ) . clear ( ) ;
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
// normal buttons
addDirectoryBtn . setStyle ( btnStyle ) ;
addStreamSourceBtn . setStyle ( btnStyle ) ;
updateBtn . setStyle ( btnStyle ) ;
2019-05-06 00:50:27 +02:00
2018-04-28 18:02:02 +02:00
// menu buttons
settingsBtn . setStyle ( menuBtnStyle ) ;
aboutBtn . setStyle ( menuBtnStyle ) ;
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
sideMenuVBox . setVisible ( true ) ;
TranslateTransition translateTransition = new TranslateTransition ( Duration . millis ( 400 ) , sideMenuVBox ) ;
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-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 ) ;
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-04-02 18:29:59 +02:00
/ * *
* set the local based on the languageChoisBox selection
* /
2019-01-14 18:44:36 +01:00
private void setLocalUI ( ) {
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
2018-03-01 23:18:40 +01:00
languageChoisBox . getSelectionModel ( ) . select ( 0 ) ;
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
2018-03-01 23:18:40 +01:00
languageChoisBox . getSelectionModel ( ) . select ( 1 ) ;
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
2018-03-01 23:18:40 +01:00
languageChoisBox . getSelectionModel ( ) . select ( 0 ) ;
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
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 " ) ) ;
updateBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " checkUpdates " ) ) ;
addDirectoryBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " addDirectory " ) ) ;
addStreamSourceBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " addStreamSource " ) ) ;
homeflixSettingsLbl . setText ( XMLController . getLocalBundle ( ) . getString ( " homeflixSettingsLbl " ) ) ;
mainColorLbl . setText ( XMLController . getLocalBundle ( ) . getString ( " mainColorLbl " ) ) ;
fontsizeLbl . setText ( XMLController . getLocalBundle ( ) . getString ( " fontsizeLbl " ) ) ;
languageLbl . setText ( XMLController . getLocalBundle ( ) . getString ( " languageLbl " ) ) ;
autoUpdateToggleBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " autoUpdate " ) ) ;
autoplayToggleBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " autoplay " ) ) ;
branchLbl . setText ( XMLController . getLocalBundle ( ) . getString ( " branchLbl " ) ) ;
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-01-08 17:10:33 +01:00
if ( XMLController . isAutoUpdate ( ) ) {
2018-03-01 15:42:47 +01:00
try {
LOGGER . info ( " AutoUpdate: looking for updates on startup ... " ) ;
2019-01-08 17:10:33 +01:00
updateController = new UpdateController ( this , buildNumber , XMLController . isUseBeta ( ) ) ;
2018-03-01 15:42:47 +01:00
Thread updateThread = new Thread ( updateController ) ;
updateThread . setName ( " Updater " ) ;
updateThread . start ( ) ;
updateThread . join ( ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
}
}
}
2019-05-06 00:50:27 +02:00
2018-04-28 12:53:44 +02:00
/ * *
2019-05-06 00:50:27 +02:00
* check if a film is supported by the HomeFlixPlayer or not this is the case if
* the mime type is mp4
*
2018-04-28 12:53:44 +02:00
* @param entry the film you want to check
* @return true if so , false if not
* /
private boolean isSupportedFormat ( FilmTabelDataType film ) {
2019-05-06 00:50:27 +02:00
String mimeType = URLConnection . guessContentTypeFromName ( film . getStreamUrl ( ) ) ;
return mimeType ! = null & & ( mimeType . contains ( " mp4 " ) | | mimeType . contains ( " vp6 " ) ) ;
2016-09-09 20:41:20 +02:00
}
2019-05-06 00:50:27 +02:00
2019-01-22 18:12:30 +01:00
/ * *
* Poser Mode WIP
* /
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
* /
private void checkAllPosters ( ) {
// 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 ( ) ) {
System . out . println ( entry . getStreamUrl ( ) + " is NOT cached! " ) ;
2019-05-06 00:50:27 +02:00
2019-06-19 16:31:49 +02:00
Runnable OMDbAPIWorker = new OMDbAPIController ( entry , XMLController . getOmdbAPIKey ( ) ) ;
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-05-06 00:50:27 +02:00
2019-01-14 18:44:36 +01:00
// update all elements from the database
refreshAllFilms ( ) ;
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-19 16:31:49 +02:00
private 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
2019-06-19 16:31:49 +02:00
System . out . println ( " selected: " + element . getStreamURL ( ) ) ;
2019-06-16 21:44:42 +02:00
// 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-19 16:31:49 +02:00
// TODO can this be done in dbController?
/ * *
* check if the cache is to old , if so update asynchron
* /
private void checkCache ( ) {
ExecutorService executor = Executors . newFixedThreadPool ( 5 ) ;
// TODO if filmlist is not used anymore, it cann be removed
for ( FilmTabelDataType entry : filmsList ) {
if ( dbController . getCacheDate ( entry . getStreamUrl ( ) ) . isBefore ( lastValidCache ) ) {
System . out . println ( entry . getTitle ( ) + " chached on: " + dbController . getCacheDate ( entry . getStreamUrl ( ) ) ) ;
Runnable OMDbAPIWorker = new OMDbAPIController ( entry , XMLController . getOmdbAPIKey ( ) ) ;
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 ) ;
}
2018-02-24 17:13:52 +01:00
// getter and setter
2019-05-06 00:50:27 +02:00
2018-04-07 17:14:35 +02:00
public FilmTabelDataType getCurrentTableFilm ( ) {
return currentTableFilm ;
}
2016-09-09 20:41:20 +02:00
2018-04-06 20:33:56 +02:00
public String getCurrentTitle ( ) {
return currentTableFilm . getTitle ( ) ;
2018-03-08 17:59:28 +01:00
}
2018-04-06 20:33:56 +02:00
public String getCurrentStreamUrl ( ) {
return currentTableFilm . getStreamUrl ( ) ;
2018-03-08 17:59:28 +01:00
}
2019-01-12 23:07:25 +01:00
public static ObservableList < SourceDataType > getSourcesList ( ) {
2018-03-04 20:07:43 +01:00
return sourcesList ;
2017-09-16 18:22:46 +02:00
}
2018-03-01 15:42:47 +01:00
public JFXButton getUpdateBtn ( ) {
return updateBtn ;
}
2017-01-26 16:32:47 +01:00
}