/// <summary> /// 获取图片类别列表 /// </summary> /// <param name="local">是否直接从本地获取类别,否-则先从网络上获取分类数据</param> /// <returns></returns> public static TypeTotal GetTypeList(bool local = false) { if (!local) { GetTypeByWeb(); } TypeTotal model = Common.JsonHelper.DeserializeJsonToObject <TypeTotal>(ConfigManage.Base.TypeJson); if (model != null && model.data != null) { model.data.Insert(0, new TypeList() { id = "recommend", name = "兴趣推荐" }); model.data.Insert(0, new TypeList() { id = "love", name = "我的收藏" }); model.data.Insert(0, new TypeList() { id = "down", name = "我的下载" }); model.data.Insert(0, new TypeList() { id = "wall", name = "历史壁纸" }); } return(model); }
/// <summary> /// 通过Web接口获取最新的壁纸类型,并保存到配置 /// </summary> private static void GetTypeByWeb() { string jsonStr = WebHelper.HttpGet(Const.Url_Type); TypeTotal model = Common.JsonHelper.DeserializeJsonToObject <TypeTotal>(jsonStr); // 如果正确获取到信息,则将字符串存储到本地(防止下次因为服务器接口问题导致无法正确获取数据) if (model != null && model.data != null && model.data.Count > 0) { ConfigManage.Base.TypeJson = jsonStr; ConfigManage.Save(); } else { LogHelper.WriteLog("获取的图片类型Json数据为空:" + jsonStr, Common.EnumLogLevel.Error); } }
/// <summary> /// 初始化壁纸分类按钮 /// </summary> private void InitPicTypeBtn() { try { // 最新 TabItem item = new TabItem(); item.Name = "btn_type_0"; item.TabIndex = 99; item.Header = "最新"; item.Tag = 0; tabControl.Items.Add(item); TypeTotal total = WebImage.GetTypeList(true); if (total != null && total.data != null && total.data.Count > 0) { int tabIndex = 100; int index = 1; foreach (TypeList type in total.data) { item = new TabItem(); item.Name = "btn_type_" + index++; item.TabIndex = ++tabIndex; item.Header = type.name; item.Tag = type.id; item.Visibility = Visibility.Collapsed; tabControl.Items.Add(item); } window_SizeChanged(null, null); } } catch (Exception ex) { LogHelper.WriteLog(ex.Message, EnumLogLevel.Error); HandyControl.Controls.Growl.Error(ex.Message); } }
private void LoadData() { TypeTotal typeTotal = WebImage.GetTypeList(true); typeTotal.data.Insert(0, new TypeList() { id = "0", name = "最新" }); #region 基本 cbox_basic_AutoOn.IsChecked = ConfigManage.Base.AutoOn; cbox_basic_Cache.IsChecked = ConfigManage.Base.Cache; cbox_basic_AutoClearCache.IsChecked = ConfigManage.Base.AutoClearCache; cbox_basic_ExcludeDislike.IsChecked = ConfigManage.Base.ExcludeDislike; tbox_basic_DownPath.Text = ConfigManage.Base.DownPath; tbox_basic_CachePath.Text = ConfigManage.Base.CachePath; #endregion 基本 #region 壁纸 cbox_wallpaper_AutoReplace.IsChecked = ConfigManage.Wallpaper.AutoReplace; nbox_wallpaper_Interval.Value = ConfigManage.Wallpaper.TimeInterval; // 壁纸类型 string[] typeList = ConfigManage.Wallpaper.SelectedTypes.Split(','); foreach (var type in typeTotal.data) { Tag tag = new Tag(); tag.Margin = new Thickness(0); tag.Selectable = true; tag.ShowCloseButton = false; tag.Content = type.name; tag.Tag = type.id; tag.IsSelected = typeList.Contains(type.id); cbox_wallpaper_SelectedTypes.Children.Add(tag); } // 初始化 RadioButton switch (ConfigManage.Wallpaper.TimeType) { case TimeType.Day: WallTimeType_Day.IsChecked = true; break; case TimeType.Hour: WallTimeType_Hour.IsChecked = true; break; case TimeType.Minute: WallTimeType_Minute.IsChecked = true; break; } #endregion #region 屏保 cbox_screen_AutoReplace.IsChecked = ConfigManage.Screen.Open; nbox_screen_OpenInterval.Value = ConfigManage.Screen.OpenInterval; nbox_screen_ReplaceInterval.Value = ConfigManage.Screen.ReplaceInterval; // 壁纸类型 typeList = ConfigManage.Screen.SelectedTypes.Split(','); foreach (var type in typeTotal.data) { Tag tag = new Tag(); tag.Margin = new Thickness(0); tag.Selectable = true; tag.ShowCloseButton = false; tag.Content = type.name; tag.Tag = type.id; tag.IsSelected = typeList.Contains(type.id); cbox_screen_SelectedTypes.Children.Add(tag); } #endregion }