Ejemplo n.º 1
0
        public async Task FetchNews(CNHCategory category)
        {
            // clear posts in case category is changed
            if (category != Category)
            {
                ClearItems();
            }

            IsLoading = true;
            OnLoading();

            WordPressManager.PostRequest postRequest = new WordPressManager.PostRequest();
            postRequest
            .Embeded()
            .Category(category)
            .Quantity(10)
            .Search(SearchKeyword)
            .Save(!IsSearchOn)
            .Update(IsSearchOn && ConnectionInfo.InternetConnected());
            var postsData = await WordpressExtension.GetPosts(postRequest);

            switch (postsData.Result)
            {
            case TaskResult.Error:
                OnError();
                break;

            case TaskResult.NoInternet:
                OnConnectionError();
                break;

            case TaskResult.NoData:
                OnNoData();
                break;

            case TaskResult.Success:
                ReplaceItems(postsData.Data);
                break;

            default:
                break;
            }

            Category = category;

            IsLoading = false;
            OnLoaded();

            CanLoadMore = true;
        }
Ejemplo n.º 2
0
        public async Task LoadMore()
        {
            if (IsLoadingMore || !CanLoadMore)
            {
                return;
            }

            SetLoadingAnimation(true);

            WordPressManager.PostRequest postRequest = new WordPressManager.PostRequest();
            int indexSubstitution = IsLoadingMore ? 1 : 0;

            postRequest
            .Embeded()
            .Category(Category)
            .Quantity(10)
            .Offset(ItemCount - indexSubstitution)
            .Search(SearchKeyword)
            .Save(!IsSearchOn)
            .Update(IsSearchOn && ConnectionInfo.InternetConnected());

            var postsData = await WordpressExtension.GetPosts(postRequest);

            switch (postsData.Result)
            {
            case TaskResult.Error:
                OnError();
                break;

            case TaskResult.NoInternet:
                OnConnectionError();
                break;

            case TaskResult.NoData:
                CanLoadMore = false;
                break;

            case TaskResult.Success:
                AddItems(postsData.Data);
                break;

            default:
                break;
            }

            SetLoadingAnimation(false);
        }
Ejemplo n.º 3
0
        public async Task RefreshNews()
        {
            IsLoading = true;
            OnLoading();

            WordPressManager.PostRequest postRequest = new WordPressManager.PostRequest();
            postRequest
            .Embeded()
            .Category(Category)
            .Quantity(10)
            .Search(SearchKeyword)
            .Update(true)
            .Save(!IsSearchOn);

            var postsData = await WordpressExtension.GetPosts(postRequest);

            switch (postsData.Result)
            {
            case TaskResult.Error:
                OnError();
                break;

            case TaskResult.NoInternet:
                OnConnectionError();
                break;

            case TaskResult.NoData:
                OnNoData();
                break;

            case TaskResult.Success:
                ReplaceItems(postsData.Data);
                break;

            default:
                break;
            }

            IsLoading = false;
            OnLoaded();

            CanLoadMore = true;
        }