Пример #1
0
        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("个人书架已更新");
            }
        }
Пример #2
0
 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);
                 }
             });
         }
     });
 }
Пример #3
0
        private void OnBookItemSelectedCommand(object obj)
        {
            if (IsLoading)
            {
                return;
            }
            BookEntity entity = obj as BookEntity;

            if (entity != null)
            {
                if (IsEditing)
                {
                    entity.IsSelected = !entity.IsSelected;

                    IsAllSelected = true;
                    foreach (var item in ShelfBookList)
                    {
                        if (!item.IsSelected)
                        {
                            IsAllSelected = false;
                            break;
                        }
                    }
                }
                else
                {
                    ViewModelInstance.Instance.MainPageViewModelInstance.OnBookItemSelectedChangedCommand(obj);

                    if (!string.IsNullOrEmpty(entity.UnReadCountData) || !entity.LastReadChapterName.Equals(entity.NewestChapterName))
                    {
                        entity.UnReadCountData     = string.Empty;
                        entity.LastReadChapterName = entity.NewestChapterName;
                        var result = DBBookShelf.InsertOrUpdateBook(AppDataPath.GetBookShelfDBPath(), entity);
                    }
                }
            }
        }