public PostRequest Category(CNHCategory category) { if (category != CNHCategory.Latest) { AddParam("categories", (int)category); } CurrentCategory = category; return this; }
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; }
/// <summary> /// Create necessary directory and return file path /// </summary> /// <param name="category"></param> /// <returns></returns> static string GetPostFilePath(CNHCategory category) { // CNHSpotlightCache/posts/{category} string path = Path.Combine( Android.OS.Environment.ExternalStorageDirectory.Path, "CNHSpotlightCache", "posts"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = Path.Combine(path, category.ToString()); return(file); }
public static void SavePosts(List <Post> data, CNHCategory category, int index) { List <Post> finalPostList = new List <Post>(); var posts = GetAllPostsOffline(new WordPressManager.PostRequest().Category(category)); // try to get saved postList if it exists if (posts.Result == TaskResult.Success) { finalPostList = posts.Data; } finalPostList.ReplaceItemRange(index, data); using (StreamWriter streamWriter = new StreamWriter(GetPostFilePath(category))) { streamWriter.Write(JsonConvert.SerializeObject(finalPostList)); } }
public async Task FetchNews(CNHCategory category) { await currentAdapter.FetchNews(category); }
/// <summary> /// Call fetch news from NewsFragment /// </summary> private async Task FetchNews(CNHCategory category) { await newsFragment.FetchNews(category); }