Exemplo n.º 1
0
 public void AddtoDownloads(ChapterListItemViewModel chapter)
 {
     if (mangaSavePath == null)
     {
         SetMangaPath();
         SaveMangaInfo();
     }
     else if (savedinfo?.chapters.Count != ChapterList.Count)
     {
         SaveMangaInfo();
     }
     MainView.DownloadsPanelViewModel.AddDownload(chapter.URL, chapter.Name, Name);
 }
Exemplo n.º 2
0
        public void ImportMangaInfo()
        {
            Url         = savedinfo.url;
            Name        = savedinfo.name;
            Description = savedinfo.description;
            ImageSource = savedinfo.image?.ToFreezedBitmapImage();
            IsFavourite = savedinfo.isFavourite;
            IsCompleted = savedinfo.isCompleted;

            Dispatcher dispatcher;

            if (Dispatcher.CurrentDispatcher != Application.Current.Dispatcher)
            {
                dispatcher = Application.Current.Dispatcher;
            }
            else
            {
                dispatcher = Dispatcher.CurrentDispatcher;
            }

            dispatcher.Invoke(() =>
            {
                AuthorList = savedinfo.authors;

                GenreList.Clear();
                for (int i = 0; i < savedinfo.genres.Count; i++)
                {
                    GenreList.Add(new GenreItemViewModel {
                        Text = savedinfo.genres[i]
                    });
                }

                ChapterList.Clear();
                for (int i = 0; i < savedinfo.chapters.Count; i++)
                {
                    ChapterListItemViewModel model = new ChapterListItemViewModel(this, i)
                    {
                        Name = savedinfo.chapters[i],
                        URL  = savedinfo.chapterUrls[i]
                    };

                    model.CheckIfDownloaded();

                    ChapterList.Add(model);
                }
            });
        }
Exemplo n.º 3
0
 public void SetSelectors(ChapterListItemViewModel item)
 {
     if (_SelectedMemory[0] != null)
     {
         if (_SelectedMemory[1] != null)
         {
             _SelectedMemory = new ChapterListItemViewModel[2];
             bool data = !item.IsSelected;
             for (int i = 0; i < ChapterList.Count; i++)
             {
                 ChapterList[i].FromMangaView = true;
                 ChapterList[i].IsSelected    = false;
                 ChapterList[i].FromMangaView = false;
             }
             if (data)
             {
                 return;
             }
             item.FromMangaView = true;
             item.IsSelected    = true;
             item.FromMangaView = false;
             SetSelectors(item);
         }
         else
         {
             _SelectedMemory[1] = item;
             int range         = _SelectedMemory[0].Index - _SelectedMemory[1].Index;
             int indexModifier = range > 0 ? -1 : 1;
             for (int i = 0; i < Math.Abs(range); i++)
             {
                 int newIndex = _SelectedMemory[0].Index + (i * indexModifier);
                 ChapterList[newIndex].FromMangaView = true;
                 ChapterList[newIndex].IsSelected    = true;
                 ChapterList[newIndex].FromMangaView = false;
             }
         }
     }
     else
     {
         _SelectedMemory[0] = item;
     }
 }
Exemplo n.º 4
0
        public async Task LoadData(string _url)
        {
            url = _url;

            #region Get Data
            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(_url);

            IEnumerable <HtmlNode> infonodes = doc.DocumentNode.SelectNodes("//ul[contains(@class, 'manga-info-text')]").Descendants("li");

            //Get Name
            string name = infonodes.ElementAt(0).Descendants("h1").FirstOrDefault().InnerText;

            //get Image URL
            HtmlNode img         = doc.DocumentNode.SelectSingleNode("//div[@class='manga-info-pic']").Descendants("img").First();
            string   imageSource = img.Attributes["src"].Value;

            //Get Status
            string status = infonodes.ElementAt(2).InnerText.Substring(9);

            //Get Authors
            ObservableCollection <string> authors = new ObservableCollection <string>();

            IEnumerable <HtmlNode> authorNodes = infonodes.ElementAt(1).Descendants("a");
            for (int i = 0; i < authorNodes.Count(); i++)
            {
                authors.Add(authorNodes.ElementAt(i).InnerText);
            }

            //Get Genres
            ObservableCollection <string> genres = new ObservableCollection <string>();

            IEnumerable <HtmlNode> genreNodes = infonodes.ElementAt(6).Descendants("a");
            for (int i = 0; i < genreNodes.Count(); i++)
            {
                genres.Add(genreNodes.ElementAt(i).InnerText);
            }

            //Get Description
            HtmlNodeCollection descriptionNodes = doc.DocumentNode.SelectNodes("//div[@id='noidungm']/text()");

            StringBuilder sb = new StringBuilder();

            foreach (var node in descriptionNodes)
            {
                sb.Append(node.InnerText);
            }

            string description = Regex.Replace(sb.ToString(), @"\n|&#39;|&quot;", "");
            description = Regex.Replace(description, @"&#39;|&rsquo;", "'");

            //Get Chapter List
            ObservableCollection <ChapterInfo> chapters = new ObservableCollection <ChapterInfo>();

            IEnumerable <HtmlNode> chapterCollection = doc.DocumentNode.SelectNodes("//div[@class='chapter-list']").Descendants("div");

            ChapterInfo newChapter;
            foreach (var node in chapterCollection)
            {
                newChapter = new ChapterInfo();
                HtmlNode link = node.Descendants("span").First().Descendants("a").First();
                newChapter.href = link.Attributes["href"].Value;
                newChapter.Name = link.InnerText;

                chapters.Add(newChapter);
            }
            chapters.Reverse();
            #endregion

            #region Save Data
            _name        = name;
            _status      = status;
            _image       = imageSource.ToFreezedBitmapImage();
            _description = description;

            _authorList = authors;

            _genreList = new ObservableCollection <GenreItemViewModel>();
            foreach (var genre in genres)
            {
                _genreList.Add(new GenreItemViewModel
                {
                    Text = genre
                });
            }

            _chapterList = new ObservableCollection <ChapterListItemViewModel>();
            for (int i = 0; i < chapters.Count; i++)
            {
                ChapterListItemViewModel model = new ChapterListItemViewModel(MangaView, i)
                {
                    Name = chapters[i].Name,
                    URL  = chapters[i].href
                };

                model.CheckIfDownloaded();

                _chapterList.Add(model);
            }
            #endregion
        }