code clean up and commons-lang removed

This commit is contained in:
Seil0 2017-04-06 12:07:34 +02:00
parent 4d3c402553
commit df448e321d
16 changed files with 97 additions and 53 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,5 @@
/**
* @author Jannik
* DBController for Project HomeFlix
* connection is in manual commit!
*/
@ -31,11 +32,13 @@ import javafx.scene.text.Text;
public class DBController {
public DBController(MainWindowController m) {
public DBController(MainWindowController m, Main main) {
mainWindowController = m;
this.main = main;
}
private MainWindowController mainWindowController;
private Main main;
private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; //path to database file
private Image favorite_black = new Image("recources/icons/ic_favorite_black_18dp_1x.png");
private Image favorite_border_black = new Image("recources/icons/ic_favorite_border_black_18dp_1x.png");
@ -329,8 +332,10 @@ public class DBController {
* @throws SQLException
* @throws FileNotFoundException
* @throws IOException
* if lastName != filmsStreamData.get(b) then set i = 0, file changed
*/
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException{
String lastName = "";
System.out.println("checking for entrys to add to DB ...");
String[] entries = new File(mainWindowController.getPath()).list();
Statement stmt = connection.createStatement();
@ -348,16 +353,20 @@ public class DBController {
}
for(int b=0; b<filmsStreamURL.size(); b++){
if(filmsdbStreamURL.contains(filmsStreamURL.get(b))){
}else{
if(filmsdbStreamURL.contains(filmsStreamURL.get(b))) {
} else {
if(lastName != "" && lastName != filmsStreamData.get(b)) {
i = 0;
}
lastName = filmsStreamData.get(b);
JsonObject object = Json.parse(new FileReader(filmsStreamData.get(b))).asObject();
JsonArray items = object.get("entries").asArray();
System.out.println(items.size()+", "+i);
System.out.println(items.size()+", "+i+"; "+b);
String streamURL = items.get(i).asObject().getString("streamUrl","");
String titel = items.get(i).asObject().getString("titel","");
if(streamURL.equals(filmsStreamURL.get(b))){
System.out.println("hinzuf<EFBFBD>gen \""+titel+"\"");
System.out.println("hinzufügen \""+titel+"\"");
ps.setInt(1, items.get(i).asObject().getInt("year", 0));
ps.setInt(2, items.get(i).asObject().getInt("season", 0));
@ -544,7 +553,7 @@ public class DBController {
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl='"+streamUrl+"';");
ArrayList<Text> nameText = new ArrayList<Text>();
ArrayList<Text> responseText = new ArrayList<Text>();
String fontFamily = mainWindowController.fontFamily;
String fontFamily = main.getFONT_FAMILY();
Image im;
int fontSize = (int) Math.round(mainWindowController.size);
int j=2;

View File

@ -42,19 +42,22 @@ public class Main extends Application {
Stage primaryStage;
private String path;
private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix";
private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix";
private String color = "ee3523";
private String mode = "local"; //local or streaming
// private String streamingPathWin = System.getProperty("user.home") + "\\Documents\\HomeFlix";
// private String streamingPathLinux = System.getProperty("user.home") + "/HomeFlix";
private String COLOR = "ee3523";
private String FONT_FAMILY = "System";
private String mode = "local"; //local or streaming TODO
private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country");
private boolean autoUpdate = false;
private double size = 17;
private boolean AUTO_UPDATE = false;
private double FONT_SIZE = 17;
private ResourceBundle bundle;
private MainWindowController mainWindowController;
private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix"); //Windows: C:/Users/"User"/Documents/HomeFlix
private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix"); //Linux: /home/"User"/HomeFlix
private File fileWin = new File(dirWin + "/config.xml"); //Windows: C:/Users/"User"/Documents/HomeFlix/config.xml
private File fileLinux = new File(dirLinux + "/config.xml"); //Linux: /home/"User"/HomeFlix/config.xml
private File directory;
private File settingsFile;
private String dirWin = System.getProperty("user.home") + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix
private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
private String fileWin = dirWin + "/config.xml"; //Windows: C:/Users/"User"/Documents/HomeFlix/config.xml
private String fileLinux = dirLinux + "/config.xml"; //Linux: /home/"User"/HomeFlix/config.xml
@Override
public void start(Stage primaryStage) {
@ -74,43 +77,66 @@ public class Main extends Application {
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon
mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.setAutoUpdate(autoUpdate); //set auto-update
mainWindowController.setAutoUpdate(AUTO_UPDATE); //set auto-update
mainWindowController.setMain(this); //call setMain
//Linux if directory exists -> check config.xml
if(System.getProperty("os.name").equals("Linux")){
if(dirLinux.exists() != true){
dirLinux.mkdir();
}else if(fileLinux.exists() != true){
mainWindowController.setPath(firstStart());
mainWindowController.setStreamingPath(streamingPathLinux);
mainWindowController.setColor(color);
mainWindowController.setSize(size);
mainWindowController.setAutoUpdate(autoUpdate);
mainWindowController.setLocal(local);
mainWindowController.setMode(mode);
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
}
//windows
}else{
if(dirWin.exists() != true){
dirWin.mkdir();
}else if(fileWin.exists() != true){
mainWindowController.setPath(firstStart());
mainWindowController.setStreamingPath(streamingPathWin);
mainWindowController.setColor(color);
mainWindowController.setSize(size);
mainWindowController.setAutoUpdate(autoUpdate);
mainWindowController.setLocal(local);
mainWindowController.setMode(mode);
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
}
if(System.getProperty("os.name").equals("Linux")) {
directory = new File(dirLinux);
settingsFile = new File(fileLinux);
} else {
directory = new File(dirWin);
settingsFile = new File(fileWin);
}
if(settingsFile.exists() != true){
directory.mkdir();
mainWindowController.setPath(firstStart());
mainWindowController.setStreamingPath(directory.getAbsolutePath());
mainWindowController.setColor(COLOR);
mainWindowController.setSize(FONT_SIZE);
mainWindowController.setAutoUpdate(AUTO_UPDATE);
mainWindowController.setLocal(local);
mainWindowController.setMode(mode);
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itse
}
// if(System.getProperty("os.name").equals("Linux")){
// if(dirLinux.exists() != true){
// dirLinux.mkdir();
// }else if(fileLinux.exists() != true) {
// mainWindowController.setPath(firstStart());
// mainWindowController.setStreamingPath(streamingPathLinux);
// mainWindowController.setColor(COLOR);
// mainWindowController.setSize(FONT_SIZE);
// mainWindowController.setAutoUpdate(AUTO_UPDATE);
// mainWindowController.setLocal(local);
// mainWindowController.setMode(mode);
// mainWindowController.saveSettings();
// Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
// System.exit(0); //finishes itself
// }
// //windows
// }else{
// if(dirWin.exists() != true){
// dirWin.mkdir();
// }else if(fileWin.exists() != true){
// mainWindowController.setPath(firstStart());
// mainWindowController.setStreamingPath(streamingPathWin);
// mainWindowController.setColor(COLOR);
// mainWindowController.setSize(FONT_SIZE);
// mainWindowController.setAutoUpdate(AUTO_UPDATE);
// mainWindowController.setLocal(local);
// mainWindowController.setMode(mode);
// mainWindowController.saveSettings();
// Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
// System.exit(0); //finishes itself
// }
// }
mainWindowController.loadSettings();
mainWindowController.loadStreamingSettings();
mainWindowController.initUI();
@ -166,4 +192,12 @@ public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
public String getFONT_FAMILY() {
return FONT_FAMILY;
}
public void setFONT_FAMILY(String FONT_FAMILY) {
this.FONT_FAMILY = FONT_FAMILY;
}
}

View File

@ -213,7 +213,6 @@ public class MainWindowController {
@SuppressWarnings("unused")
private String ratingSortType;
private String local;
String fontFamily = "System"; //TODO -> in mainwindowcontroller machen
String title;
String year;
String rating;
@ -518,8 +517,8 @@ public class MainWindowController {
void setMain(Main main) {
this.main = main;
Updater = new updater(this,buildURL, downloadLink, buildNumber);
dbController = new DBController(this);
ApiQuery = new apiQuery(this, dbController);
dbController = new DBController(this, this.main);
ApiQuery = new apiQuery(this, dbController, this.main);
}
//Initialize the tables (treeTableViewfilm and tableViewStreamingdata)

View File

@ -21,13 +21,15 @@ import javafx.scene.text.Text;
public class apiQuery{
public apiQuery(MainWindowController m, DBController db){
public apiQuery(MainWindowController m, DBController db, Main main){
mainWindowController=m;
dbController=db;
this.main = main;
}
private MainWindowController mainWindowController;
private DBController dbController;
private Main main;
private Image im;
private String[] responseString = new String[20];
ArrayList<Text> responseText = new ArrayList<Text>();
@ -42,7 +44,7 @@ public class apiQuery{
String retdata = null;
InputStream is = null;
BufferedReader br = null;
String fontFamily = mainWindowController.fontFamily;
String fontFamily = main.getFONT_FAMILY();
int fontSize = (int) Math.round(mainWindowController.size);
responseText.removeAll(responseText);