Пример #1
0
        public static PodcastSubscriptionsManager getInstance()
        {
            if (m_subscriptionManagerInstance == null)
            {
                m_subscriptionManagerInstance = new PodcastSubscriptionsManager();
            }

            return(m_subscriptionManagerInstance);
        }
        private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
        {
            PodcastSubscriptionModel subscriptionToDelete = (sender as MenuItem).DataContext as PodcastSubscriptionModel;

            Debug.WriteLine("Delete podcast subscription. Name: " + subscriptionToDelete.PodcastName);

            PodcastSubscriptionsManager subscriptionsManager = PodcastSubscriptionsManager.getInstance();

            subscriptionsManager.deleteSubscription(subscriptionToDelete);
        }
Пример #3
0
        public MainView()
        {
            InitializeComponent();

            this.DataContext = App.mainViewModels;

            // Hook to the event when the download list changes, so we can update the pivot header text for the
            // download page.
            ((INotifyCollectionChanged)EpisodeDownloadList.Items).CollectionChanged += downloadListChanged;

            // Upon startup, refresh all subscriptions so we get the latest episodes for each.
            m_subscriptionsManager = PodcastSubscriptionsManager.getInstance();
            m_subscriptionsManager.OnPodcastSubscriptionsChanged += new SubscriptionManagerHandler(m_subscriptionsManager_OnPodcastSubscriptionsChanged);
            m_subscriptionsManager.refreshSubscriptions();

            // Hook to SkyDrive export events
            m_subscriptionsManager.OnOPMLExportToSkydriveChanged += new SubscriptionManagerHandler(m_subscriptionsManager_OnOPMLExportToSkydriveChanged);

            m_applicationSettings = IsolatedStorageSettings.ApplicationSettings;

            // Hook to the event when the podcast player starts playing.
            m_playbackManager = PodcastPlaybackManager.getInstance();
            m_playbackManager.OnOpenPodcastPlayer += new EventHandler(PodcastPlayer_PodcastPlayerStarted);

            PodcastSubscriptionsManager.getInstance().OnPodcastChannelDeleteStarted
                += new SubscriptionManagerHandler(subscriptionManager_OnPodcastChannelDeleteStarted);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelDeleteFinished
                += new SubscriptionManagerHandler(subscriptionManager_OnPodcastChannelDeleteFinished);

            PodcastSubscriptionsManager.getInstance().OnPodcastChannelPlayedCountChanged
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelPlayedCountChanged);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelAdded
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelAdded);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelRemoved
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelRemoved);

            SubscriptionsList.ItemsSource = m_subscriptions;

            if (m_subscriptions.Count > 0)
            {
                NoSubscriptionsLabel.Visibility = Visibility.Collapsed;
            }
            else
            {
                NoSubscriptionsLabel.Visibility = Visibility.Visible;
            }

            handleShowReviewPopup();

            // This is the earliest place that we can initialize the download manager so it can show the error toast
            // which is defined in App.
            App.episodeDownloadManager = PodcastEpisodesDownloadManager.getInstance();
        }
Пример #4
0
        public MainView()
        {
            InitializeComponent();

            this.DataContext = App.mainViewModels;

            // Hook to the event when the download list changes, so we can update the pivot header text for the
            // download page.
            ((INotifyCollectionChanged)EpisodeDownloadList.Items).CollectionChanged += downloadListChanged;

            // Upon startup, refresh all subscriptions so we get the latest episodes for each.
            m_subscriptionsManager = PodcastSubscriptionsManager.getInstance();
            m_subscriptionsManager.OnPodcastSubscriptionsChanged += new SubscriptionManagerHandler(m_subscriptionsManager_OnPodcastSubscriptionsChanged);
            m_subscriptionsManager.refreshSubscriptions();

            // Hook to SkyDrive export events
            m_subscriptionsManager.OnOPMLExportToSkydriveChanged += new SubscriptionManagerHandler(m_subscriptionsManager_OnOPMLExportToSkydriveChanged);

            m_applicationSettings = IsolatedStorageSettings.ApplicationSettings;

            // Hook to the event when the podcast player starts playing.
            m_playbackManager = PodcastPlaybackManager.getInstance();
            m_playbackManager.OnOpenPodcastPlayer += new EventHandler(PodcastPlayer_PodcastPlayerStarted);

            PodcastSubscriptionsManager.getInstance().OnPodcastChannelDeleteStarted
                += new SubscriptionManagerHandler(subscriptionManager_OnPodcastChannelDeleteStarted);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelDeleteFinished
                += new SubscriptionManagerHandler(subscriptionManager_OnPodcastChannelDeleteFinished);

            PodcastSubscriptionsManager.getInstance().OnPodcastChannelPlayedCountChanged
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelPlayedCountChanged);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelAdded
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelAdded);
            PodcastSubscriptionsManager.getInstance().OnPodcastChannelRemoved
                += new SubscriptionChangedHandler(subscriptionManager_OnPodcastChannelRemoved);

            SubscriptionsList.ItemsSource = m_subscriptions;

            if (m_subscriptions.Count > 0)
            {
                NoSubscriptionsLabel.Visibility = Visibility.Collapsed;
            }
            else
            {
                NoSubscriptionsLabel.Visibility = Visibility.Visible;
            }

            handleShowReviewPopup();

            // This is the earliest place that we can initialize the download manager so it can show the error toast
            // which is defined in App.
            App.episodeDownloadManager = PodcastEpisodesDownloadManager.getInstance();
        }
Пример #5
0
        public void addEpisodeToDownloadQueue(PodcastEpisodeModel episode)
        {
            episode.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Queued;
            episode.DownloadPercentage   = 0;
            m_episodeDownloadQueue.Enqueue(episode);
            saveEpisodeInfoToDB(episode);
            PodcastSubscriptionsManager.getInstance().newDownloadedEpisode(episode);

            if (m_currentEpisodeDownload == null)
            {
                startNextEpisodeDownload();
            }
        }
Пример #6
0
        private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
        {
            PodcastEpisodeModel podcastEpisode = (sender as MenuItem).DataContext as PodcastEpisodeModel;

            podcastEpisode.deleteDownloadedEpisode();
            PodcastSubscriptionsManager.getInstance().removedPlayableEpisode(podcastEpisode);

            using (var db = new PodcastSqlModel())
            {
                m_episodeModel = db.episodeForEpisodeId(m_episodeModel.EpisodeId);
            }

            this.DataContext = null;
            this.DataContext = m_episodeModel;
        }
Пример #7
0
        private string generateLocalEpisodeFileName(PodcastEpisodeModel podcastEpisode)
        {
            // Parse the filename of the logo from the remote URL.
            string localPath = new Uri(podcastEpisode.EpisodeDownloadUri).LocalPath;
            string podcastEpisodeFilename = localPath.Substring(localPath.LastIndexOf('/') + 1);

            podcastEpisodeFilename = PodcastSubscriptionsManager.sanitizeFilename(podcastEpisodeFilename);
            podcastEpisodeFilename = String.Format("{0}_{1}", DateTime.Now.Millisecond, podcastEpisodeFilename);

            string localPodcastEpisodeFilename = App.PODCAST_DL_DIR + "/" + podcastEpisodeFilename;

            Debug.WriteLine("Found episode filename: " + localPodcastEpisodeFilename);

            return(localPodcastEpisodeFilename);
        }
        private void updateEpisodeWhenDownloaded(PodcastEpisodeModel episode)
        {
            Debug.WriteLine("Updating episode information for episode when download completed: " + episode.EpisodeName);
            episode.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Downloaded;

            using (var db = new PodcastSqlModel())
            {
                Debug.WriteLine(" * Downloaded file name: " + episode.EpisodeFile);

                PodcastEpisodeModel e = db.episodeForEpisodeId(episode.EpisodeId);
                e.EpisodeFile          = episode.EpisodeFile;
                e.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Downloaded;
                e.EpisodePlayState     = PodcastEpisodeModel.EpisodePlayStateEnum.Downloaded;

                db.SubmitChanges();

                PodcastSubscriptionsManager.getInstance().podcastPlaystateChanged(e.PodcastSubscription);
            }
        }
Пример #9
0
        public MainView()
        {
            InitializeComponent();

            // Upon startup, refresh all subscriptions so we get the latest episodes for each.
            m_subscriptionsManager = PodcastSubscriptionsManager.getInstance();
            m_subscriptionsManager.OnPodcastSubscriptionsChanged += new SubscriptionManagerHandler(m_subscriptionsManager_OnPodcastSubscriptionsChanged);

            m_subscriptionsManager.refreshSubscriptions();

            // Post-pageinitialization event call hookup.
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            // Hook to the event when the download list changes, so we can update the pivot header text for the
            // download page.
            ((INotifyCollectionChanged)EpisodeDownloadList.Items).CollectionChanged += downloadListChanged;

            // Hook to the event when the podcast player starts playing.
            this.PodcastPlayer.PodcastPlayerStarted += new EventHandler(PodcastPlayer_PodcastPlayerStarted);
            this.PodcastPlayer.PodcastPlayerStopped += new EventHandler(PodcastPlayer_PodcastPlayerStopped);
        }
Пример #10
0
        private void MenuItemMarkAsListened_Click(object sender, RoutedEventArgs e)
        {
            PodcastEpisodeModel      podcastEpisode = this.DataContext as PodcastEpisodeModel;
            PodcastSubscriptionModel subscription   = null; // We need this to update the play states for this subscription.

            bool delete = false;

            using (var db = new PodcastSqlModel())
            {
                PodcastEpisodeModel sqlepisode = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == podcastEpisode.EpisodeId);

                subscription = db.Subscriptions.FirstOrDefault(sub => sub.PodcastId == sqlepisode.PodcastId);
                PodcastSubscriptionsManager.getInstance().podcastPlaystateChanged(subscription);

                delete = db.settings().IsAutoDelete;

                sqlepisode.SavedPlayPos     = 0;
                sqlepisode.EpisodePlayState = PodcastEpisodeModel.EpisodePlayStateEnum.Listened;
                db.SubmitChanges();
            }

            podcastEpisode.markAsListened(delete);
        }
Пример #11
0
        async internal void importSubscriptionsFromOneDrive()
        {
            if (MessageBox.Show("Podcatcher will try to find and import the latest podcasts that were exported from Podcatcher. Please login to OneDrive to continue.",
                                "Import from OneDrive",
                                MessageBoxButton.OKCancel) != MessageBoxResult.OK)
            {
                return;
            }

            OneDriveFile latestExport = (await OneDriveManager.getInstance().getFileListing("me/SkyDrive/files"))
                                        .OrderByDescending(file => file.Created)
                                        .Where(file => file.Name.Contains("PodcatcherSubscriptions"))
                                        .FirstOrDefault();

            if (latestExport == null)
            {
                MessageBox.Show("Could not find any exported podcasts from Podcatcher on OneDrive. Make sure to have the exported OPML file in your root OneDrive folder.");
                return;
            }

            Debug.WriteLine("Going to get file {0} (Id: {1}) from {2}: ", latestExport.Name, latestExport.Id, latestExport.Url);
            PodcastSubscriptionsManager.getInstance().addSubscriptionFromOPMLFile(latestExport.Url);
        }
Пример #12
0
        private void ExportSubscriptionsMenuItem_Click(object sender, EventArgs e)
        {
            String exportNotificationText = "";

            using (var db = new PodcastSqlModel())
            {
                if (db.settings().SelectedExportIndex == (int)SettingsModel.ExportMode.ExportToSkyDrive)
                {
                    exportNotificationText = "This will export your podcast subscriptions information in OPML format to your SkyDrive account. Do you want to continue?";
                }
                else if (db.settings().SelectedExportIndex == (int)SettingsModel.ExportMode.ExportViaEmail)
                {
                    exportNotificationText = "This will export your podcast subscriptions information in OPML format via email. Do you want to continue?";
                }
            }

            if (MessageBox.Show(exportNotificationText,
                                "Export subscriptions in OPML format",
                                MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                PodcastSubscriptionsManager.getInstance().exportSubscriptions();
            }
        }
Пример #13
0
        public void cancelEpisodeDownload(PodcastEpisodeModel episode)
        {
            // Update new episode state.
            episode.EpisodeDownloadState = PodcastEpisodeModel.EpisodeDownloadStateEnum.Idle;
            saveEpisodeInfoToDB(episode);

            // Get the transfer request that we should cancel.
            BackgroundTransferRequest thisRequest = episode.DownloadRequest;

            // We canceled a queued episode that wasn't downloading yet.
            if (thisRequest == null)
            {
                removeEpisodeFromDownloadQueue(episode);
                return;
            }
            else
            {
                // We canceled current download.
                RemoveTransferRequest(thisRequest);
            }

            episode.DownloadRequest = null;
            PodcastSubscriptionsManager.getInstance().removedPlayableEpisode(episode);
        }
        public static PodcastSubscriptionsManager getInstance()
        {
            if (m_subscriptionManagerInstance == null)
            {
                m_subscriptionManagerInstance = new PodcastSubscriptionsManager();
            }

            return m_subscriptionManagerInstance;
        }
Пример #15
0
        private void PlayStateChanged(object sender, EventArgs e)
        {
            EventHandler handlerStoppedPlaying = null;

            switch (BackgroundAudioPlayer.Instance.PlayerState)
            {
            case PlayState.Playing:
                PodcastEpisodeModel currentEpisode = updateCurrentlyPlayingEpisode();
                if (currentEpisode == null)
                {
                    Debug.WriteLine("Error: No playing episode in DB.");
                    return;
                }

                if (CurrentlyPlayingEpisode == null)
                {
                    CurrentlyPlayingEpisode = currentEpisode;
                }
                else if (currentEpisode.EpisodeId != CurrentlyPlayingEpisode.EpisodeId)
                {
                    CurrentlyPlayingEpisode = currentEpisode;
                }

                if (CurrentlyPlayingEpisode.TotalLengthTicks == 0)
                {
                    CurrentlyPlayingEpisode.StoreProperty <long>("TotalLengthTicks", BackgroundAudioPlayer.Instance.Track.Duration.Ticks);
                    PodcastSubscriptionsManager.getInstance().podcastPlaystateChanged(CurrentlyPlayingEpisode.getSubscriptionModel());
                }
                break;

            case PlayState.Paused:
                BackgroundAudioPlayer playerPaused = BackgroundAudioPlayer.Instance;
                if (CurrentlyPlayingEpisode != null)
                {
                    CurrentlyPlayingEpisode = App.refreshEpisodeFromAudioAgent(CurrentlyPlayingEpisode);
                    CurrentlyPlayingEpisode.StoreProperty <PodcastEpisodeModel.EpisodePlayStateEnum>("EpisodePlayState", PodcastEpisodeModel.EpisodePlayStateEnum.Paused);
                }
                else
                {
                    Debug.WriteLine("SHOULD NOT HAPPEND! Cannot save episode state to paused!");
                }
                break;

            case PlayState.Stopped:
            case PlayState.Shutdown:
            case PlayState.TrackEnded:
                if (CurrentlyPlayingEpisode == null)
                {
                    // We didn't have a track playing.
                    return;
                }

                // F**K YOU WINDOWS PHONE!!

                /**
                 * This is so horrible that I can't find other words to describe how bad the BackgroundAudioPlayer
                 * is in Windows Phone!
                 *
                 * First of all the events are fired totally differently between Windows Phone 7 and Windows Phone 8.
                 * Secondly the events related to when tracks end arae totally wrong and horrible! Let me explain:
                 * - We get here the PlayState.Stopped event when the track ends.
                 * - We get the event here BEFORE the AudioAgent gets any events.
                 * - AudioAgent correctly gets the PlayState.TrackEnded event, but it gets it after we have received the
                 *   event here.
                 * - We NEVER get the the PlayState.TrackEnded event here.
                 * - Which is not the case for Windows Phone 7, because it first fires PlayState.TrackEnded.
                 *
                 * So this code here is a horrible kludge that just guesses that Windows Phone means "track did end"
                 * when the state is stopped and the play position is still 0.
                 *
                 * Johan, when you return from the future to this piece of code, don't even try to change it or "fix it".
                 **/
                long playpos = 0;
                if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.TrackEnded)
                {
                    playpos = CurrentlyPlayingEpisode.TotalLengthTicks;
                }
                else if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Stopped &&
                         BackgroundAudioPlayer.Instance.Position.Ticks == 0)
                {
                    playpos = CurrentlyPlayingEpisode.TotalLengthTicks;
                }
                else
                {
                    try
                    {
                        playpos = BackgroundAudioPlayer.Instance.Position.Ticks;
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Warning: Player didn't return us a play pos!");
                    }
                }

                CurrentlyPlayingEpisode.SavedPlayPos = playpos;
                CurrentlyPlayingEpisode.setNoPlaying();

                using (var db = new PodcastSqlModel())
                {
                    PodcastEpisodeModel savingEpisode = db.Episodes.FirstOrDefault(ep => ep.EpisodeId == CurrentlyPlayingEpisode.EpisodeId);
                    if (savingEpisode != null)
                    {
                        savingEpisode.SavedPlayPos = CurrentlyPlayingEpisode.SavedPlayPos;
                        // Update play state to listened as appropriate.
                        if (savingEpisode.isListened())
                        {
                            savingEpisode.markAsListened(db.settings().IsAutoDelete);
                            removeFromPlayqueue(savingEpisode);
                        }
                        else
                        {
                            savingEpisode.EpisodePlayState = CurrentlyPlayingEpisode.EpisodePlayState;
                        }
                        db.SubmitChanges();

                        PodcastSubscriptionsManager.getInstance().podcastPlaystateChanged(savingEpisode.PodcastSubscription);
                    }
                }

                PodcastSubscriptionsManager.getInstance().podcastPlaystateChanged(CurrentlyPlayingEpisode.getSubscriptionModel());
                handlerStoppedPlaying = OnPodcastStoppedPlaying;
                if (handlerStoppedPlaying != null)
                {
                    OnPodcastStoppedPlaying(this, new EventArgs());
                }

                // Cleanup
                CurrentlyPlayingEpisode = null;
                break;

            case PlayState.TrackReady:
                break;

            case PlayState.Unknown:
                // Unknown? WTF.
                break;
            }

            App.mainViewModels.PlayQueue = new System.Collections.ObjectModel.ObservableCollection <PlaylistItem>();

            if (CurrentlyPlayingEpisode != null)
            {
                PodcastSubscriptionsManager.getInstance().podcastPlaystateChanged(CurrentlyPlayingEpisode.PodcastSubscriptionInstance);
            }
        }
Пример #16
0
        private void MenuItemRefresh_Click(object sender, RoutedEventArgs e)
        {
            PodcastSubscriptionModel subscriptionToRefresh = (sender as MenuItem).DataContext as PodcastSubscriptionModel;

            PodcastSubscriptionsManager.getInstance().refreshSubscription(subscriptionToRefresh);
        }