Example #1
0
        public async Task <IEnumerable <FavourVolume> > LoadAsync(bool foreceRefresh = false, int maxItemCount = 9)
        {
            if (!IsLoading && !IsLoaded && LightKindomHtmlClient.IsSignedIn)
            {
                IsLoading = true;
                try
                {
                    await App.Current.User.SyncFavoriteListAsync(foreceRefresh);

                    var favList = App.Current.User.FavoriteList.Take(maxItemCount);

                    foreach (var item in favList)
                    {
                        this.Add(item);
                        var vol = await CachedClient.GetVolumeAsync(item.VolumeId);

                        item.CoverImageUri = vol.CoverImageUri;
                        item.Description   = vol.Description;
                        NotifyPropertyChanged("IsEmpty");
                    }

                    IsLoading = false;
                    IsLoaded  = true;
                    return(favList);
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.Message);
                    IsLoading = false;
                    IsLoaded  = false;
                }
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public async Task LoadSeriesIndexDataAsync()
        {
            if (IsIndexDataLoaded)
            {
                return;
            }
            LoadingText = "Loading series index data...";
            IsLoading   = true;
            try
            {
                var serIndex = await CachedClient.GetSeriesIndexAsync();

                //var serVmList = serIndex.Select(series => new SeriesPreviewModel { ID = series.Id, Title = series.Title });
                var cgs = new Windows.Globalization.Collation.CharacterGroupings();
                SeriesIndex = (from series in serIndex
                               group series
                               by cgs.Lookup(series.Title) into g
                               orderby g.Key
                               select g).ToList();

                //SeriesIndex = AlphaKeyGroup<SeriesPreviewModel>.CreateGroups(
                //	serVmList,
                //	new System.Globalization.CultureInfo("zh-Hans"),
                //	svm => svm.Title, true);
                IsIndexDataLoaded = true;
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Exception when retrieving series index : " + exception.Message);
                //throw exception;
                //MessageBox.Show(exception.Message, "Data error", MessageBoxButton.OK);
            }
            IsLoading = false;
        }
Example #3
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public async Task LoadSeriesIndexDataAsync()
        {
            if (IsLoading || IsIndexDataLoaded)
            {
                return;
            }
            LoadingText = "Loading series index data...";
            IsLoading   = true;
            try
            {
                var serIndex = await CachedClient.GetSeriesIndexAsync();

                var serVmList = serIndex.Select(series => new SeriesPreviewModel {
                    ID = series.Id, Title = series.Title
                });
                SeriesIndex = AlphaKeyGroup <SeriesPreviewModel> .CreateGroups(
                    serVmList,
                    new System.Globalization.CultureInfo("zh-CN"),
                    svm => svm.Title, true);

                IsIndexDataLoaded = true;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Data error", MessageBoxButton.OK);
            }
            IsLoading = false;
        }
        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);
            }
        }
        public async Task LoadDataAsync(string id, bool loadCommentsList)
        {
            //await DataCache.ClearAll();
            IsLoading = true;
            ChapterId = id;
            Chapter chapter = null;

            try
            {
                chapter = await CachedClient.GetChapterAsync(id);
            }
            catch (Exception exception)
            {
                IsLoading = false;
                ChapterId = 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);
            }
            if (chapter != null)
            {
                DataContext = chapter;
            }
            if (!loadCommentsList)
            {
                IsLoading = false;
                return;
            }
            try
            {
                await LoadCommentListAsync();

                //foreach (LineViewModel line in vm.Lines)
                //{
                //    if (line.HasComments && line.Comments.Count == 0 && !line.IsLoading)
                //    await ViewModel.LoadCommentsAsync(line);
                //}
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Failed to retrive comment data : " + exception.Message);
                //MessageBox.Show(exception.Message, "Failed to retrive comment data.", MessageBoxButton.OK);
            }
            IsLoading = false;
        }
Example #6
0
        public async Task <IDictionary <string, IList <BookItem> > > LoadAsync(bool forceRefresh = false, int maxVolumeCount = 9)
        {
            if (!IsLoading && (!IsLoaded || forceRefresh))
            {
                IsLoading = true;
                try
                {
                    var recommandBookGroups = await CachedClient.GetRecommandedBookLists(forceRefresh);

                    this.Clear();
                    foreach (var bookGroup in recommandBookGroups)
                    {
                        var group = new KeyGroup <string, BookCoverViewModel>
                        {
                            Key = bookGroup.Key
                        };
                        if (bookGroup.Value.Count <= maxVolumeCount)
                        {
                            group.AddRange(bookGroup.Value.Select(x => new BookCoverViewModel(x)));
                        }
                        else
                        {
                            group.AddRange(bookGroup.Value.Take(maxVolumeCount).Select(x => new BookCoverViewModel(x)));
                        }
                        this.Add(group);
                    }
                    IsLoading = false;
                    IsLoaded  = true;
                    NotifyPropertyChanged("IsEmpty");
                    return(recommandBookGroups);
                }
                catch (Exception exception)
                {
                    IsLoading = false;
                    IsLoaded  = false;
                    Debug.WriteLine(exception.Message);
                    return(null);
                }
            }
            return(null);
        }
Example #7
0
        public async Task LoadRecommandDataAsync()
        {
            if (IsLoading || IsRecommandLoaded)
            {
                return;
            }
            LoadingText = "Loading recommand books";
            IsLoading   = true;
            try
            {
                var recommandBookGroups = await CachedClient.GetRecommandedBookLists();

                RecommandBookItems = new List <KeyGroup <string, BookCoverViewModel> >();
                foreach (var bookGroup in recommandBookGroups)
                {
                    var group = new KeyGroup <string, BookCoverViewModel>
                    {
                        Key = bookGroup.Key
                    };
                    if (bookGroup.Value.Count <= 12)
                    {
                        group.AddRange(bookGroup.Value.Select(x => new BookCoverViewModel(x)));
                    }
                    else
                    {
                        group.AddRange(bookGroup.Value.Take(12).Select(x => new BookCoverViewModel(x)));
                    }
                    RecommandBookItems.Add(group);
                }
                IsLoading         = false;
                IsRecommandLoaded = true;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Exception when retriving recommanded books", MessageBoxButton.OK);
                IsLoading = false;
            }
        }
        public async Task LoadDataAsync(string id)
        {
            IsLoading = true;
            Id        = id;
            try
            {
                var volume = await CachedClient.GetVolumeAsync(id);

                DataContext = volume;
                IsLoading   = false;
                //Title = volume.Title;
                //Author = volume.Author;
                //Description = volume.Description;
                //CoverImageUri = new Uri(volume.CoverImageUri);
                //Illustrator = volume.Illustrator;
                //ChapterList.Clear();
                //int no = 0;
                //foreach (var cp in volume.ChapterDescriptorList)
                //{
                //    var cpvm = new ChapterPreviewModel
                //    {
                //        Title = cp.Title,
                //        Id = cp.Id,
                //        No = no++
                //    };
                //    ChapterList.Add(cpvm);
                //}
                //IsLoading = false;
            }
            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);
            }
        }
Example #9
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;
        }
Example #10
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;
            }
        }