Esempio n. 1
0
        private async Task <bool> addToQueue(ContentItemEx item)
        {
            try
            {
                registerForNotifications();

                if (mediaContentViewModel != null)
                {
                    mediaContentViewModel.IsDetailsLoading = true;
                }

                var recordToken = await ContentClient.GetRecordToken(item.ID);

                var smallThumbUrl = ContentClient.GetSmallImageUrl(item.ID, 192, 128);
                var smallThumb    = await ImageToolsService.Instance.GetImageFromCache(smallThumbUrl);

                if (smallThumb == null)
                {
                    smallThumb = await ContentClient.GetImageFromUrl(smallThumbUrl);
                }

                var largeThumbUrl = ContentClient.GetLargeImageUrl(item.ID, 720, 480);
                var largeThumb    = await ImageToolsService.Instance.GetImageFromCache(largeThumbUrl);

                if (largeThumb == null)
                {
                    largeThumb = await ContentClient.GetImageFromUrl(largeThumbUrl);
                }

                var isSmallThumbValid = isValidImage(smallThumb);
                var isLargeThumbValid = isValidImage(largeThumb);
                if (!isSmallThumbValid || !isLargeThumbValid)
                {
                    var channelThumbUrl = item.ChannelThumbnailUrl;
                    if (!string.IsNullOrEmpty(channelThumbUrl))
                    {
                        var channelThumb = await ContentClient.GetImageFromUrl(channelThumbUrl);

                        if (!isSmallThumbValid)
                        {
                            smallThumb = channelThumb;
                        }

                        if (!isLargeThumbValid)
                        {
                            largeThumb = channelThumb;
                        }
                    }
                }

                var response = await QueueClient.Add(recordToken, smallThumb, largeThumb);

                if ((response != null) && response.Success)
                {
                    item.InQueue = true;
                    if (mediaContentViewModel.SelectedItem is ContentItemEx)
                    {
                        (mediaContentViewModel.SelectedItem as ContentItemEx).InQueue = true;
                    }

                    FacebookToolsService.Instance.LogCustomEvent("AddToQueue");

                    NewItemsCount++;
                    return(true);
                }

                return(false);
            }
            finally
            {
                if (mediaContentViewModel != null)
                {
                    mediaContentViewModel.IsDetailsLoading = false;
                }
            }
        }