Exemplo n.º 1
0
        /// <summary>
        /// 分页获取主题日报中的文章
        /// </summary>
        /// <param name="theme_id"></param>
        /// <param name="last_story_id"></param>
        /// <returns></returns>
        public async Task<List<Story>> GetBeforeThemeStories(string theme_id, string last_story_id)
        {
            try
            {
                if (NetworkManager.Current.Network == 4)
                {
                    List<Story> l = await FileHelper.Current.ReadObjectAsync<List<Story>>(theme_id + "_" + last_story_id + "_before_theme_stories.json");
                    return l;
                }
                else
                {
                    string url = string.Format(ServiceURL.BeforeThemeStories, theme_id, last_story_id);
                    JsonObject json = await GetJson(url);
                    if (json != null)
                    {
                        List<Story> stories_list = new List<Story>();

                        var stories = json["stories"];
                        Story tmp;
                        if (stories != null)
                        {
                            JsonObject jo;
                            JsonArray ja = stories.GetArray();
                            string image_s = "";
                            WriteableBitmap wb = null; string image_ext = "jpg"; string[] sitem = null;

                            foreach (var jv in ja)
                            {
                                image_s = "";
                                jo = jv.GetObject();
                                if (jo.ContainsKey("images"))
                                {
                                    image_s = jo["images"].GetArray()[0].GetString();
                                }
                                tmp = new Story { ID = jo["id"].GetNumber().ToString(), Image = image_s, Title = jo["title"].GetString() };

                                if (!await FileHelper.Current.CacheExist(tmp.ID + "_story_image." + image_ext) && !tmp.Image.Equals(""))  //没有缓存
                                {
                                    wb = await GetImage(tmp.Image);  //下载图片
                                    if (!tmp.Image.Equals(""))
                                    {
                                        sitem = tmp.Image.Split('.');
                                        image_ext = sitem[sitem.Count() - 1];
                                    }
                                    await FileHelper.Current.SaveImageAsync(wb, tmp.ID + "_story_image." + image_ext); //保存图片
                                }
                                if (!tmp.Image.Equals(""))
                                {
                                    tmp.Image = _local_path + "\\images_cache\\" + tmp.ID + "_story_image." + image_ext;  //图片路径重定向
                                }

                                //tmp.Favorite = DataShareManager.Current.FavoriteList.Contains(tmp.ID) ? true : false;  //是否收藏
                                //tmp.Readed = DataShareManager.Current.ReadedList.Contains(tmp.ID) ? true : false;  //是否已读
                                stories_list.Add(tmp);
                            }
                        }
                        await FileHelper.Current.WriteObjectAsync<List<Story>>(stories_list, theme_id + "_" + last_story_id + "_before_theme_stories.json");
                        return stories_list;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 主题日报中最近文章
        /// </summary>
        /// <param name="theme_id"></param>
        /// <returns></returns>
        public async Task<LatestThemeStories> GetLatestThemeStories(string theme_id)
        {
            try
            {
                if (NetworkManager.Current.Network == 4)
                {
                    LatestThemeStories lst = await FileHelper.Current.ReadObjectAsync<LatestThemeStories>(theme_id + "_latest_theme_stories.json");
                    return lst;
                }
                else
                {
                    string url = string.Format(ServiceURL.ThemeStories, theme_id);
                    JsonObject json = await GetJson(url);
                    if (json != null)
                    {
                        ObservableCollection<Editor> editors_list = new ObservableCollection<Editor>();
                        ObservableCollection<Story> stories_list = new ObservableCollection<Story>();

                        string background = json["background"].GetString();
                        string description = json["description"].GetString();
                        string image = json["image"].GetString();
                        string image_source = json["image_source"].GetString();
                        string name = json["name"].GetString();

                        WriteableBitmap wb = null;string image_ext = "jpg";string[] sitem = null;

                        if (json.ContainsKey("editors"))
                        {
                            var editors = json["editors"];
                            if (editors != null)
                            {
                                JsonObject jo;
                                JsonArray ja = editors.GetArray();
                                foreach (var jv in ja)
                                {
                                    jo = jv.GetObject();
                                    Editor tmp = new Editor
                                    {
                                        Avatar = jo.ContainsKey("avatar") ? jo["avatar"].GetString() : "",
                                        Bio = jo.ContainsKey("bio") ? jo["bio"].GetString() : "",
                                        ID = jo["id"].GetNumber().ToString(),
                                        Name = jo["name"].GetString(),
                                        URL = jo.ContainsKey("url") ? jo["url"].GetString() : ""
                                    };

                                    if (!await FileHelper.Current.CacheExist(tmp.ID + "_editor_avatar." + image_ext)) //没有缓存
                                    {
                                        wb = await GetImage(tmp.Avatar);  //下载图片
                                        if (!tmp.Avatar.Equals(""))
                                        {
                                            sitem = tmp.Avatar.Split('.');
                                            image_ext = sitem[sitem.Count() - 1];
                                        }
                                        await FileHelper.Current.SaveImageAsync(wb, tmp.ID + "_editor_avatar." + image_ext); //保存图片
                                    }
                                    if(!tmp.Avatar.Equals(""))  //重定向路径
                                    {
                                        tmp.Avatar = _local_path + "\\images_cache\\" + tmp.ID + "_editor_avatar." + image_ext;
                                    }
                                    editors_list.Add(tmp);
                                }
                            }
                        }
                        if (json.ContainsKey("stories"))
                        {
                            var stories = json["stories"];
                            Story tmp;
                            if (stories != null)
                            {
                                JsonObject jo;
                                JsonArray ja = stories.GetArray();
                                string image_s = "";
                                foreach (var jv in ja)
                                {
                                    image_s = "";
                                    jo = jv.GetObject();
                                    if (jo.ContainsKey("images"))
                                    {
                                        image_s = jo["images"].GetArray()[0].GetString();
                                    }
                                    tmp = new Story { ID = jo["id"].GetNumber().ToString(), Image = image_s, Title = jo["title"].GetString() };

                                    if (!await FileHelper.Current.CacheExist(tmp.ID + "_story_image." + image_ext) && !tmp.Image.Equals("")) //没有缓存
                                    {
                                        wb = await GetImage(tmp.Image);  //下载图片
                                        if (!tmp.Image.Equals(""))
                                        {
                                            sitem = tmp.Image.Split('.');
                                            image_ext = sitem[sitem.Count() - 1];
                                        }
                                        await FileHelper.Current.SaveImageAsync(wb, tmp.ID + "_story_image." + image_ext); //保存图片
                                    }
                                    if (!tmp.Image.Equals(""))
                                    {
                                        tmp.Image = _local_path + "\\images_cache\\" + tmp.ID + "_story_image." + image_ext;  //图片路径重定向
                                    }

                                    //tmp.Favorite = DataShareManager.Current.FavoriteList.Contains(tmp.ID) ? true : false;  //是否收藏
                                    //tmp.Readed = DataShareManager.Current.ReadedList.Contains(tmp.ID) ? true : false;  //是否已读
                                    stories_list.Add(tmp);
                                }
                            }
                        }
                        LatestThemeStories lts = new LatestThemeStories
                        {
                            Background = background,
                            Description = description,
                            Editors = editors_list,
                            Image = image,
                            Image_Source = image_source,
                            Name = name,
                            Stories = stories_list
                        };
                        await FileHelper.Current.WriteObjectAsync<LatestThemeStories>(lts, theme_id + "_latest_theme_stories.json");
                        return lts;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 3
0
 public void ExchangeReaded(Story story)
 {
     story.Readed = true;
     DataShareManager.Current.UpdateReadeds(_story_id);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 主页最近文章
        /// </summary>
        /// <returns></returns>
        public async Task<LatestStories> GetLatestStories()
        {
            try
            {
                if (NetworkManager.Current.Network == 4)
                {
                    LatestStories l = await FileHelper.Current.ReadObjectAsync<LatestStories>("latest_stories.json");
                    return l;
                }
                else
                {
                    JsonObject json = await GetJson(ServiceURL.LatestStories);
                    if (json != null)
                    {
                        ObservableCollection<Story> stories_list = new ObservableCollection<Story>();
                        ObservableCollection<Story> top_stories_list = new ObservableCollection<Story>();
                        Story tmp;
                        var stories = json["stories"];
                        WriteableBitmap wb = null; string image_ext = "jpg";string[] sitem = null;
                        if (stories != null)
                        {
                            JsonArray ja = stories.GetArray();
                            JsonObject jo; string image; bool multiPic = false;

                            foreach (var j in ja)
                            {
                                jo = j.GetObject();
                                multiPic = jo.ContainsKey("multipic") && (jo["multipic"].GetBoolean());
                                image = jo["images"].GetArray()[0].GetString();
                                tmp = new Story { Date = json["date"].GetString(), ID = jo["id"].GetNumber().ToString(), Image = image, Title = jo["title"].GetString(), MultiPic = multiPic };

                                if (!await FileHelper.Current.CacheExist(tmp.ID + "_story_image." + image_ext)) //没有缓存
                                {
                                    wb = await GetImage(tmp.Image);  //下载图片
                                    if (!tmp.Image.Equals(""))
                                    {
                                        sitem = tmp.Image.Split('.');
                                        image_ext = sitem[sitem.Count() - 1];
                                    }
                                    await FileHelper.Current.SaveImageAsync(wb, tmp.ID + "_story_image." + image_ext); //保存图片
                                }
                                if (!tmp.Image.Equals(""))
                                {
                                    tmp.Image = _local_path + "\\images_cache\\" + tmp.ID + "_story_image." + image_ext;  //图片路径重定向
                                }
                                //tmp.Favorite = DataShareManager.Current.FavoriteList.Contains(tmp.ID) ? true : false;  //是否收藏
                                //tmp.Readed = DataShareManager.Current.ReadedList.Contains(tmp.ID) ? true : false;  //是否已读
                                stories_list.Add(tmp);
                            }
                        }

                        var top_stories = json["top_stories"];
                        if (top_stories != null)
                        {
                            JsonArray ja = top_stories.GetArray();
                            JsonObject jo;
                            foreach (var j in ja)
                            {
                                jo = j.GetObject();
                                tmp = new Story { Date = json["date"].GetString(), Favorite = false, ID = jo["id"].GetNumber().ToString(), Image = jo["image"].GetString(), Title = jo["title"].GetString() };

                                if (!await FileHelper.Current.CacheExist(tmp.ID + "_story_top_image." + image_ext)) //没有缓存
                                {
                                    wb = await GetImage(tmp.Image);  //下载图片
                                    if (!tmp.Image.Equals(""))
                                    {
                                        sitem = tmp.Image.Split('.');
                                        image_ext = sitem[sitem.Count() - 1];
                                    }
                                    await FileHelper.Current.SaveImageAsync(wb, tmp.ID + "_story_top_image." + image_ext); //保存图片
                                }
                                if (!tmp.Image.Equals(""))
                                {
                                    tmp.Image = _local_path + "\\images_cache\\" + tmp.ID + "_story_top_image." + image_ext;  //图片路径重定向
                                }

                                top_stories_list.Add(tmp);
                            }
                        }
                        LatestStories ls = new LatestStories { Date = json["date"].GetString(), Stories = stories_list, Top_Stories = top_stories_list };
                        await FileHelper.Current.WriteObjectAsync<LatestStories>(ls, "latest_stories.json");
                        return ls;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 5
0
        public StoryViewModel(Story story)
        {
            _story_id = story.ID;
            _story = story;
            DataShareManager.Current.ShareDataChanged += Current_ShareDataChanged;
            Update();

            ExchangeReaded(story);
        }