package me.tdjones.main;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import me.tdjones.main.model.Feed;
import me.tdjones.main.model.Playlist;
import me.tdjones.main.util.MediaPlayerUtil;
import me.tdjones.main.util.XMLUtil;
import me.tdjones.main.view.FeedLayoutController;
import me.tdjones.main.view.RootLayoutController;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;


public class Main extends Application{

    private static Stage primaryStage;
    private BorderPane musicMain;
    private File directory;
    private Playlist nowPlaying;
    private MediaPlayer mediaPlayer;
    private Scene scene;
    private RootLayoutController rootLayoutController;
    private FeedLayoutController feedLayoutController;
    private Feed feed;

    public final static String itunesNamespace = "http://www.itunes.com/dtds/podcast-1.0.dtd";

    public static void main(String[] args) {
        Application.launch(Main.class);
    }

    @Override
    public void start(Stage primaryStage){
        this.primaryStage = primaryStage;
        try {
            feed = XMLUtil.parseRSS(new URL("http://rss.earwolf.com/beautiful-anonymous"));
        }catch (MalformedURLException e){
            e.printStackTrace();
        }
        MediaPlayerUtil.setCurrPlaying(feed.getEpisodeList().get(0));
        mediaPlayer = new MediaPlayer(new Media("http://feeds.soundcloud.com/stream/271124645-beautiful-anonymous-17-early-onset.mp3"));
        initLayout();
    }

    private void initLayout(){
        rootLayoutController = new RootLayoutController();

        scene = new Scene(rootLayoutController.getRootBorderPane(), 400, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

@@ -62,39 +62,8 @@
 on;%0A
-import javafx.fxml.FXMLLoader;%0A
 impo
@@ -561,16 +561,92 @@
 et.URL;%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Locale;%0A
 %0A%0Apublic
@@ -768,22 +768,35 @@
 ate 
-File directory
+static File subscriptionDir
 ;%0A  
@@ -990,32 +990,77 @@
 youtController;%0A
+    private static List%3CFeed%3E subscriptions;%0A
     private Feed
@@ -1208,16 +1208,96 @@
 args) %7B%0A
+        subscriptionDir = getSubscriptionDir();%0A        importSubscriptions();%0A%0A
         
@@ -1850,24 +1850,88 @@
 itLayout();%0A
+        rootLayoutController.updateFeedTilePane(subscriptions);%0A
     %7D%0A%0A    p
@@ -2084,17 +2084,17 @@
 Pane(), 
-4
+9
 00, 600)
@@ -2167,11 +2167,1072 @@
 );%0A    %7D
+%0A%0A    private static void importLibrary()%7B%0A    %7D%0A%0A    private static void importSubscriptions()%7B%0A        subscriptions = new ArrayList%3C%3E();%0A        List%3CURL%3E RSSUrls = XMLUtil.parseOPML(subscriptionDir);%0A        for (URL feedURL : RSSUrls)%7B%0A            subscriptions.add(XMLUtil.parseRSS(feedURL));%0A        %7D%0A    %7D%0A%0A    private static File getSubscriptionDir()%7B%0A        String directory = new String();%0A        String OS = System.getProperty(%22os.name%22, %22generic%22).toLowerCase(Locale.ENGLISH);%0A        if ((OS.indexOf(%22mac%22) %3E= 0) %7C%7C (OS.indexOf(%22darwin%22) %3E= 0) %7C%7C (OS.indexOf(%22nux%22) %3E= 0))%7B%0A            directory = System.getProperty(%22user.home%22) + File.separator + %22YAPM%22 + File.separator + %22subscriptions.opml%22;%0A        %7D else if (OS.indexOf(%22win%22) %3E= 0) %7B%0A            directory = System.getProperty(%22user.home%22) + File.separator + %22Documents%22 + File.separator + %22YAPM%22 + File.separator + %22subscriptions.opml%22;%0A        %7D else %7B%0A            // TODO: Handle other OS or error cases%0A            directory = %22%22;%0A        %7D%0A        return new File(directory);%0A    %7D
 %0A%7D%0A

Add support for subscriptions with agnostic system