public async Task LoadDataAsync(string serId, string volId = "", string cptId = "")
        {
            IsLoading = true;
            Id        = serId;
            try
            {
                var series = await CachedClient.GetSeriesAsync(serId);

                DataContext = series;
            }
            catch (Exception exception)
            {
                IsLoading = false;
                Id        = null;
                MessageBox.Show("Network issue occured, please check your wi-fi or data setting and try again.\nError Code:" + exception.Message, "Network issue", MessageBoxButton.OK);
            }
        }
예제 #2
0
        public async Task LoadAsync(bool foreceRefresh = false, int maxItemCount = 9, bool forcePull = false)
        {
            if (IsLoading)
            {
                return;
            }
            IsLoading = true;
            try
            {
                await AppGlobal.PullBookmarkFromUserFavoriteAsync(foreceRefresh, forcePull);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                IsLoading = false;
                IsLoaded  = false;
                return;
            }

            for (int i = 0; i < this.Count; ++i)
            {
                var hvm      = this[i];
                var bookmark = AppGlobal.BookmarkList.FirstOrDefault(bk => bk.SeriesTitle == hvm.SeriesTitle);
                if (bookmark == null) //Thus we should remove this item from our collection
                {
                    this.RemoveAt(i);
                    --i;
                }
            }

            foreach (var bk in AppGlobal.BookmarkList)
            {
                var hvm = this.FirstOrDefault(vm => vm.Position.SeriesId == bk.Position.SeriesId);
                if (hvm == null)
                {
                    hvm = new HistoryItemViewModel(bk);
                    if (!String.IsNullOrEmpty(bk.DescriptionThumbnailUri))
                    {
                        hvm.CoverImageUri = bk.DescriptionThumbnailUri;
                    }
                    this.Add(hvm);
                    NotifyPropertyChanged("IsEmpty");
                    if (String.IsNullOrEmpty(bk.Position.SeriesId))
                    {
                        try
                        {
                            var volume = await CachedClient.GetSeriesAsync(bk.Position.SeriesId);

                            hvm.CoverImageUri          = volume.CoverImageUri;
                            hvm.Description            = volume.Description;
                            bk.Position.SeriesId       = volume.Id;
                            bk.ContentDescription      = volume.Description;
                            bk.DescriptionThumbnailUri = volume.CoverImageUri;
                        }
                        catch (Exception exception)
                        {
                            Debug.WriteLine(exception.Message);
                        }
                    }
                }
                else
                {
                    hvm.Position           = bk.Position;
                    hvm.ProgressPercentage = bk.Progress;
                    if (!String.IsNullOrEmpty(bk.DescriptionThumbnailUri))
                    {
                        hvm.CoverImageUri = bk.DescriptionThumbnailUri;
                    }
                    else if (bk.DescriptionImageUri != null)
                    {
                        hvm.CoverImageUri = bk.DescriptionImageUri;
                    }
                    hvm.Description  = bk.ContentDescription;
                    hvm.ChapterTitle = bk.ChapterTitle;
                    hvm.VolumeTitle  = bk.VolumeTitle;
                    hvm.SeriesTitle  = bk.SeriesTitle;
                    hvm.UpdateTime   = bk.ViewDate;
                }
            }
            NotifyPropertyChanged("IsEmpty");
            IsLoaded  = true;
            IsLoading = false;

            //await App.User.SyncFavoriteListAsync(foreceRefresh);

            //App.User.FavoriteList.CollectionChanged += FavoriteList_CollectionChanged;

            //var favList = from fav in App.User.FavoriteList orderby fav.VolumeNo group fav by fav.SeriesTitle ;

            //foreach (var series in favList)
            //{
            //	var vol = series.LastOrDefault();
            //	var item = new HistoryItemViewModel() { SeriesTitle = vol.SeriesTitle, VolumeTitle = vol.VolumeTitle, UpdateTime = vol.FavTime};
            //	var volume = await CachedClient.GetVolumeAsync(vol.VolumeId);
            //	item.CoverImageUri = volume.CoverImageUri;
            //	item.Description = volume.Description;
            //	item.Position = new NovelPositionIdentifier { SeriesId = volume.ParentSeriesId, VolumeId = volume.Id, VolumeNo = -1 };
            //	this.Add(item);
            //	NotifyPropertyChanged("IsEmpty");
            //}

            //IsLoading = false;
            //IsLoaded = true;
            //return App.User.FavoriteList;
        }
예제 #3
0
        private async void FavoriteList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            var FavoriteList = sender as ObservableCollection <FavourVolume>;

            switch (e.Action)
            {
            case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                foreach (FavourVolume vol in e.NewItems)
                {
                    var serp = this.FirstOrDefault(ser => ser.SeriesTitle == vol.SeriesTitle);
                    if (serp == null)
                    {
                        var item = new HistoryItemViewModel()
                        {
                            SeriesTitle = vol.SeriesTitle, VolumeTitle = vol.VolumeTitle, UpdateTime = vol.FavTime
                        };
                        var volume = await CachedClient.GetSeriesAsync(vol.VolumeId);

                        item.CoverImageUri = volume.CoverImageUri;
                        item.Description   = volume.Description;
                        item.Position      = new NovelPositionIdentifier {
                            SeriesId = volume.Id, VolumeId = volume.Id, VolumeNo = -1
                        };
                        this.Add(item);
                        NotifyPropertyChanged("IsEmpty");
                    }
                    else if (int.Parse(serp.Position.VolumeId) < int.Parse(vol.VolumeId))
                    {
                        serp.SeriesTitle = vol.SeriesTitle;
                        serp.VolumeTitle = vol.VolumeTitle;
                        serp.UpdateTime  = vol.FavTime;
                        var volume = await CachedClient.GetSeriesAsync(vol.VolumeId);

                        serp.CoverImageUri = volume.CoverImageUri;
                        serp.Description   = volume.Description;
                        serp.Position      = new NovelPositionIdentifier {
                            SeriesId = volume.Id, VolumeId = volume.Id, VolumeNo = -1
                        };
                    }
                }
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                foreach (FavourVolume vol in e.OldItems)
                {
                    var serp = this.FirstOrDefault(ser => ser.SeriesTitle == vol.SeriesTitle);
                    if (serp == null)
                    {
                        continue;
                    }
                    if (!FavoriteList.Any(f => f.SeriesTitle == serp.SeriesTitle))
                    {
                        this.Remove(serp);
                    }
                }
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                IsLoading = true;
                var favList = from fav in FavoriteList orderby fav.VolumeNo group fav by fav.SeriesTitle;
                this.Clear();
                foreach (var series in favList)
                {
                    var vol  = series.LastOrDefault();
                    var item = new HistoryItemViewModel()
                    {
                        SeriesTitle = vol.SeriesTitle, VolumeTitle = vol.VolumeTitle, UpdateTime = vol.FavTime
                    };
                    var volume = await CachedClient.GetSeriesAsync(vol.VolumeId);

                    item.CoverImageUri = volume.CoverImageUri;
                    item.Description   = volume.Description;
                    item.Position      = new NovelPositionIdentifier {
                        SeriesId = volume.Id, VolumeId = volume.Id, VolumeNo = -1
                    };
                    this.Add(item);
                    NotifyPropertyChanged("IsEmpty");
                }
                IsLoading = false;
                break;

            default:
                break;
            }
        }