public BookSearchResultPage(BookShelf bookshelf, AmazonBookSearch search, ObservableCollection <Book> books) { InitializeComponent(); SearchContext = search; InitList(bookshelf, books); }
public BookSearchPage(BookShelf bookShelf) { this.bookShelf = bookShelf; amazonKey = LoadCredentialsFile(); InitializeComponent(); this.Appearing += (object sender, System.EventArgs e) => this.entryTitle.Focus(); //スクリーンのサイズを取得する var screenWidth = Application.Current.MainPage.Width; var screenHeight = Application.Current.MainPage.Height; ResizeView(screenWidth, screenHeight); }
protected override void OnAppearing() { base.OnAppearing(); //トリッキーだが、ここで登録済み判定の更新を行う BookShelf bookShelf = new BookShelf(); foreach (var book in ResultBookList) { if (bookShelf.IsRegistBook(book.ISBN)) { book.IsRegistBookShelf = true; } } }
async private void InitList(BookShelf bookshelf, ObservableCollection <Book> books) { ResultBookList = new ObservableCollection <ViewModel.SearchResultBook>(); addResultBook(books, ResultBookList); SearchResultVM = new SearchResultVM { BookResultList = ResultBookList }; this.BindingContext = SearchResultVM; listBook.ItemSelected += async(sender, e) => { if (e.SelectedItem == null) { return; } ((ListView)sender).SelectedItem = null; ViewModel.SearchResultBook item = e.SelectedItem as ViewModel.SearchResultBook; //本棚に登録済みの場合は詳細を表示しない if (item != null && item.IsRegistBookShelf == false) { await Navigation.PushAsync(new BookDetailPage(bookshelf, item.CreateBook(), item.IsRegistBookShelf)); } }; listBook.ItemAppearing += async(object sender, ItemVisibilityEventArgs e) => { // ObservableCollection の最後が ListView の Item と一致した時に ObservableCollection にデータを追加する。 if (ResultBookList.Last() == e.Item as SearchResultBook) { // ObservableCollection にデータを追加する処理 stack.IsVisible = true; await AmazonSearch(SearchContext); // 実際の処理を入れてください。 stack.IsVisible = false; } }; SearchResultVM.CheckBooks(books); }
private void CrateExportView(Style labelStyleDetailContent) { exportLabel = new Label { Text = "本だなデータの移行/取込み", Style = labelStyleDetailContent, }; exportButton = new Button { Text = "本だなデータファイルを保存する", }; exportButton.Clicked += async(sender, e) => { string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + BOOKSHELF_FILENAME; BookShelf bookShelf = new BookShelf(); string bookJsonText = JsonConvert.SerializeObject(bookShelf.Books); var obj = DependencyService.Get <IBookShelf>(); // SDカードに出力する場合の処理 string filepath = obj.SaveFile(filename, bookJsonText); bool isExist = obj.IsExistFile(filepath); if (isExist == false) { await DisplayAlert("バックアップデータ作成失敗", "本だなデータファイルの作成に失敗しましたので終了します", "OK"); return; } await DisplayAlert("本だなデータを以下のファイルに保存しました", filepath, "OK"); }; importButton = new Button { Text = "本だなデータファイルを読み込む", }; importButton.Clicked += async(sender, e) => { var obj = DependencyService.Get <IBookShelf>(); obj.OnFileLoaded += async(s, jsonText) => { if (jsonText == null) { await DisplayAlert("データファイル読み込み失敗", "指定したファイルに問題ないか確認してください。", "OK"); return; } IEnumerable <Book> books = JsonConvert.DeserializeObject <IEnumerable <Book> >(jsonText); if (books == null) { await DisplayAlert("読み込み失敗", "本だなデータの読み込みに失敗しました", "OK"); return; } BookShelf bookShelf = new BookShelf(); bookShelf.UpdateAll(books); await DisplayAlert("読み込み完了", "本だなデータの読み込みに成功しました", "OK"); }; obj.LoadFile(); }; }
public BookDetailPage(BookShelf bookShelf, Book book, bool isRegist) { //GA-> //詳細ページ表示してAmazonページをみる割合を検証する GoogleAnalytics.Current.Tracker.SendView("BookDetailPage"); //GA<- this.Book = book; CalilSearch = new SearchResultVM { BookResultList = GetSearchResultBookList(this.Book) }; if (!isRegist) { ToolbarItems.Add(new ToolbarItem { Text = "[本の登録]", Command = new Command(() => { string readingStatus = SwitchReading.IsToggled ? "既読" : "未読"; bookShelf.SaveBook(book, readingStatus, EntryNote.Text); //GA-> //膨大な蔵書を育てる人が多い事の検証。蔵書追加頻度を知りたい GoogleAnalytics.Current.Tracker.SendEvent("BookDetailPage", "AddBook", book.Title); //GA<- LabelFooter.Text = "本を登録しました [" + DateTime.Now.ToString() + "]"; }) }); } else { ToolbarItems.Add(new ToolbarItem { Text = "[本の登録]", Command = new Command(() => { string readingStatus = SwitchReading.IsToggled ? "既読" : "未読"; bookShelf.SaveBook(book, readingStatus, EntryNote.Text); //GA-> //膨大な蔵書を育てる人が多い事の検証。蔵書の更新頻度を知りたい GoogleAnalytics.Current.Tracker.SendEvent("BookDetailPage", "UpdateBook", book.Title); //GA<- LabelFooter.Text = "本を登録しました [" + DateTime.Now.ToString() + "]"; }) }); ToolbarItems.Add(new ToolbarItem { Text = "[本の削除]", Command = new Command(async() => { bool ret = await DisplayAlert("本の削除", "本を削除します", "OK", "キャンセル"); if (!ret) { return; } bookShelf.DeleteBook(book); await Navigation.PopAsync(true); }) }); } Label labelFooter = new Label { Style = Application.Current.Resources["FooterLabelStyle"] as Style, BindingContext = CalilSearch, }; labelFooter.SetBinding(Label.TextProperty, "Status"); LabelFooter = labelFooter; ScrollView scrollView = new ScrollView { Margin = new Thickness(10, 0), VerticalOptions = LayoutOptions.FillAndExpand, Content = GetBookDetailContent(), }; Content = new StackLayout { Children = { scrollView, labelFooter, }, }; this.BindingContext = CalilSearch; CheckLibrary(); }