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 ;
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.JFXTextField ;
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 ;
2019-01-14 18:44:36 +01:00
import javafx.application.Platform ;
2016-08-14 15:17:14 +02:00
import javafx.beans.value.ChangeListener ;
import javafx.beans.value.ObservableValue ;
import javafx.collections.FXCollections ;
import javafx.collections.ObservableList ;
2017-01-06 00:04:07 +01:00
import javafx.event.ActionEvent ;
import javafx.event.EventHandler ;
2016-08-14 15:17:14 +02:00
import javafx.fxml.FXML ;
2019-01-14 18:44:36 +01:00
import javafx.scene.Node ;
2016-08-14 15:17:14 +02:00
import javafx.scene.control.ChoiceBox ;
2017-01-06 00:04:07 +01:00
import javafx.scene.control.ContextMenu ;
2016-08-14 15:17:14 +02:00
import javafx.scene.control.Label ;
2017-01-06 00:04:07 +01:00
import javafx.scene.control.MenuItem ;
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 ;
import javafx.scene.control.TreeTableColumn ;
2017-03-05 18:29:24 +01:00
import javafx.scene.control.TreeTableColumn.SortType ;
2016-08-14 15:17:14 +02:00
import javafx.scene.control.TreeTableView ;
import javafx.scene.image.Image ;
import javafx.scene.image.ImageView ;
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 ;
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 ;
2019-01-14 18:44:36 +01:00
import javafx.scene.text.FontWeight ;
import javafx.scene.text.Text ;
2017-03-05 18:29:24 +01:00
import javafx.scene.text.TextFlow ;
2016-08-14 15:17:14 +02:00
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 ;
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
2018-07-24 14:14:34 +02:00
// general/settings fxml elements
@FXML private AnchorPane mainAnchorPane ;
@FXML private ScrollPane settingsScrollPane ;
2018-04-07 17:14:35 +02:00
2018-07-24 14:14:34 +02:00
@FXML private JFXHamburger menuHam ;
@FXML private HBox topHBox ;
@FXML private VBox sideMenuVBox ;
@FXML private TableView < SourceDataType > sourcesTable ;
2018-03-01 23:18:40 +01:00
2018-07-24 14:14:34 +02:00
@FXML private JFXButton aboutBtn ;
@FXML private JFXButton settingsBtn ;
@FXML private JFXButton updateBtn ;
@FXML private JFXButton addDirectoryBtn ;
@FXML private JFXButton addStreamSourceBtn ;
2018-03-01 23:18:40 +01:00
2018-07-24 14:14:34 +02:00
@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 ;
2018-03-01 23:18:40 +01: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
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 ;
// table-mode
@FXML private AnchorPane tableModeAnchorPane ;
@FXML private JFXTextField searchTextField ;
@FXML private TreeTableView < FilmTabelDataType > filmsTreeTable ;
2019-01-22 18:12:30 +01:00
@FXML private TreeTableColumn < FilmTabelDataType , String > columnStreamUrl ;
@FXML private TreeTableColumn < FilmTabelDataType , String > columnTitle ;
@FXML private TreeTableColumn < FilmTabelDataType , ImageView > columnFavorite ;
@FXML private TreeTableColumn < FilmTabelDataType , String > columnSeason ;
@FXML private TreeTableColumn < FilmTabelDataType , String > columnEpisode ;
2019-01-22 17:29:56 +01:00
@FXML private TreeItem < FilmTabelDataType > filmRoot = new TreeItem < > ( new FilmTabelDataType ( " " , " " , " " , " " , false , null , null ) ) ;
2019-01-12 23:07:25 +01:00
2018-07-24 14:14:34 +02:00
@FXML private ScrollPane textScrollPane ;
@FXML private TextFlow textFlow ;
@FXML private ImageView posterImageView ;
@FXML private JFXButton playbtn ;
@FXML private JFXButton openfolderbtn ;
@FXML private JFXButton returnBtn ;
@FXML private JFXButton forwardBtn ;
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 AnchorPane posterModeAnchorPane ;
@FXML private ScrollPane posterModeScrollPane ;
2018-04-28 18:02:02 +02:00
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 ( ) ) ;
2018-03-01 16:10:37 +01:00
private boolean menuTrue = false ;
2018-04-08 13:30:55 +02:00
2018-04-27 15:06:40 +02:00
private final String version = " 0.7.0 " ;
2019-01-09 22:36:50 +01:00
private final String buildNumber = " 169 " ;
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 ;
2018-03-01 15:42:47 +01:00
2018-04-28 18:02:02 +02:00
private final int hashA = - 647380320 ;
2016-08-14 15:17:14 +02:00
private int last ;
2018-03-08 17:59:28 +01:00
private int indexTable ;
private int indexList ;
2016-08-14 15:17:14 +02:00
private int next ;
2019-01-22 17:29:56 +01:00
private FilmTabelDataType currentTableFilm = new FilmTabelDataType ( " " , " " , " " , " " , false , null , null ) ;
2018-04-03 18:03:43 +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 > filterData = FXCollections . observableArrayList ( ) ;
private ObservableList < FilmTabelDataType > filmsList = FXCollections . observableArrayList ( ) ;
2019-01-12 23:07:25 +01:00
private static ObservableList < SourceDataType > sourcesList = FXCollections . observableArrayList ( ) ;
2018-04-07 17:26:56 +02:00
private MenuItem like = new MenuItem ( " like " ) ;
private MenuItem dislike = new MenuItem ( " dislike " ) ; // TODO one option (like or dislike)
2017-02-09 20:39:43 +01:00
private ContextMenu menu = new ContextMenu ( like , dislike ) ;
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
}
@FXML
public void initialize ( ) {
xmlController = new XMLController ( ) ;
2019-01-14 18:44:36 +01:00
dbController = DBController . getInstance ( ) ;
2016-08-14 15:17:14 +02:00
}
2018-10-11 12:29:26 +02:00
public void init ( ) {
2018-04-18 21:04:14 +02:00
LOGGER . info ( " Initializing Project-HomeFlix build " + buildNumber ) ;
2018-10-11 12:29:26 +02:00
2019-01-08 17:10:33 +01:00
xmlController . loadSettings ( ) ; // load settings
2018-03-01 15:42:47 +01:00
checkAutoUpdate ( ) ;
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-01-14 18:44:36 +01:00
refreshAllFilms ( ) ;
2018-08-13 23:56:16 +02:00
2019-01-12 23:07:25 +01:00
// load sources list in gui
addSourceToTable ( ) ;
2019-01-22 18:12:30 +01:00
// posterModeStartup(); // TODO testing DO NOT USE THIS!!
2018-10-11 12:29:26 +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 ( ) {
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-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 ) ;
}
setLocalUI ( ) ;
applyColor ( ) ;
}
2018-07-22 23:30:52 +02:00
/ * *
* Initialize the tables ( treeTableViewfilm and sourcesTable )
* only needed for Tabel - Mode
* /
2018-03-01 16:10:37 +01:00
private void initTabel ( ) {
2016-08-14 15:17:14 +02:00
2018-03-05 22:37:32 +01:00
// film Table
2018-03-07 23:51:02 +01:00
filmsTreeTable . setRoot ( filmRoot ) ;
filmsTreeTable . setColumnResizePolicy ( TreeTableView . CONSTRAINED_RESIZE_POLICY ) ;
filmsTreeTable . setShowRoot ( false ) ;
2018-03-05 22:37:32 +01:00
// write content into cell
columnStreamUrl . setCellValueFactory ( cellData - > cellData . getValue ( ) . getValue ( ) . streamUrlProperty ( ) ) ;
2018-03-08 17:59:28 +01:00
columnTitle . setCellValueFactory ( cellData - > cellData . getValue ( ) . getValue ( ) . titleProperty ( ) ) ;
2018-03-09 20:12:03 +01:00
columnSeason . setCellValueFactory ( cellData - > cellData . getValue ( ) . getValue ( ) . seasonProperty ( ) ) ;
columnEpisode . setCellValueFactory ( cellData - > cellData . getValue ( ) . getValue ( ) . episodeProperty ( ) ) ;
columnFavorite . setCellValueFactory ( cellData - > cellData . getValue ( ) . getValue ( ) . imageProperty ( ) ) ;
2018-03-05 22:37:32 +01:00
2018-04-08 13:30:55 +02:00
// context menu for treeTableViewfilm
2018-03-07 23:51:02 +01:00
filmsTreeTable . setContextMenu ( menu ) ;
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
}
} ) ;
2016-10-09 18:35:55 +02:00
2018-03-04 20:07:43 +01:00
languageChoisBox . getSelectionModel ( ) . selectedIndexProperty ( ) . addListener ( new ChangeListener < Number > ( ) {
@Override
public void changed ( ObservableValue < ? extends Number > ov , Number value , Number new_value ) {
String local = languageChoisBox . getItems ( ) . get ( ( int ) new_value ) . toString ( ) ;
local = local . substring ( local . length ( ) - 6 , local . length ( ) - 1 ) ; // reading only en_US from English (en_US)
2019-01-08 17:10:33 +01:00
XMLController . setUsrLocal ( local ) ;
2018-03-04 20:07:43 +01:00
setLocalUI ( ) ;
2019-01-08 17:10:33 +01:00
xmlController . saveSettings ( ) ;
2018-03-04 20:07:43 +01:00
}
} ) ;
branchChoisBox . getSelectionModel ( ) . selectedIndexProperty ( ) . addListener ( new ChangeListener < Number > ( ) {
2018-03-01 23:18:40 +01:00
@Override
public void changed ( ObservableValue < ? extends Number > ov , Number value , Number new_value ) {
if ( branchChoisBox . getItems ( ) . get ( ( int ) new_value ) . toString ( ) = = " beta " ) {
2019-01-08 17:10:33 +01:00
XMLController . setUseBeta ( true ) ;
2018-03-01 23:18:40 +01:00
} else {
2019-01-08 17:10:33 +01:00
XMLController . setUseBeta ( false ) ;
2018-03-01 23:18:40 +01:00
}
2019-01-08 17:10:33 +01:00
xmlController . saveSettings ( ) ;
2018-03-01 23:18:40 +01:00
}
} ) ;
2018-03-04 20:07:43 +01:00
fontsizeSlider . valueProperty ( ) . addListener ( new ChangeListener < Number > ( ) {
@Override
public void changed ( ObservableValue < ? extends Number > ov , Number old_val , Number new_val ) {
2019-01-08 17:10:33 +01:00
XMLController . setFontSize ( fontsizeSlider . getValue ( ) ) ;
2018-04-06 20:33:56 +02:00
if ( ! getCurrentTitle ( ) . isEmpty ( ) ) {
2019-01-14 18:44:36 +01:00
setSelectedFilmInfo ( dbController . readCache ( getCurrentStreamUrl ( ) ) ) ;
2017-03-09 22:26:37 +01:00
}
2019-01-08 17:10:33 +01:00
xmlController . saveSettings ( ) ;
2018-03-04 20:07:43 +01:00
}
} ) ;
2017-01-06 00:04:07 +01:00
2018-07-22 23:30:52 +02:00
// Table-Mode actions
searchTextField . textProperty ( ) . addListener ( new ChangeListener < String > ( ) {
@Override
public void changed ( ObservableValue < ? extends String > observable , String oldValue , String newValue ) {
ObservableList < FilmTabelDataType > helpData ;
filterData . clear ( ) ;
filmRoot . getChildren ( ) . clear ( ) ;
helpData = filmsList ;
for ( int i = 0 ; i < helpData . size ( ) ; i + + ) {
if ( helpData . get ( i ) . getTitle ( ) . toLowerCase ( ) . contains ( searchTextField . getText ( ) . toLowerCase ( ) ) ) {
filterData . add ( helpData . get ( i ) ) ; // add data from newDaten to filteredData where title contains search input
}
}
for ( int i = 0 ; i < filterData . size ( ) ; i + + ) {
filmRoot . getChildren ( ) . add ( new TreeItem < FilmTabelDataType > ( filterData . get ( i ) ) ) ; // add filtered data to root node after search
}
if ( searchTextField . getText ( ) . hashCode ( ) = = hashA ) {
2019-01-08 17:10:33 +01:00
XMLController . setColor ( " 000000 " ) ;
2018-07-22 23:30:52 +02:00
colorPicker . setValue ( new Color ( 0 , 0 , 0 , 1 ) ) ;
applyColor ( ) ;
}
}
} ) ;
2018-03-04 20:07:43 +01:00
like . setOnAction ( new EventHandler < ActionEvent > ( ) {
@Override
public void handle ( ActionEvent event ) {
2018-04-06 20:33:56 +02:00
dbController . like ( getCurrentStreamUrl ( ) ) ;
2019-01-14 18:44:36 +01:00
filmsList . set ( indexList , dbController . getDatabaseFilm ( getCurrentStreamUrl ( ) ) ) ;
2018-04-28 18:02:02 +02:00
refreshTableElement ( ) ;
2016-09-09 20:41:20 +02:00
}
2018-03-04 20:07:43 +01:00
} ) ;
2017-01-06 00:04:07 +01:00
2018-03-04 20:07:43 +01:00
dislike . setOnAction ( new EventHandler < ActionEvent > ( ) {
@Override
public void handle ( ActionEvent event ) {
2018-04-06 20:33:56 +02:00
dbController . dislike ( getCurrentStreamUrl ( ) ) ;
2019-01-14 18:44:36 +01:00
filmsList . set ( indexList , dbController . getDatabaseFilm ( getCurrentStreamUrl ( ) ) ) ;
2018-04-28 18:02:02 +02:00
refreshTableElement ( ) ;
2016-09-09 20:41:20 +02:00
}
2018-03-04 20:07:43 +01:00
} ) ;
2017-03-05 18:29:24 +01:00
2018-03-04 20:07:43 +01:00
/ * *
* FIXME fix bug when sort by ASCENDING , wrong order
* /
2018-03-09 20:12:03 +01:00
columnFavorite . sortTypeProperty ( ) . addListener ( new ChangeListener < SortType > ( ) {
2018-03-04 20:07:43 +01:00
@Override
2018-03-05 22:37:32 +01:00
public void changed ( ObservableValue < ? extends SortType > paramObservableValue , SortType paramT1 , SortType paramT2 ) {
2018-04-06 20:33:56 +02:00
filmRoot . getChildren ( ) . clear ( ) ;
2018-04-07 12:49:00 +02:00
filterData . clear ( ) ;
2018-04-06 20:33:56 +02:00
if ( paramT2 . equals ( SortType . DESCENDING ) ) {
2018-06-13 13:50:21 +02:00
// add favorites at the top
2018-04-06 20:33:56 +02:00
for ( FilmTabelDataType film : filmsList ) {
if ( film . getFavorite ( ) ) {
2018-04-07 12:49:00 +02:00
filterData . add ( 0 , film ) ;
2018-04-06 20:33:56 +02:00
} else {
2018-04-07 12:49:00 +02:00
filterData . add ( film ) ;
2018-04-06 20:33:56 +02:00
}
2018-03-04 20:07:43 +01:00
}
} else {
2018-06-13 13:50:21 +02:00
// add favorites at the bottom
2018-04-06 20:33:56 +02:00
for ( FilmTabelDataType film : filmsList ) {
if ( ! film . getFavorite ( ) ) {
2018-04-07 12:49:00 +02:00
filterData . add ( 0 , film ) ;
2018-04-06 20:33:56 +02:00
} else {
2018-04-07 12:49:00 +02:00
filterData . add ( film ) ;
2018-04-06 20:33:56 +02:00
}
2018-03-04 20:07:43 +01:00
}
}
2018-04-07 12:49:00 +02:00
2018-05-09 22:55:32 +02:00
addFilmsToTable ( filterData ) ;
2018-03-04 20:07:43 +01:00
}
} ) ;
// Change-listener for treeTableViewfilm
2018-03-07 23:51:02 +01:00
filmsTreeTable . getSelectionModel ( ) . selectedItemProperty ( ) . addListener ( new ChangeListener < Object > ( ) {
2018-03-04 20:07:43 +01:00
@Override
public void changed ( ObservableValue < ? > observable , Object oldVal , Object newVal ) {
2018-04-07 12:49:00 +02:00
if ( filmsTreeTable . getSelectionModel ( ) . getSelectedItem ( ) = = null ) {
return ;
}
2018-04-06 20:33:56 +02:00
currentTableFilm = filmsTreeTable . getSelectionModel ( ) . getSelectedItem ( ) . getValue ( ) ; // set the current film object
indexTable = filmsTreeTable . getSelectionModel ( ) . getSelectedIndex ( ) ; // get selected items table index
2018-04-07 12:49:00 +02:00
for ( FilmTabelDataType film : filmsList ) {
if ( film . equals ( currentTableFilm ) ) {
indexList = filmsList . indexOf ( film ) ; // get selected items list index
}
}
2018-04-06 20:33:56 +02:00
2018-03-08 17:59:28 +01:00
last = indexTable - 1 ;
next = indexTable + 1 ;
2019-01-22 17:29:56 +01:00
2018-03-08 23:01:07 +01:00
2019-01-22 17:29:56 +01:00
if ( ( currentTableFilm . getCached ( ) . isAfter ( lastValidCache ) ) | | dbController . searchCacheByURL ( getCurrentStreamUrl ( ) ) ) {
2018-04-06 20:33:56 +02:00
LOGGER . info ( " loading from cache: " + getCurrentTitle ( ) ) ;
2019-01-14 18:44:36 +01:00
setSelectedFilmInfo ( dbController . readCache ( getCurrentStreamUrl ( ) ) ) ;
2019-03-11 18:38:56 +01:00
// System.out.println("cache date is: " + currentTableFilm.getCached().toString());
2018-10-01 21:12:53 +02:00
} else {
2019-03-11 18:38:56 +01:00
// System.out.println("either not cached or to old!");
// System.out.println("cache date is: " + currentTableFilm.getCached().toString());
2019-01-14 18:44:36 +01:00
// this is not perfect!
new Thread ( new Runnable ( ) {
public void run ( ) {
Thread omdbAPIThread = new Thread ( new OMDbAPIController ( dbController , currentTableFilm , XMLController . getOmdbAPIKey ( ) ) ) ;
omdbAPIThread . setName ( " OMDbAPI " ) ;
omdbAPIThread . start ( ) ;
synchronized ( omdbAPIThread ) {
try {
omdbAPIThread . wait ( ) ;
} catch ( InterruptedException e ) {
LOGGER . error ( e ) ;
}
// update the GUI for the selected film
Platform . runLater ( ( ) - > {
setSelectedFilmInfo ( dbController . readCache ( getCurrentStreamUrl ( ) ) ) ;
} ) ;
}
}
} ) . start ( ) ;
2018-03-04 20:07:43 +01:00
}
}
} ) ;
2018-07-22 23:30:52 +02:00
// Poster-Mode actions
2016-09-09 20:41:20 +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 ( ) ) ;
}
if ( isSupportedFormat ( currentTableFilm ) ) {
new Player ( getCurrentTableFilm ( ) ) ;
} 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 " ,
XMLController . getLocalBundle ( ) . getString ( " vlcNotInstalled " ) ,
btnStyle , primaryStage ) ;
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
}
}
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 ( ) ;
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
}
@FXML
private void returnBtnclicked ( ) {
2018-03-07 23:51:02 +01:00
filmsTreeTable . getSelectionModel ( ) . select ( last ) ;
2018-03-01 16:10:37 +01:00
}
@FXML
private void forwardBtnclicked ( ) {
2018-03-07 23:51:02 +01:00
filmsTreeTable . getSelectionModel ( ) . select ( next ) ;
2018-03-01 16:10:37 +01: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 ( ) {
2018-10-13 00:32:29 +02:00
String bodyText = " Project HomeFlix \ nVersion: " + version + " (Build: " + buildNumber + " ) \" "
2019-01-09 22:36:50 +01:00
+ 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
}
@FXML
2018-05-17 18:58:54 +02:00
private void settingsBtnclicked ( ) {
2019-01-14 20:45:49 +01:00
if ( settingsScrollPane . isVisible ( ) ) {
2018-03-01 23:18:40 +01:00
settingsScrollPane . setVisible ( false ) ;
2018-05-17 18:58:54 +02:00
} else {
settingsScrollPane . setVisible ( true ) ;
2018-03-01 16:10:37 +01:00
}
}
@FXML
2018-03-04 20:07:43 +01: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
}
@FXML
2018-03-04 20:07:43 +01:00
private void addStreamSourceBtnAction ( ) {
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
}
@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 ( ) ;
}
@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 " ) ;
updateThread . start ( ) ;
}
@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
}
2018-04-07 17:14:35 +02:00
@FXML
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
}
2018-03-05 22:37:32 +01:00
// refresh the selected child of the root node
2018-04-28 18:02:02 +02:00
private void refreshTableElement ( ) {
2018-03-08 17:59:28 +01:00
filmRoot . getChildren ( ) . get ( indexTable ) . setValue ( filmsList . get ( indexList ) ) ;
2017-01-06 00:04:07 +01:00
}
2019-01-14 18:44:36 +01:00
/ * *
* refresh all films in filmsList and in filmsTable
* clear the FilmsList and FilmRoot children , then update the database
* /
private void refreshAllFilms ( ) {
2019-01-14 20:45:49 +01:00
filmsList . clear ( ) ;
filmRoot . getChildren ( ) . clear ( ) ;
2019-01-14 18:44:36 +01:00
dbController . refreshDataBase ( ) ; // refreshes the database after a source path was added
filmsList = dbController . getDatabaseFilmsList ( ) ; // returns a list of all films stored in the database
addFilmsToTable ( filmsList ) ;
}
2018-03-07 23:51:02 +01:00
/ * *
* add data from films - list to films - table
* /
2018-05-09 22:55:32 +02:00
public void addFilmsToTable ( ObservableList < FilmTabelDataType > elementsList ) {
2018-03-05 23:03:05 +01:00
2018-04-07 12:49:00 +02:00
for ( FilmTabelDataType element : elementsList ) {
2018-03-09 20:12:03 +01:00
// only if the entry contains a season and a episode it's a valid series
if ( ! element . getSeason ( ) . isEmpty ( ) & & ! element . getEpisode ( ) . isEmpty ( ) ) {
2018-04-13 11:11:25 +02:00
// check if there is a series node to add the item
2018-03-07 00:20:14 +01:00
for ( int i = 0 ; i < filmRoot . getChildren ( ) . size ( ) ; i + + ) {
if ( filmRoot . getChildren ( ) . get ( i ) . getValue ( ) . getTitle ( ) . equals ( element . getTitle ( ) ) ) {
2018-04-03 18:23:54 +02:00
// if a root node exists, add element as child
2018-04-13 11:11:25 +02:00
TreeItem < FilmTabelDataType > episodeNode = new TreeItem < > ( new FilmTabelDataType (
element . getStreamUrl ( ) , element . getTitle ( ) , element . getSeason ( ) , element . getEpisode ( ) ,
element . getFavorite ( ) , element . getCached ( ) , element . getImage ( ) ) ) ;
2018-03-07 00:20:14 +01:00
filmRoot . getChildren ( ) . get ( i ) . getChildren ( ) . add ( episodeNode ) ;
2018-04-13 11:11:25 +02:00
} else if ( filmRoot . getChildren ( ) . get ( i ) . nextSibling ( ) = = null ) {
2018-04-03 18:23:54 +02:00
// if no root node exists, create one and add element as child
2018-04-13 11:11:25 +02:00
TreeItem < FilmTabelDataType > seriesRootNode = new TreeItem < > ( new FilmTabelDataType (
2018-04-14 16:14:10 +02:00
element . getTitle ( ) + " _rootNode " , element . getTitle ( ) , " " , " " , element . getFavorite ( ) ,
2019-01-22 17:29:56 +01:00
element . getCached ( ) , element . getImage ( ) ) ) ;
2018-03-07 00:20:14 +01:00
filmRoot . getChildren ( ) . add ( seriesRootNode ) ;
2018-03-06 20:41:52 +01:00
}
}
2018-03-07 00:20:14 +01:00
} else {
2018-04-13 11:11:25 +02:00
// if season and episode are empty, we can assume the object is a film
filmRoot . getChildren ( ) . add ( new TreeItem < FilmTabelDataType > ( element ) ) ;
2016-09-09 20:41:20 +02:00
}
2016-08-14 15:17:14 +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 ( ) {
for ( SourceDataType source : sourcesList ) {
sourceRoot . getChildren ( ) . add ( new TreeItem < SourceDataType > ( source ) ) ; // add data to root-node
}
2016-09-09 20:41:20 +02:00
}
2018-02-24 17:13:52 +01:00
2018-07-22 23:30:52 +02:00
/ * *
* add a source to the newsources list
* @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 ) {
JsonObject source = null ;
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
source = Json . object ( ) . add ( " path " , path ) . add ( " mode " , mode ) ;
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 ) ;
}
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-01-09 22:36:50 +01:00
2019-01-14 18:44:36 +01:00
// clear the FilmsList and FilmRoot children, then update the database
refreshAllFilms ( ) ;
2019-01-09 22:36:50 +01:00
checkAllPosters ( ) ; // check if there is anything to cache
2016-08-14 15:17:14 +02:00
}
2018-04-02 18:29:59 +02:00
/ * *
* set the color of the GUI - Elements
* if usedColor is less than checkColor set text fill white , else black
* /
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-01-08 17:10:33 +01: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; " ;
2018-04-28 12:53:44 +02:00
2018-05-09 22:55:32 +02:00
playbtn . setGraphic ( new ImageView ( new Image ( " icons/ic_play_arrow_white_18dp_1x.png " ) ) ) ;
returnBtn . setGraphic ( new ImageView ( new Image ( " icons/ic_skip_previous_white_18dp_1x.png " ) ) ) ;
forwardBtn . setGraphic ( new ImageView ( new Image ( " icons/ic_skip_next_white_18dp_1x.png " ) ) ) ;
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-01-08 17:10:33 +01: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; " ;
2018-04-28 12:53:44 +02:00
2018-05-09 22:55:32 +02:00
playbtn . setGraphic ( new ImageView ( new Image ( " icons/ic_play_arrow_black_18dp_1x.png " ) ) ) ;
returnBtn . setGraphic ( new ImageView ( new Image ( " icons/ic_skip_previous_black_18dp_1x.png " ) ) ) ;
forwardBtn . setGraphic ( new ImageView ( new Image ( " icons/ic_skip_next_black_18dp_1x.png " ) ) ) ;
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
}
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 ( ) + " ; " ) ;
searchTextField . setFocusColor ( Color . valueOf ( XMLController . getColor ( ) ) ) ;
2018-04-28 18:02:02 +02:00
// normal buttons
addDirectoryBtn . setStyle ( btnStyle ) ;
addStreamSourceBtn . setStyle ( btnStyle ) ;
updateBtn . setStyle ( btnStyle ) ;
playbtn . setStyle ( btnStyle ) ;
openfolderbtn . setStyle ( btnStyle ) ;
returnBtn . setStyle ( btnStyle ) ;
forwardBtn . setStyle ( btnStyle ) ;
// menu buttons
settingsBtn . setStyle ( menuBtnStyle ) ;
aboutBtn . setStyle ( menuBtnStyle ) ;
2016-08-14 15:17:14 +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
}
2016-08-14 15:17:14 +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
}
2016-08-14 15:17:14 +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-01-09 22:36:50 +01:00
aboutBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " info " ) ) ;
settingsBtn . setText ( XMLController . getLocalBundle ( ) . getString ( " settings " ) ) ;
searchTextField . setPromptText ( XMLController . getLocalBundle ( ) . getString ( " tfSearch " ) ) ;
openfolderbtn . setText ( XMLController . getLocalBundle ( ) . getString ( " openFolder " ) ) ;
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 " ) ) ;
columnStreamUrl . setText ( XMLController . getLocalBundle ( ) . getString ( " columnStreamUrl " ) ) ;
columnTitle . setText ( XMLController . getLocalBundle ( ) . getString ( " columnName " ) ) ;
2019-01-12 23:07:25 +01:00
columnFavorite . setText ( XMLController . getLocalBundle ( ) . getString ( " columnFavorite " ) ) ;
2019-01-09 22:36:50 +01:00
columnSeason . setText ( XMLController . getLocalBundle ( ) . getString ( " columnSeason " ) ) ;
columnEpisode . setText ( XMLController . getLocalBundle ( ) . getString ( " columnEpisode " ) ) ;
2016-08-14 15:17:14 +02:00
}
2019-01-14 18:44:36 +01:00
private void setSelectedFilmInfo ( String [ ] cacheData ) {
Font font = Font . font ( " System " , FontWeight . BOLD , ( int ) Math . round ( XMLController . getFontSize ( ) ) ) ;
ObservableList < Node > textFlow = getTextFlow ( ) . getChildren ( ) ;
// TODO this should move! ***
2019-01-14 20:45:49 +01:00
Text [ ] nameText = new Text [ 20 ] ;
nameText [ 0 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " title " ) + " : " ) ;
nameText [ 1 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " year " ) + " : " ) ;
nameText [ 2 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " rated " ) + " : " ) ;
nameText [ 3 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " released " ) + " : " ) ;
nameText [ 4 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " season " ) + " : " ) ;
nameText [ 5 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " episode " ) + " : " ) ;
nameText [ 6 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " runtime " ) + " : " ) ;
nameText [ 7 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " genre " ) + " : " ) ;
nameText [ 8 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " director " ) + " : " ) ;
nameText [ 9 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " writer " ) + " : " ) ;
nameText [ 10 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " actors " ) + " : " ) ;
nameText [ 11 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " plot " ) + " : " ) ;
nameText [ 12 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " language " ) + " : " ) ;
nameText [ 13 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " country " ) + " : " ) ;
nameText [ 14 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " awards " ) + " : " ) ;
nameText [ 15 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " metascore " ) + " : " ) ;
nameText [ 16 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " imdbRating " ) + " : " ) ;
nameText [ 17 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " type " ) + " : " ) ;
nameText [ 18 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " boxOffice " ) + " : " ) ;
nameText [ 19 ] = new Text ( XMLController . getLocalBundle ( ) . getString ( " website " ) + " : " ) ;
2019-01-14 18:44:36 +01:00
// ***
2019-01-22 17:29:56 +01:00
2019-01-14 18:44:36 +01:00
// set the correct font for the nameText
for ( Text text : nameText ) {
text . setFont ( font ) ;
}
// clear the textFlow and add the new text
textFlow . clear ( ) ;
// TODO rework
for ( int i = 0 ; i < 20 ; i + + ) {
if ( cacheData [ i ] ! = null & & ( i = = 5 | | i = = 6 ) & & cacheData [ 5 ] . length ( ) = = 0 ) {
// do nothing
} else if ( cacheData [ i ] ! = null ) {
2019-01-14 20:45:49 +01:00
textFlow . addAll ( nameText [ i ] , new Text ( cacheData [ i ] + " \ n " ) ) ;
2019-01-14 18:44:36 +01:00
}
}
getTextFlow ( ) . setStyle ( " -fx-font-size : " + ( ( int ) Math . round ( XMLController . getFontSize ( ) ) + 1 ) + " px; " ) ;
// add the image
2019-01-22 17:29:56 +01:00
if ( new File ( cacheData [ 20 ] ) . isFile ( ) ) {
try {
posterImageView . setImage ( new Image ( new File ( cacheData [ 20 ] ) . toURI ( ) . toString ( ) ) ) ;
} catch ( Exception e ) {
posterImageView . setImage ( new Image ( cacheData [ 20 ] ) ) ;
LOGGER . error ( " No Poster found, useing default. " ) ;
}
} else {
posterImageView . setImage ( new Image ( cacheData [ 20 ] ) ) ;
2019-01-14 18:44:36 +01: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 ( ) ;
}
}
}
2018-04-28 12:53:44 +02:00
/ * *
* check if a film is supported by the HomeFlixPlayer or not
* this is the case if the mime type is mp4
* @param entry the film you want to check
* @return true if so , false if not
* /
private boolean isSupportedFormat ( FilmTabelDataType film ) {
String mimeType = URLConnection . guessContentTypeFromName ( film . getStreamUrl ( ) ) ;
return mimeType ! = null & & ( mimeType . contains ( " mp4 " ) | | mimeType . contains ( " vp6 " ) ) ;
2016-09-09 20:41:20 +02:00
}
2018-08-13 23:56:16 +02:00
2019-01-22 18:12:30 +01:00
/ * *
* Poser Mode WIP
* /
2018-08-13 23:56:16 +02:00
private void posterModeStartup ( ) {
checkAllPosters ( ) ;
}
/ * *
* 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 ) ;
2018-08-13 23:56:16 +02:00
for ( FilmTabelDataType entry : dbController . getAllNotCachedEntries ( ) ) {
System . out . println ( entry . getStreamUrl ( ) + " is NOT cached! " ) ;
2018-12-08 23:44:17 +01:00
2019-01-14 18:44:36 +01:00
Runnable OMDbAPIWorker = new OMDbAPIController ( dbController , 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 ( ) ;
2018-10-01 21:12:53 +02:00
2018-12-08 23:44:17 +01:00
// TODO show loading screen
2019-01-14 18:44:36 +01:00
// update all elements from the database
refreshAllFilms ( ) ;
2018-08-13 23:56:16 +02:00
}
2018-02-24 17:13:52 +01:00
// getter and setter
2018-04-28 18:02:02 +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
}
public int getIndexTable ( ) {
return indexTable ;
}
public int getIndexList ( ) {
return indexList ;
}
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 TextFlow getTextFlow ( ) {
return textFlow ;
}
public JFXButton getUpdateBtn ( ) {
return updateBtn ;
}
2017-01-26 16:32:47 +01:00
}