private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (NavigationService.CanGoBack)
            {
                NavigationService.GoBack();
            }

            PodcastEpisodesDownloadManager downloadManager = PodcastEpisodesDownloadManager.getInstance();

            PodcastEpisodesDownloadManager.notifyUserOfDownloadRestrictions(m_podcastEpisode);
            downloadManager.addEpisodeToDownloadQueue(m_podcastEpisode);
        }
Exemplo n.º 2
0
            public void updatePodcastEpisodes()
            {
                Debug.WriteLine("Updating episodes for podcast: " + m_subscriptionModel.PodcastName);

                bool subscriptionAddedNow = true;

                List <PodcastEpisodeModel> episodes = null;

                using (var db = new PodcastSqlModel())
                {
                    episodes = db.episodesForSubscription(m_subscriptionModel);
                }

                DateTime latestEpisodePublishDate = new DateTime();

                if (episodes.Count > 0)
                {
                    // The episodes are in descending order as per publish date.
                    // So take the first episode and we have the latest known publish date.
                    latestEpisodePublishDate = episodes[0].EpisodePublished;

                    // If we already have episodes, this subscription is not being added now.
                    subscriptionAddedNow = false;
                }

                episodes = null;

                Debug.WriteLine("\nStarting to parse episodes for podcast: " + m_subscriptionModel.PodcastName);
                List <PodcastEpisodeModel> newPodcastEpisodes = PodcastFactory.newPodcastEpisodes(m_subscriptionModel.CachedPodcastRSSFeed, latestEpisodePublishDate);

                m_subscriptionModel.CachedPodcastRSSFeed = "";

                if (newPodcastEpisodes == null)
                {
                    Debug.WriteLine("WARNING: Got null list of new episodes.");
                    return;
                }

                using (var db = new PodcastSqlModel())
                {
                    PodcastSubscriptionModel sub = db.Subscriptions.FirstOrDefault(s => s.PodcastId == m_subscriptionModel.PodcastId);
                    if (sub == null)
                    {
                        Debug.WriteLine("Subscription NULL. Probably already deleted.");
                        return;
                    }

                    PodcastEpisodeModel[] newEpisodesSet = new PodcastEpisodeModel[newPodcastEpisodes.Count];
                    newPodcastEpisodes.CopyTo(newEpisodesSet);

                    // Let's check for duplicate episode names. This can happen if the subscription updates the "pubDate"
                    // of the most recent episode in the feed, in which case the most recent one (at least) can become a duplicate entry.
                    foreach (PodcastEpisodeModel newEpisode in newEpisodesSet.AsEnumerable())
                    {
                        if (sub.Episodes.OrderByDescending(ep => ep.EpisodePublished).Take(10).ToArray().FirstOrDefault(ep => ep.EpisodeName == newEpisode.EpisodeName) != null)
                        {
                            Debug.WriteLine("Episode already found in the subscription, removing: " + newEpisode.EpisodeName);
                            newPodcastEpisodes.Remove(newEpisode);
                        }
                    }

                    db.insertEpisodesForSubscription(m_subscriptionModel, newPodcastEpisodes);

                    // Indicate new episodes to the UI only when we are not adding the feed.
                    // I.e. we want to show new episodes only when we refresh the feed at restart.
                    if (subscriptionAddedNow == false)
                    {
                        int numOfNewPodcasts = newPodcastEpisodes.Count;

                        Debug.WriteLine("Got {0} new episodes.", numOfNewPodcasts);
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            m_subscriptionModel.addNumOfNewEpisodes(numOfNewPodcasts);
                        });

                        sub.addNumOfNewEpisodes(numOfNewPodcasts);

                        db.SubmitChanges();
                    }
                }

                if (m_subscriptionModel.IsAutoDownload &&
                    newPodcastEpisodes.Count > 0)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        PodcastEpisodesDownloadManager.getInstance().addEpisodesToDownloadQueue(newPodcastEpisodes);
                    });
                }

                if (newPodcastEpisodes.Count > 0)
                {
                    // Update subscription's information if it's pinned to home screen.
                    updatePinnedInformation();

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        // This will call the setter for episode model in the UI that will notify the UI that the content has changed.
                        m_subscriptionModel.EpisodesPublishedDescending = new ObservableCollection <PodcastEpisodeModel>();
                    });
                }
            }
Exemplo n.º 3
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            m_podcastId = int.Parse(NavigationContext.QueryString["podcastId"]);
            using (var db = new PodcastSqlModel())
            {
                m_subscription = db.subscriptionModelForIndex(m_podcastId);
                m_cleanListenedEpisodesAutomatically = db.settings().IsAutoDelete;
                if (m_cleanListenedEpisodesAutomatically)
                {
                    PodcastSubscriptionsManager.getInstance().cleanListenedEpisodes(m_subscription);
                }
            }

            m_playableEpisodes = m_subscription.PlayableEpisodes;
            this.DataContext   = m_subscription;

            PodcastSubscriptionsManager.getInstance().NewPlayableEpisode     -= new PodcastSubscriptionsManager.EpisodesEventHandler(m_subscription_NewPlayableEpisode);
            PodcastSubscriptionsManager.getInstance().RemovedPlayableEpisode -= new PodcastSubscriptionsManager.EpisodesEventHandler(m_subscription_RemovedPlayableEpisode);

            PodcastSubscriptionsManager.getInstance().NewPlayableEpisode     += new PodcastSubscriptionsManager.EpisodesEventHandler(m_subscription_NewPlayableEpisode);
            PodcastSubscriptionsManager.getInstance().RemovedPlayableEpisode += new PodcastSubscriptionsManager.EpisodesEventHandler(m_subscription_RemovedPlayableEpisode);

            bool forceUpdate = false;

            try
            {
                forceUpdate = String.IsNullOrEmpty(NavigationContext.QueryString["forceUpdate"]) == false &&
                              bool.Parse(NavigationContext.QueryString["forceUpdate"]);
            }
            catch (KeyNotFoundException)
            {
                forceUpdate = false;
            }

            if (forceUpdate)
            {
                // Clear the back stack
                while (((App)Application.Current).RootFrame.RemoveBackEntry() != null)
                {
                    ;
                }

                ShellTile pinnedSubscriptionTile = m_subscription.getSubscriptionsLiveTile();
                if (pinnedSubscriptionTile != null)
                {
                    StandardTileData tileData = new StandardTileData();
                    tileData.Count     = 0;
                    tileData.BackTitle = "";
                    pinnedSubscriptionTile.Update(tileData);
                }

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

            m_subscription.PodcastCleanStarted  -= new PodcastSubscriptionModel.SubscriptionModelHandler(m_subscription_PodcastCleanStarted);
            m_subscription.PodcastCleanFinished -= new PodcastSubscriptionModel.SubscriptionModelHandler(m_subscription_PodcastCleanFinished);

            m_subscription.PodcastCleanStarted  += new PodcastSubscriptionModel.SubscriptionModelHandler(m_subscription_PodcastCleanStarted);
            m_subscription.PodcastCleanFinished += new PodcastSubscriptionModel.SubscriptionModelHandler(m_subscription_PodcastCleanFinished);

            // Clean old episodes from the listing.
            if (SettingsModel.keepNumEpisodesForSelectedIndex(m_subscription.SubscriptionSelectedKeepNumEpisodesIndex) != SettingsModel.KEEP_ALL_EPISODES)
            {
                m_subscription.cleanOldEpisodes(SettingsModel.keepNumEpisodesForSelectedIndex(m_subscription.SubscriptionSelectedKeepNumEpisodesIndex));
            }

            if (App.episodeDownloadManager == null)
            {
                App.episodeDownloadManager = PodcastEpisodesDownloadManager.getInstance();
            }

            App.episodeDownloadManager.OnPodcastEpisodeDownloadStateChanged += new PodcastDownloadManagerHandler(episodeDownloadManager_PodcastEpisodeDownloadStateChanged);

            PodcastPlaybackManager.getInstance().OnPodcastStartedPlaying += new EventHandler(PodcastEpisodes_OnPodcastPlaystateChanged);
            PodcastPlaybackManager.getInstance().OnPodcastStoppedPlaying += new EventHandler(PodcastEpisodes_OnPodcastPlaystateChanged);
        }