Example #1
0
        private static List <Chapter> DownloadChaptersWork(String bookID, List <String> fileUrlsToDownload)
        {
            // If chapters are not downloaded yet or expired, download them again
            List <Chapter> chapterList = null;

            if (!BooksOnServerAccessor.HasChapters(bookID) || CurrentBook.Status == Book.BookStatus.UPDATING)
            {
                chapterList = eBriefingService.StartDownloadChapters(bookID);
                if (chapterList != null)
                {
                    BooksOnServerAccessor.SaveChapters(bookID, chapterList);
                }
            }
            else
            {
                // Or get them from the cache
                chapterList = BooksOnServerAccessor.GetChapters(bookID);
            }

            // Queue up cover images for the chapter only if the image version is different
            if (chapterList != null)
            {
                foreach (Chapter serverCh in chapterList)
                {
                    // Remove cover image if this is an update
                    bool download = false;
                    if (CurrentBook.Status == Book.BookStatus.UPDATING)
                    {
                        Chapter deviceCh = BooksOnDeviceAccessor.GetChapter(CurrentBook.ID, serverCh.ID);
                        if (deviceCh == null)
                        {
                            download = true;
                        }
                        else if (serverCh.ImageVersion != deviceCh.ImageVersion)
                        {
                            DownloadedFilesCache.RemoveFile(deviceCh.LargeImageURL);
                            DownloadedFilesCache.RemoveFile(deviceCh.SmallImageURL);

                            download = true;
                        }
                    }
                    else
                    {
                        download = true;
                    }

                    if (download)
                    {
                        fileUrlsToDownload.Add(serverCh.LargeImageURL);
                        fileUrlsToDownload.Add(serverCh.SmallImageURL);
                    }
                }
            }

            return(chapterList);
        }
        async private void RetrieveChapters()
        {
            // Update cover image
            UpdateImage();

            List <Chapter> chapterList = await eBriefingService.Run(() => eBriefingService.StartDownloadChapters(book.ID));

            if (chapterList != null)
            {
                // Save in the cache
                BooksOnServerAccessor.SaveChapters(book.ID, chapterList);

                // Update UI
                UpdateUI();

                // Enable segmentedControl
                segmentedControl.Enabled = true;
                spinner2.StopAnimating();
            }
        }