public EditorInfoViewModel(Editor editor) { _editor = editor; Update(); }
/// <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; } }