예제 #1
0
        /// <summary>
        /// Navigate to read book page
        /// </summary>
        private async void AdaptiveGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var book   = e.ClickedItem as BookSummary;
            var pdfUrl = await NetworkGet.DownloadBook(book.ID);

            var password = await NetworkGet.GetBookKey(book.ID);

            if (password == null || password.Length == 0)
            {
                notification.Show("It seems that you do not own the book, " +
                                  "please try again", 4000);
                return;
            }
            Util.MainElem.NavigateToReadBook(book.ID, pdfUrl, password);
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var bookId = this.detail.ID;

            switch ((sender as Button).Tag as string)
            {
            case "buy":
                await Util.BuyBookAsync(bookId, this.detail, null, this.notification);

                this.Detail = detail;
                break;

            case "readlist":
                var ids = await NetworkGet.GetMyReadListsWithout(bookId);

                List <string> titles = new List <string>(ids.Length);
                foreach (int id in ids)
                {
                    var readlist = new BookDetailCollection();
                    await NetworkGet.GetTitleDescription(readlist, false, id);

                    titles.Add(readlist.Title);
                }
                if (titles.Count <= 0)
                {
                    break;
                }
                var combo = new ComboBox()
                {
                    FontSize      = 16,
                    ItemsSource   = titles,
                    SelectedIndex = 0
                };
                var dialog = new ContentDialog()
                {
                    Content = combo,
                    Title   = "Add Book to Read List",
                    IsSecondaryButtonEnabled = true,
                    PrimaryButtonText        = "Confirm",
                    SecondaryButtonText      = "Cancel"
                };
                if (await dialog.ShowAsync() == ContentDialogResult.Primary)
                {
                    var successful = await NetworkSet.ChangeReadList(ids[combo.SelectedIndex],
                                                                     BookListChangeType.AddBook,
                                                                     bookId, null);

                    if (successful)
                    {
                        this.detail.CanAddReadList = titles.Count - 1 > 0;
                        this.Detail = detail;
                        notification.Show("Success in adding book to your read list" +
                                          $"\"{combo.SelectedItem as string}\"", 4000);
                    }
                    else
                    {
                        notification.Show("Something wrong in adding book to your read list" +
                                          $"\"{combo.SelectedItem as string}\". " +
                                          "Please try again later.", 4000);
                    }
                }
                break;

            case "wishlist":
                var success = await NetworkSet.ChangeWishlist(bookId, true);

                if (success)
                {
                    this.detail.CanAddWishList = false;
                    this.Detail = detail;
                    notification.Show("Success in adding book to your wish list", 4000);
                }
                else
                {
                    notification.Show("Something wrong in adding book to your wish list. " +
                                      "Please try again later.", 4000);
                }
                break;

            case "preview":
                var content = (sender as Button).Content as string;
                if (content == "Read")
                {
                    var pdfUrl = await NetworkGet.DownloadBook(bookId);

                    var pass = await NetworkGet.GetBookKey(bookId);

                    if (pass == null || pass.Length == 0)
                    {
                        notification.Show("It seems that you haven't bought the book. " +
                                          "Please try again later.", 4000);
                        return;
                    }
                    Util.MainElem.NavigateToReadBook(bookId, pdfUrl, pass);
                }
                else
                {
                    var pdfUrl = await NetworkGet.GetBookPreview(bookId);

                    Util.MainElem.NavigateToReadBook(bookId, pdfUrl);
                }
                break;

            default:
                return;
            }
        }