Ejemplo n.º 1
0
        public PeopleTopicView()
        {
            InitializeComponent();
            var click = Observable
                        .FromEventPattern <ItemClickEventArgs>(PeopleTopicsList, nameof(PeopleTopicsList.ItemClick))
                        .Select(x => x.EventArgs.ClickedItem as TopicModel)
                        .ObserveOnCoreDispatcher()
                        .Subscribe(x => PageStack.Next("Right", "Right", typeof(RepliesAndTopicView), x.Id));

            NotifyData.LoadDataTask = async count =>
            {
                var html = await ApiClient.GetFavoriteTopics(NotifyData.CurrentPage);

                var dom = new HtmlParser().ParseDocument(html);
                return(new PagesBaseModel <TopicModel>
                {
                    Pages = DomParse.ParseMaxPage(dom),
                    Entity = DomParse.ParseTopics(dom) ?? new List <TopicModel>()
                });
            };

            _events = new List <IDisposable> {
                click
            };
        }
        public CollectedTopicsFragment()
        {
            InitializeComponent();
            LabelPanel.ItemsSource = _tabs;
            async Task <IEnumerable <TopicModel> > loadData()
            {
                var model = LabelPanel.SelectedItem as CollectedListModel;
                var html  = await ApiClient.GetTopicsWithTab(model.Name);

                var dom = new HtmlParser().ParseDocument(html);

                return(DomParse.ParseTopics(dom));
            }

            var selectionChanged = Observable
                                   .FromEventPattern <SelectionChangedEventArgs>(LabelPanel, nameof(LabelPanel.SelectionChanged))
                                   .SelectMany(x => loadData())
                                   .Retry(10)
                                   .ObserveOnCoreDispatcher()
                                   .Subscribe(x =>
            {
                News.Clear();
                foreach (var item in x)
                {
                    News.Add(item);
                }
            });
            var click = Observable.FromEventPattern <ItemClickEventArgs>(NewsList, nameof(NewsList.ItemClick))
                        .Select(x => x.EventArgs.ClickedItem as TopicModel)
                        .ObserveOnCoreDispatcher()
                        .Subscribe(x => PageStack.Next("Left", "Right", typeof(RepliesAndTopicView), x.Id));
            var refresh = Observable.FromEventPattern <TappedRoutedEventArgs>(Refresh, nameof(Refresh.Tapped))
                          .SelectMany(x => loadData())
                          .Retry(10)
                          .ObserveOnCoreDispatcher()
                          .Subscribe(x =>
            {
                News.Clear();
                foreach (var item in x)
                {
                    News.Add(item);
                }
            });

            LabelPanel.SelectedIndex = 0;

            this.Unloaded += (s, e) =>
            {
                selectionChanged.Dispose();
                click.Dispose();
                refresh.Dispose();
            };
        }