コード例 #1
0
        void HandleUpdateAvailableBadgeEvent(object sender, EventArgs e)
        {
            try
            {
                List <Book> sBooks = BooksOnServerAccessor.GetBooks();
                List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();

                int count = 0;
                if (sBooks != null && dBooks != null)
                {
                    HashSet <String> dIDs = new HashSet <String>(dBooks.Select(d => d.ID));
                    var results           = sBooks.Where(s => !dIDs.Contains(s.ID)).Where(s => !s.Viewed).ToList();
                    if (results != null)
                    {
                        count = results.Count;
                    }
                }
                else if (sBooks != null)
                {
                    count = sBooks.Where(s => !s.Viewed).ToList().Count;
                }

                UpdateBadge(3, count);
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("eBriefingViewController - HandleUpdateAvailableBadgeEvent: {0}", ex.ToString());
            }
        }
コード例 #2
0
            public BookSearchDisplayDelegate(PopoverSearchController parent)
            {
                this.parent = parent;

                myBooks        = BooksOnDeviceAccessor.GetBooks();
                availableBooks = BooksOnServerAccessor.GetBooks();
            }
コード例 #3
0
ファイル: BookUpdater.cs プロジェクト: MetroStar/eBriefingiOS
        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);
        }
コード例 #4
0
ファイル: BookUpdater.cs プロジェクト: MetroStar/eBriefingiOS
        public static void RemoveBookFromDevice(Book book)
        {
            if (book != null)
            {
                if (book.Status == Book.BookStatus.DOWNLOADING || book.Status == Book.BookStatus.PENDING2DOWNLOAD)
                {
                    if (book.Status == Book.BookStatus.DOWNLOADING)
                    {
                        // Remove page images from the file system
                        List <Page> pageList = BooksOnServerAccessor.GetPages(book.ID);
                        if (pageList != null)
                        {
                            foreach (Page page in pageList)
                            {
                                DownloadedFilesCache.RemoveFile(page.URL);
                            }
                        }
                        BooksOnServerAccessor.RemovePages(book.ID);

                        // Remove chapter images from the file system
                        List <Chapter> chapterList = BooksOnServerAccessor.GetChapters(book.ID);
                        if (chapterList != null)
                        {
                            foreach (Chapter chapter in chapterList)
                            {
                                DownloadedFilesCache.RemoveFile(chapter.SmallImageURL);
                                DownloadedFilesCache.RemoveFile(chapter.LargeImageURL);
                            }
                        }
                        BooksOnServerAccessor.RemoveChapters(book.ID);
                    }

                    // Remove book images from the file system
                    DownloadedFilesCache.RemoveFile(book.SmallImageURL);
                    DownloadedFilesCache.RemoveFile(book.LargeImageURL);

                    BooksOnDeviceAccessor.RemoveBook(book.ID);

                    // Initialize CurrentBook
                    InitializeFailedURLs();
                }
                else if (book.Status == Book.BookStatus.PENDING2UPDATE || book.Status == Book.BookStatus.UPDATING)
                {
                    RemoveBookFromBooks2Update(book.ID);

                    BooksOnServerAccessor.RemovePages(book.ID);
                    BooksOnServerAccessor.RemoveChapters(book.ID);
                }
            }
        }
コード例 #5
0
        private void LoadCollectionView()
        {
            // Load collectionView
            if (collectionView != null)
            {
                List <Book> bookList = null;

                // Only show those books that are not on the device
                List <Book> sBooks = BooksOnServerAccessor.GetBooks();
                List <Book> dBooks = BooksOnDeviceAccessor.GetBooks();

                if (sBooks != null && dBooks != null)
                {
                    HashSet <String> dIDs = new HashSet <String>(dBooks.Select(d => d.ID));
                    var results           = sBooks.Where(s => !dIDs.Contains(s.ID)).ToList();
                    if (results != null)
                    {
                        bookList = results;
                    }
                }
                else if (sBooks != null)
                {
                    bookList = sBooks;
                }

                LoadingView.Hide();

                if (bookList == null || bookList.Count == 0)
                {
                    UpdateStatusLabel("There are no more available books.");

                    UpdateAvailableBadge();
                }
                else
                {
                    dataSource = new LibraryDataSource(new List <Book>(bookList), this);
                    dataSource.ItemPressedEvent += HandleItemPressedEvent;
                    dataSource.DownloadEvent    += HandleDownloadEvent;
                    collectionView.Source        = dataSource;
                    collectionView.ReloadData();

                    ShowHideStatusLabel(false);
                }
            }
        }
コード例 #6
0
        private void Failed2RetrieveBooks()
        {
            LoadingView.Hide();

            UIAlertView alert = new UIAlertView(StringRef.alert, StringRef.failed2Retrieve + "books.", null, StringRef.ok);

            alert.Dismissed += (object sender, UIButtonEventArgs e) =>
            {
                if (!BooksOnServerAccessor.HasBooks())
                {
                    if (String.IsNullOrEmpty(URL.ServerURL))
                    {
                        OpenBookshelf();
                    }
                }
            };
            alert.Show();
        }
コード例 #7
0
        private void UpdateBadge(int index, int number)
        {
            if (index == 0)
            {
                if (number == 0)
                {
                    vc1.TabBarItem.BadgeValue = null;
                }
                else
                {
                    vc1.TabBarItem.BadgeValue = number.ToString();
                }
            }
            else if (index == 2)
            {
                if (number == 0)
                {
                    vc3.TabBarItem.BadgeValue = null;
                }
                else
                {
                    vc3.TabBarItem.BadgeValue = number.ToString();
                }

                // If current tab is already Updates Tab, refresh and show books
                if (tabBarController.SelectedIndex == 2)
                {
                    vc3.RetrieveBooks();
                }
            }
            else if (index == 3)
            {
                if (number == 0)
                {
                    BooksOnServerAccessor.UpdateViewed();
                    vc4.TabBarItem.BadgeValue = null;
                }
                else
                {
                    vc4.TabBarItem.BadgeValue = number.ToString();
                }
            }
        }
コード例 #8
0
        private void UpdateUI()
        {
            if (segmentedControl.SelectedSegment == 0)
            {
                tableView.Hidden = true;
                textView.Hidden  = false;
            }
            else
            {
                textView.Hidden  = true;
                tableView.Hidden = false;

                // tableView
                if (tableView.Source == null)
                {
                    tableView.Source = new BookOverviewDataSource(BooksOnServerAccessor.GetChapters(book.ID));
                    tableView.ReloadData();
                }
            }
        }
コード例 #9
0
        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();
            }
        }
コード例 #10
0
ファイル: BookUpdater.cs プロジェクト: MetroStar/eBriefingiOS
        private static List <Page> DownloadPagesWork(String bookID)
        {
            // If pages are not downloaded yet or expired, download them again
            if (!BooksOnServerAccessor.HasPages(bookID) || CurrentBook.Status == Book.BookStatus.UPDATING)
            {
                List <Page> pageList = eBriefingService.StartDownloadPages(bookID);
                if (pageList != null)
                {
                    BooksOnServerAccessor.SavePages(bookID, pageList);

                    return(pageList);
                }
                return(null);
            }
            else
            {
                // Or get them from the cache
                return(BooksOnServerAccessor.GetPages(bookID));
            }
        }
コード例 #11
0
        async public void LoadBooks()
        {
            TimeSpan diff = DateTime.UtcNow.Subtract(Settings.AvailableCheckTime);

            if (TimeSettings.LibraryRefreshRequired(diff))
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    LoadingView.Show("Loading", "Please wait while we're checking Available Books...", false);

                    List <Book> bookList = await eBriefingService.Run(() => eBriefingService.StartDownloadBooks());

                    if (bookList != null)
                    {
                        Settings.AvailableCheckTime = DateTime.UtcNow;

                        // Save in the cache
                        BooksOnServerAccessor.SaveBooks(bookList);

                        // Load books
                        RetrieveBooks();

                        // Update available badge
                        UpdateAvailableBadge();
                    }
                    else
                    {
                        LoadingView.Hide();
                    }
                }
                else
                {
                    UpdateStatusLabel(StringRef.connectionRequired);
                }
            }
            else
            {
                RetrieveBooks();
            }
        }
コード例 #12
0
        public void RetrieveBooks()
        {
            if (!Reachability.IsDefaultNetworkAvailable())
            {
                UpdateStatusLabel(StringRef.connectionRequired);
            }
            else
            {
                List <Book> bookList = BooksOnServerAccessor.GetBooks();
                if (bookList == null)
                {
                    UpdateStatusLabel("There are no available books.");

                    Failed2RetrieveBooks();
                }
                else
                {
                    // Load collectionView
                    LoadCollectionView();
                }
            }
        }
コード例 #13
0
ファイル: BookRemover.cs プロジェクト: MetroStar/eBriefingiOS
        public static void RemoveBook(Book book)
        {
            // Remove page images from the file system
            List <Page> pageList = BooksOnDeviceAccessor.GetPages(book.ID);

            if (pageList != null)
            {
                foreach (Page page in pageList)
                {
                    BooksOnDeviceAccessor.RemoveBookmark(book.ID, page.ID);
                    BooksOnDeviceAccessor.RemoveAllNotesForThisPage(book.ID, page.ID);
                    BooksOnDeviceAccessor.RemoveAnnotation(book.ID, page.ID);

                    DownloadedFilesCache.RemoveFile(page.URL);
                }
            }
            BooksOnServerAccessor.RemovePages(book.ID);
            BooksOnDeviceAccessor.RemovePages(book.ID);

            // Remove chapter images from the file system
            List <Chapter> chapterList = BooksOnDeviceAccessor.GetChapters(book.ID);

            if (chapterList != null)
            {
                foreach (Chapter chapter in chapterList)
                {
                    DownloadedFilesCache.RemoveFile(chapter.SmallImageURL);
                    DownloadedFilesCache.RemoveFile(chapter.LargeImageURL);
                }
            }
            BooksOnServerAccessor.RemoveChapters(book.ID);
            BooksOnDeviceAccessor.RemoveChapters(book.ID);

            // Remove book images from the file system
            DownloadedFilesCache.RemoveFile(book.SmallImageURL);
            DownloadedFilesCache.RemoveFile(book.LargeImageURL);

            BooksOnDeviceAccessor.RemoveBook(book.ID);
        }
コード例 #14
0
        public LibraryBookView(Book book, LibraryViewController parentVC) : base(new CGRect(0, 0, 280, 280))
        {
            this.LibraryBook = book;

            this.BackgroundColor     = UIColor.White;
            this.Layer.ShadowColor   = UIColor.Black.CGColor;
            this.Layer.ShadowOpacity = 0.3f;
            this.Layer.ShadowRadius  = 2f;
            this.Layer.ShadowOffset  = new CGSize(5f, 5f);

            // imageView
            imageView       = new UIImageView();
            imageView.Frame = new CGRect(0, 0, this.Frame.Width, 150);
            this.AddSubview(imageView);

            if (!String.IsNullOrEmpty(LibraryBook.LargeImageURL))
            {
                // imageSpinner
                imageSpinner        = eBriefingAppearance.GenerateBounceSpinner();
                imageSpinner.Center = imageView.Center;
                this.AddSubview(imageSpinner);

                // Download image
                bool exist = FileDownloader.Download(LibraryBook.LargeImageURL, parentVC);
                if (exist)
                {
                    bool outDated = false;
                    var  item     = BooksOnServerAccessor.GetBook(LibraryBook.ID);
                    if (item != null)
                    {
                        if (item.ImageVersion < LibraryBook.ImageVersion)
                        {
                            DownloadedFilesCache.RemoveFile(item.LargeImageURL);
                            DownloadedFilesCache.RemoveFile(item.SmallImageURL);

                            outDated = true;
                        }
                    }

                    if (outDated)
                    {
                        FileDownloader.Download(LibraryBook.LargeImageURL, parentVC, true);
                    }
                    else
                    {
                        UpdateImage(LibraryBook.LargeImageURL);
                    }
                }
            }

            // titleLabel
            UILabel titleLabel = eBriefingAppearance.GenerateLabel(16);

            titleLabel.Frame         = new CGRect(10, imageView.Frame.Bottom + 8, 260, 21);
            titleLabel.Lines         = 2;
            titleLabel.LineBreakMode = UILineBreakMode.WordWrap;
            titleLabel.Text          = book.Title;
            titleLabel.SizeToFit();
            titleLabel.Frame = new CGRect(10, titleLabel.Frame.Y, 260, titleLabel.Frame.Height);
            this.AddSubview(titleLabel);

            // bookInfoView
            BookInfoView bookInfoView = new BookInfoView("0", "0", "0", book.PageCount.ToString(), false, false, this.Frame.Width - 30);

            bookInfoView.Frame = new CGRect(10, this.Frame.Bottom - 44, bookInfoView.Frame.Width, bookInfoView.Frame.Height);
            this.AddSubview(bookInfoView);

            // downloadButton
            UIButton downloadButton = UIButton.FromType(UIButtonType.Custom);

            downloadButton.Font = eBriefingAppearance.ThemeBoldFont(14);
            downloadButton.SetTitleColor(eBriefingAppearance.Color("37b878"), UIControlState.Normal);
            downloadButton.SetTitleColor(UIColor.White, UIControlState.Highlighted);
            downloadButton.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/green_unfilled.png").CreateResizableImage(new UIEdgeInsets(15f, 14f, 15f, 14f)), UIControlState.Normal);
            downloadButton.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/green_filled.png").CreateResizableImage(new UIEdgeInsets(15f, 14f, 15f, 14f)), UIControlState.Highlighted);
            downloadButton.Frame = new CGRect(this.Center.X - 65, bookInfoView.Frame.Top - 28, 130, downloadButton.CurrentBackgroundImage.Size.Height);
            downloadButton.SetTitle("DOWNLOAD", UIControlState.Normal);
            downloadButton.TouchUpInside += HandleDownloadButtonTouchUpInside;
            this.AddSubview(downloadButton);
        }
コード例 #15
0
ファイル: BookUpdater.cs プロジェクト: MetroStar/eBriefingiOS
        private static void UpdateDatabase(Book book)
        {
            try
            {
                List <Chapter> chapterList = BooksOnServerAccessor.GetChapters(book.ID);
                List <Page>    pageList    = BooksOnServerAccessor.GetPages(book.ID);

                // Update notes
                if (BooksOnDeviceAccessor.GetNotes(book.ID) != null)
                {
                    // Remove orphans
                    BooksOnDeviceAccessor.RemoveOrphanNotes(book.ID, pageList);
                }

                // Update bookmarks
                if (BooksOnDeviceAccessor.GetBookmarks(book.ID) != null)
                {
                    // Remove orphans
                    BooksOnDeviceAccessor.RemoveOrphanBookmarks(book.ID, pageList);
                }

                // Update new chapters
                if (BooksOnDeviceAccessor.GetChapters(book.ID) == null)
                {
                    BooksOnDeviceAccessor.AddChapters(book.ID, chapterList);
                }
                else
                {
                    BooksOnDeviceAccessor.UpdateChapters(book.ID, chapterList);
                }

                BooksOnDeviceAccessor.MapPagesToChapter(chapterList, pageList); // ML: 4/9/2013 We need to map them after each update

                // Update new pages
                if (BooksOnDeviceAccessor.GetPages(book.ID) == null)
                {
                    BooksOnDeviceAccessor.AddPages(book.ID, pageList);
                }
                else
                {
                    BooksOnDeviceAccessor.UpdatePages(book.ID, pageList);
                }

                // Remove chapters and pages list from BooksOnServer because they now exist on the device
                BooksOnServerAccessor.RemoveChapters(book.ID);
                BooksOnServerAccessor.RemovePages(book.ID);

                // Update new book
                book.New           = true;
                book.Status        = Book.BookStatus.DOWNLOADED;
                book.UserAddedDate = DateTime.UtcNow;

                if (BooksOnDeviceAccessor.GetBook(book.ID) == null)
                {
                    BooksOnDeviceAccessor.AddBook(book);
                }
                else
                {
                    if (BooksDataAccessor.IsFavorite(book.ID))
                    {
                        book.IsFavorite = true;
                    }
                    BooksOnDeviceAccessor.UpdateBook(book);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("BookUpdater - UpdateDatabase: {0}", ex.ToString());
            }
        }