Пример #1
0
 private async void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "CurrentTrack")
     {
         await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             BackgroundImage.Source = new BitmapImage(new Uri(ArtworkConverter.ConvertObjectToImage(ViewModel.Service.CurrentTrack)));
         });
     }
 }
Пример #2
0
        public Overlay()
        {
            InitializeComponent();

            _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            ViewModel.Service.PropertyChanged += Service_PropertyChanged;

            // Set the accent color
            AccentHelper.UpdateAccentColor();

            BackgroundImage.Blur(40).Start();

            BackgroundImage.Source = new BitmapImage(new Uri(ArtworkConverter.ConvertObjectToImage(ViewModel.Service.CurrentTrack)));
        }
Пример #3
0
        public OverlayView()
        {
            InitializeComponent();

            _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            ViewModel.Service.PropertyChanged += Service_PropertyChanged;

            // Set the accent color
            TitlebarHelper.UpdateTitlebarStyle();

            BackgroundImage.Source =
                new BitmapImage(new Uri(ArtworkConverter.ConvertObjectToImage(ViewModel.Service.CurrentTrack)));
            TrackTitle.Text = ViewModel.Service.CurrentTrack.Title;
            TrackUser.Text  = ViewModel.Service.CurrentTrack.User.Username;
        }
Пример #4
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // Enable Async Code
            var deferral = taskInstance.GetDeferral();

            // If we have no internet, do not perform the task
            if (!NetworkHelper.HasInternet)
            {
                return;
            }

            // If the user has not connected their soundcloud
            // account. Do nothing.
            if (!SoundByteService.Instance.IsSoundCloudAccountConnected)
            {
                return;
            }

            // If the user has disabled notifications, do not
            // do anything.
            if (!SettingsService.Instance.IsNotificationsEnabled)
            {
                return;
            }

            // Get the time of the last check, we do this
            // so we know what tracks to get (that the user
            // has not already seen).
            var lastCheckTime = SettingsService.Instance.LatestViewedTrack;

            try
            {
                // Call the SoundCloud api and get notifications for this user
                var items = await SoundByteService.Instance.GetAsync <NotificationListHolder>("/e1/me/stream",
                                                                                              new Dictionary <string, string>
                {
                    { "limit", "20" }
                });

                foreach (var notification in items.Notifications)
                {
                    // Get the current date and time of the uploaded item
                    var postedTime = notification.CreatedAt.ToUniversalTime();

                    // Check if the notification happened before the last
                    // notification check
                    if (lastCheckTime > postedTime)
                    {
                        continue;
                    }

                    // Create the variables needed for the notification
                    var title     = string.Empty;
                    var content   = string.Empty;
                    var logo      = string.Empty;
                    var arguments = string.Empty;

                    switch (notification.Type)
                    {
                    case "track-repost":
                        // Clean and set the notification title
                        title = TextHelper.CleanXmlString(notification.Track.Title);
                        // Clean and set the notification content
                        content = TextHelper.CleanXmlString(string.Format("{0} has reposted a sound by {1}.",
                                                                          notification.User.Username, notification.Track.User.Username));
                        // Set the logo
                        logo = ArtworkConverter.ConvertObjectToImage(notification.Track);
                        // Set the arguments
                        arguments = $"soundbyte://core/track?id={notification.Track.Id}";
                        break;

                    case "track":
                        // Clean and set the notification title
                        title = TextHelper.CleanXmlString(notification.Track.Title);
                        // Clean and set the notification content
                        content = TextHelper.CleanXmlString(string.Format("{0} has uploaded a new sound.",
                                                                          notification.User.Username));
                        // Set the logo
                        logo = ArtworkConverter.ConvertObjectToImage(notification.Track);
                        // Set the arguments
                        arguments = $"soundbyte://core/track?id={notification.Track.Id}";
                        break;

                    case "playlist-repost":
                        // Clean and set the notification title
                        title = TextHelper.CleanXmlString(notification.Playlist.Title);
                        // Clean and set the notification content
                        content = TextHelper.CleanXmlString(string.Format("{0} has reposted a set by {1}.",
                                                                          notification.User.Username, notification.Playlist.User.Username));
                        // Set the logo
                        logo = ArtworkConverter.ConvertObjectToImage(notification.Playlist);
                        // Set the arguments
                        arguments = $"soundbyte://core/playlist?id={notification.Playlist.Id}";
                        break;

                    case "playlist":
                        // Clean and set the notification title
                        title = TextHelper.CleanXmlString(notification.Playlist.Title);
                        // Clean and set the notification content
                        content = TextHelper.CleanXmlString(string.Format("{0} has created a new set.",
                                                                          notification.User.Username));
                        // Set the logo
                        logo = ArtworkConverter.ConvertObjectToImage(notification.Playlist);
                        // Set the arguments
                        arguments = $"soundbyte://core/playlist?id={notification.Playlist.Id}";
                        break;
                    }

                    // Create the visual part of the taost notification
                    var toastVisual =
                        $@"<visual><binding template='ToastGeneric'><text>{title}</text><text>{
                                content
                            }</text><image src='{logo}' placement='appLogoOverride'/></binding></visual>";

                    // Create the toast XML string
                    var toastXmlString =
                        $@" <toast launch='{arguments}' displayTimestamp='{notification.CreatedAt.ToLocalTime():yyyy-MM-ddTHH:mm:ss.ffzzz}'>{
                                toastVisual
                            }<actions></actions></toast>";

                    // Create the XML document
                    var toastXml = new XmlDocument();
                    toastXml.LoadXml(toastXmlString);

                    // Create the toast notification
                    var toast = new ToastNotification(toastXml)
                    {
                        SuppressPopup = !SettingsService.Instance.IsNotificationPopupEnabled
                    };

                    // Show the taost notification
                    ToastNotificationManager.CreateToastNotifier().Show(toast);
                }
            }
            catch (Exception e)
            {
                TelemetryService.Instance.TrackException(e);
            }

            // Store the latest time so the notifications do not repeat
            SettingsService.Instance.LatestViewedTrack = DateTime.UtcNow;

            // Finished
            deferral.Complete();
        }
Пример #5
0
        private void UpdatePausedTile()
        {
            if (CurrentTrack == null)
            {
                return;
            }

            if (App.IsDesktop || App.IsMobile)
            {
                try
                {
                    _tileUpdater.Clear();

                    var firstXml = new Windows.Data.Xml.Dom.XmlDocument();
                    firstXml.LoadXml("<tile><visual><binding template=\"TileMedium\" branding=\"nameAndLogo\"><image placement=\"peek\" src=\"" + ArtworkConverter.ConvertObjectToImage(CurrentTrack) + "\"/><text>Paused</text><text hint-style=\"captionsubtle\" hint-wrap=\"true\"><![CDATA[" + CurrentTrack.Title.Replace("&", "&amp;") + "]]></text></binding><binding template=\"TileLarge\" branding=\"nameAndLogo\"><image placement=\"peek\" src=\"" + ArtworkConverter.ConvertObjectToImage(CurrentTrack) + "\"/><text>Paused</text><text hint-style=\"captionsubtle\" hint-wrap=\"true\"><![CDATA[" + CurrentTrack.Title.Replace("&", "&amp;") + "]]></text></binding></visual></tile>", new Windows.Data.Xml.Dom.XmlLoadSettings {
                        ValidateOnParse = true
                    });
                    _tileUpdater.Update(new TileNotification(firstXml));
                }
                catch
                {
                    // ignored
                }
            }
        }