Ejemplo n.º 1
0
        private async Task downloadChecked()
        {
            if (CloudItems != null)
            {
                try
                {
                    var downloadItems = CloudItems.Where(item => item.Checked).ToArray();
                    foreach (var downloadItem in downloadItems)
                    {
                        await doItemDownload(downloadItem);
                    }
                }
                catch (Exception ex)
                {
                    LoggerService.Instance.Log("ERROR: Library.downloadChecked: " + ex);
                }
            }

            manageDone();
        }
Ejemplo n.º 2
0
        public Library(Account accountViewModel)
        {
            this.accountViewModel = accountViewModel;
            Sort     = new Command <LibrarySort>(p => LibrarySort = p);
            Manage   = new Command(() => manage());
            Download = new Command <LibraryItem>(async p => await DownloadItem(p, true),
                                                 p => { return(p != null && !p.IsLocal && p.DownloadStatus != DownloadStatus.Downloading); });
            CancelDownload = new Command <LibraryItem>(p => cancelDownload(p),
                                                       p => { return(p != null && !p.IsLocal && p.DownloadStatus == DownloadStatus.Downloading); });
            Play = new Command <LibraryItem>(async p => await play(p),
                                             p => { return(p != null && (p.IsLocal || p.LocalItem != null)); });
            Delete = new Command <LibraryItem>(async p =>
            {
                if (p == null)
                {
                    return;
                }

                var message = string.Empty;
                if (p.IsLocal)
                {
                    message = "Are you sure you want to delete this recording from your device?" +
                              Environment.NewLine + "It is no longer available to download from the cloud.";
                    LibraryItem cloudRecording = null;
                    if (CloudItems != null)
                    {
                        cloudRecording = CloudItems.ToList().FirstOrDefault(c => c.ID == p.ID);
                    }

                    if (cloudRecording != null)
                    {
                        var timeLeft = cloudRecording.Expires.ToLocalTime().Subtract(DateTime.Now);
                        message      = "Are you sure you want to delete this recording from your device?" +
                                       Environment.NewLine + "You can download it again from the cloud within the next " +
                                       Math.Round(timeLeft.TotalDays) + " days.";
                    }
                }
                else
                {
                    message = "Are you sure you want to delete this recording from the cloud?" + Environment.NewLine +
                              "You will need to record it again to download and watch on any device.";
                    LibraryItem localRecording = null;
                    if (LocalItems != null)
                    {
                        localRecording = LocalItems.ToList().FirstOrDefault(l => l.ID == p.ID);
                    }

                    if (localRecording != null)
                    {
                        message = "Are you sure you want to delete this recording from the cloud?" +
                                  Environment.NewLine + "It will no longer be available for download on any device.";
                    }
                }

                if (await Application.Current.MainPage.DisplayAlert("Delete Recording", message, "Yes", "No"))
                {
                    try
                    {
                        CancelDownload?.Execute(p);

                        IsLoading = true;
                        if (!await delete(p))
                        {
                            await Application.Current.MainPage.DisplayAlert("Error Deleting",
                                                                            "Unable to delete the selected recording.", "OK");
                        }
                        else
                        {
                            OnItemDeleted?.Invoke(this, null);
                        }

                        IsLoading = false;
                    }
                    catch (Exception ex)
                    {
                        LoggerService.Instance.Log("ERROR: Library.DeleteCommand: " + ex);
                    }
                }
            },
                                               p => { return(p != null && p.Storage != LibraryItemStorage.iTunes); });

            DownloadChecked = new Command(async() => await downloadChecked(),
                                          () => { return(selectedView == LibraryViewMode.Cloud); });
            ManageDone    = new Command(() => manageDone());
            DeleteChecked = new Command(async() =>
            {
                IEnumerable <LibraryItem> items = null;
                if (selectedView == LibraryViewMode.Cloud)
                {
                    items = CloudItems.Where(l => l.Checked);
                }
                else
                {
                    items = LocalItems.Where(l => l.Checked);
                }

                if (items == null || !items.Any())
                {
                    await Application.Current.MainPage.DisplayAlert("Delete Recordings",
                                                                    "Please select one or more recordings to delete.", "OK");
                    return;
                }

                if (await Application.Current.MainPage.DisplayAlert("Delete Recordings",
                                                                    "Are you sure you want to delete the selected recordings?", "Yes", "No"))
                {
                    if (!await deleteMultipleItems(items.ToArray()))
                    {
                        await Application.Current.MainPage.DisplayAlert("Error Deleting",
                                                                        "Unable to delete all of the selected recordings.", "OK");
                    }
                }

                Edit = false;
            });

            RefreshCloudItems = new Command(async() =>
            {
                Edit = false;
                await getItems(true);
                try
                {
                    var clouds = cloudItems.ToList();
                    foreach (var cloudItem in clouds)
                    {
                        if (!string.IsNullOrEmpty(cloudItem.SmallThumbnailUri))
                        {
                            await ImageService.Instance.InvalidateCacheEntryAsync(cloudItem.SmallThumbnailUri,
                                                                                  CacheType.All);
                        }

                        if (!string.IsNullOrEmpty(cloudItem.LargeThumbnailUri))
                        {
                            await ImageService.Instance.InvalidateCacheEntryAsync(cloudItem.LargeThumbnailUri,
                                                                                  CacheType.All);
                        }

                        cloudItem.RefreshImages();
                    }
                }
                catch (Exception ex)
                {
                    //XXX : Handle error
                    LoggerService.Instance.Log("ERROR: Library.RefreshCloudItems: " + ex);
                }

                IsRefreshing = false;
            });

            RefreshLocalItems = new Command(async() =>
            {
                Edit = false;
                await updateLocalItems();
                IsRefreshing = false;
            });

            itemDownloader = ItemDownloaderService.Instance;
            itemDownloader.DownloadProgress += ItemDownloaderOnDownloadProgress;
            itemDownloader.DownloadComplete += ItemDownloaderOnDownloadComplete;
        }