public void RemoveBookList(List <BookEntity> removeBookList) { if (IsLoading) { return; } IsLoading = true; Task.Run(async() => { bool result = true; foreach (var item in removeBookList) { if (!IsLoading) { result = false; break; } string url = ViewModelInstance.Instance.UrlService.GetBookShelfPage() + "?id=" + item.BookID; string html = await http.WebRequestGet(url); if (html.Contains("取消收藏成功")) { DispatcherHelper.CheckBeginInvokeOnUI(() => { ShelfBookList.Remove(item); }); } else { result = false; } } return(result); }).ContinueWith((result) => { DispatcherHelper.CheckBeginInvokeOnUI(() => { IsLoading = false; if (result.Result) { // ToastHeplper.ShowMessage("操作完毕"); removeBookList.Clear(); OnEditCommand(false); RefreshList(); } else { ToastHeplper.ShowMessage("取消收藏失败。"); } } ); }); }
public void RefreshList() { if (this.ShelfBookList.Count > 0) { List <BookEntity> list = new List <BookEntity>(); this.ShelfBookList.ToList().ForEach(p => list.Add(p)); this.ShelfBookList.Clear(); list = list.OrderByDescending(p => DateTime.Parse(p.UpdateTime)).ToList(); list.ForEach(p => ShelfBookList.Add(p)); } else { IsShow = true; } }
public void SetBookList(string html) { if (!string.IsNullOrEmpty(html)) { var list = AnalysisSoduService.GetBookShelftListFromHtml(html); if (list == null) { this.IsShow = true; } else { this.ShelfBookList?.Clear(); this.IsShow = false; if (list.Count > 0) { var temp = list.OrderByDescending(p => DateTime.Parse(p.UpdateTime)).ToList(); foreach (var item in temp) { var entity = DBBookShelf.GetBook(AppDataPath.GetBookShelfDBPath(), item); if (!string.IsNullOrEmpty(entity?.LastReadChapterName)) { item.LastReadChapterName = entity.LastReadChapterName; var sim = LevenshteinDistancePercent(item.LastReadChapterName, item.NewestChapterName); if (sim) { item.UnReadCountData = ""; } else { item.UnReadCountData = "(有更新)"; } } else { item.UnReadCountData = "(有更新)"; item.LastReadChapterName = item.NewestChapterName; } ShelfBookList.Add(item); } DBBookShelf.ClearBooks(AppDataPath.GetBookShelfDBPath()); DBBookShelf.InsertOrUpdateBooks(AppDataPath.GetBookShelfDBPath(), ShelfBookList.ToList()); } } ToastHeplper.ShowMessage("个人书架已更新"); } }
public void AddEntityToList(BookEntity entity) { Task.Run(async() => { if (ShelfBookList.ToList().Find(p => p.BookID == entity.BookID) == null) { string html = await(new HttpHelper()).WebRequestGet(string.Format(ViewModelInstance.Instance.UrlService.GetAddToShelfPage(), entity.BookID)); if (html.Contains("{\"success\":true}")) { DispatcherHelper.CheckBeginInvokeOnUI(() => { var temp = entity.Clone(); temp.LastReadChapterName = temp.NewestChapterName; temp.UnReadCountData = null; var result = DBBookShelf.InsertOrUpdateBook(AppDataPath.GetBookShelfDBPath(), temp); ShelfBookList.Insert(0, temp); RefreshList(); }); } else { ToastHeplper.ShowMessage(entity.BookName + " 添加至个人书架失败"); } } else { DispatcherHelper.CheckBeginInvokeOnUI(() => { var temp = ShelfBookList.ToList().Find(p => p.BookID == entity.BookID); var sim = LevenshteinDistancePercent(temp.LastReadChapterName, entity.NewestChapterName); if (!sim) { temp.LastReadChapterName = temp.NewestChapterName; temp.UnReadCountData = null; var result = DBBookShelf.InsertOrUpdateBook(AppDataPath.GetBookShelfDBPath(), temp); } }); } }); }