License text

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER 
 * Copyright  2008, 2010 Oracle and/or its affiliates.  All rights reserved. 
 * Use is subject to license terms.
 * 
 * This file is available and licensed under the following license:
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met: 
 * 
 *   * Redistributions of source code must retain the above copyright notice, 
 *     this list of conditions and the following disclaimer. 
 *
 *   * Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *   * Neither the name of Oracle Corporation nor the names of its contributors 
 *     may be used to endorse or promote products derived from this software 
 *     without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

    

/*
 * Main.fx
 *
 * Created on Dec 21, 2009, 4:47:27 AM
 */

package fxpodcastviewer;

import fxpodcastviewer.feed.PodcastMedia;
import fxpodcastviewer.feed.PodcastFeed;
import fxpodcastviewer.ui.desktop.MainScreen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import fxpodcastviewer.storage.PersistenceHandler;
import javafx.util.Sequences;

/**
 * @author raghunair
 */

 public def applicationTitle = "FXPodcastSearch";
 var mediaURL ="http://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2956241001_big-buck-bunny-640x360.flv";

    var meta = PodcastMedia{
                    mediaURL:mediaURL
                    image:"{__DIR__}resources/podcast.png"
                    title:"Test title by Raghu Nair"
                    publisher:"Raghu Nair"
                    pubDate:"Thursday, April 20 2009"
                    data:" How to use this Podcast Viewer\n"
                        "1) Enter URL in the text box and press refresh button\n"
                        "2) Navigate from the current podcasts using navigation button \n"
                        "3) Press + button to add this to favourates\n"
                        "4) Press Feed button to list the favourates\n"
                        "5) Press the info button to view details \n"
                }


     public var currentFeed:PodcastFeed;

     public function nextMedia(){
         var nextMedia:PodcastMedia;
         var currentMedia = mainScreen.mediaMeta;

         var mediaSequence:PodcastMedia[];
         if ( currentMedia.fromStore){
            mediaSequence = PersistenceHandler.storedMedias;
         }else{
            mediaSequence = currentFeed.medias;
         }

         if ( sizeof mediaSequence <= 0){
             return;
         }


         var index = Sequences.indexOf(mediaSequence, currentMedia);
         if ( index == sizeof mediaSequence -1){
            nextMedia = mediaSequence[0];
         }else {
            nextMedia = mediaSequence[index+1];
         }
         
         mainScreen.mediaMeta = nextMedia;
     }


     public function prevMedia(){
         var prevMedia:PodcastMedia;
         var currentMedia = mainScreen.mediaMeta;

         var mediaSequence:PodcastMedia[];
         if ( currentMedia.fromStore){
            mediaSequence = PersistenceHandler.storedMedias;
         }else{
            mediaSequence = currentFeed.medias;
         }

         if ( sizeof mediaSequence <= 0){
             return;
         }

         var index = Sequences.indexOf(mediaSequence, currentMedia);
         if ( index == 0){
            prevMedia = mediaSequence[sizeof mediaSequence -1];
         }else {
            prevMedia = mediaSequence[index-1];
         }

         mainScreen.mediaMeta = prevMedia;
     }


     public function list(){
         var currentMedia = mainScreen.mediaMeta;
         var mediaSequence:PodcastMedia[];
         if ( currentMedia.fromStore){
            mediaSequence = PersistenceHandler.storedMedias;
         }else{
            mediaSequence = currentFeed.medias;
         }
         
         if ( sizeof mediaSequence <= 0){
             return;
         }

         mainScreen.podcastList.podcasts = mediaSequence;
         mainScreen.addList();
     }


     public var mainScreen = MainScreen{ mediaMeta:meta };

     public function run(){
         //fxpodcastviewer.storage.PersistenceHandler.clear();
         fxpodcastviewer.storage.PersistenceHandler.load();
         Stage {
                    title : applicationTitle
                    style:StageStyle.TRANSPARENT
                    scene: Scene {
                                width: 640
                                height: 480

                                fill:Color.BLACK
                                content: [ mainScreen]
                           }
                }
     }