Exemplo n.º 1
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);
                 }
             });
         }
     });
 }
Exemplo n.º 2
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);
                    }
                }
            }
        }