Merge pull request #3207 from larsbrubaker/design_tools

Adding in bits to support new feed (has a list of banners)
This commit is contained in:
Lars Brubaker 2018-04-19 10:33:08 -07:00 committed by GitHub
commit 554a4abb87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1448 additions and 1418 deletions

View file

@ -95,7 +95,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab
try
{
var client = new HttpClient();
string json = await client.GetStringAsync($"http://www.matterhackers.com/feeds/explore?sk={sk}");
string json = await client.GetStringAsync($"http://www.matterhackers.com/feeds/{sk}");
return JsonConvert.DeserializeObject<ExplorerFeed>(json);
}
@ -113,45 +113,57 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab
{
foreach (var content in contentList.Content)
{
switch (content.content_type)
{
case "banner_image":
AddContentItem(content);
}
}
private void AddContentItem(ExploreFeedContent content)
{
switch (content.content_type)
{
case "banner_rotate":
// TODO: make this make a carousel rather than add the first item and rotate between all the items
var rand = new Random();
AddContentItem(content.banner_list[rand.Next(content.banner_list.Count)]);
break;
case "banner_image":
{
// Our banners seem to end with something like "=w1520-h170"
// if present use that to get the right width and height
int expectedWidth = 1520;
GCodeFile.GetFirstNumberAfter("=w", content.image_url, ref expectedWidth);
int expectedHeight = 170;
GCodeFile.GetFirstNumberAfter("-h", content.image_url, ref expectedHeight);
if ((content.theme_filter == "dark" && ActiveTheme.Instance.IsDarkTheme)
|| (content.theme_filter == "light" && !ActiveTheme.Instance.IsDarkTheme)
|| (content.theme_filter == "all"))
{
// Our banners seem to end with something like "=w1520-h170"
// if present use that to get the right width and height
int expectedWidth = 1520;
GCodeFile.GetFirstNumberAfter("=w", content.image_url, ref expectedWidth);
int expectedHeight = 170;
GCodeFile.GetFirstNumberAfter("-h", content.image_url, ref expectedHeight);
if ((content.theme_filter == "dark" && ActiveTheme.Instance.IsDarkTheme)
|| (content.theme_filter == "light" && !ActiveTheme.Instance.IsDarkTheme))
ImageBuffer image = new ImageBuffer(expectedWidth, expectedHeight);
ResponsiveImageWidget imageWidget = new ResponsiveImageWidget(image)
{
ImageBuffer image = new ImageBuffer(expectedWidth, expectedHeight);
ResponsiveImageWidget imageWidget = new ResponsiveImageWidget(image)
Margin = new BorderDouble(5),
};
if (content.link != null)
{
imageWidget.Cursor = Cursors.Hand;
imageWidget.Click += (s, e) =>
{
Margin = new BorderDouble(5),
ApplicationController.Instance.LaunchBrowser(content.link);
};
if (content.link != null)
{
imageWidget.Cursor = Cursors.Hand;
imageWidget.Click += (s, e) =>
{
ApplicationController.Instance.LaunchBrowser(content.link);
};
}
imageWidget.Load += (s, e) => ApplicationController.Instance.DownloadToImageAsync(image, content.image_url, false, new BlenderPreMultBGRA());
this.AddChild(imageWidget);
}
}
break;
case "article_group":
case "product_group":
this.AddChild(new ExploreSection(content, theme));
break;
}
imageWidget.Load += (s, e) => ApplicationController.Instance.DownloadToImageAsync(image, content.image_url, false, new BlenderPreMultBGRA());
this.AddChild(imageWidget);
}
}
break;
case "article_group":
case "product_group":
this.AddChild(new ExploreSection(content, theme));
break;
}
}
}
@ -162,6 +174,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab
{
public string content_type;
public List<ExplorerFeedItem> group_items;
public List<ExploreFeedContent> banner_list;
public string group_link;
public string group_subtitle;
public string group_title;

View file

@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab
if (OemSettings.Instance.ShowShopButton)
{
topToBottom.AddChild(new ExplorePanel(theme, "2lhddgi3q67xoqa53pchpeddl6w1", "BannerFeed.json"));
topToBottom.AddChild(new ExplorePanel(theme, "banners?sk=ii2gffs6e89c2cdd9er21v", "BannerFeed.json"));
}
var lastProfileID = ProfileManager.Instance.LastProfileID;
@ -90,9 +90,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab
if (OemSettings.Instance.ShowShopButton)
{
// actual feed
//topToBottom.AddChild(new ExplorePanel(theme, "2lhddgi3q67xoqa53pchpeddl6w1uf", "ExploreFeed.json"));
// broken feed so we can see what we want it to be
topToBottom.AddChild(new ExplorePanel(theme, "2lhddgi3q67xoqa53pchpeddl6w1uf_bad", "ExploreFeed.json"));
topToBottom.AddChild(new ExplorePanel(theme, "explore?sk=2lhddgi3q67xoqa53pchpeddl6w1uf", "ExploreFeed.json"));
}
}

View file

@ -1,21 +1,27 @@
{
"Content": [
{
"content_type": "headline",
"link": "https://www.matterhackers.com/explore",
"text": "Explore 3D Printing at MatterHackers"
},
{
"content_type": "banner_image",
"image_url": "https://lh3.googleusercontent.com/2yEiigWrAXQpvjBGhQllSItRTUA8s4ScTmn1dY20KO6jgxsrifoZ3L6MLy54yoAaKvleXjpdNfwKnJcK4yf210jQiJQ=w1520-h170",
"link": "https://www.matterhackers.com/store/c/mh-build-series",
"theme_filter": "light"
},
{
"content_type": "banner_image",
"image_url": "https://lh3.googleusercontent.com/2yEiigWrAXQpvjBGhQllSItRTUA8s4ScTmn1dY20KO6jgxsrifoZ3L6MLy54yoAaKvleXjpdNfwKnJcK4yf210jQiJQ=w1520-h170",
"link": "https://www.matterhackers.com/store/c/mh-build-series",
"theme_filter": "dark"
"banner_list": [
{
"content_type": "banner_image",
"image_url": "https://lh3.googleusercontent.com/2yEiigWrAXQpvjBGhQllSItRTUA8s4ScTmn1dY20KO6jgxsrifoZ3L6MLy54yoAaKvleXjpdNfwKnJcK4yf210jQiJQ=w1520-h170",
"link": "https://www.matterhackers.com/store/c/mh-build-series",
"theme_filter": "all"
},
{
"content_type": "banner_image",
"image_url": "https://lh3.googleusercontent.com/LS-CkJVjvmctT1w7MBIarRKYeyjIyBJXcyMXkcVpSbbrVhhO0m8ELo7AU8RDuIudviqZw-EAbUK5u5J8TiGXbN_GlQ=w1520-h170",
"link": "https://www.matterhackers.com/3d-printer-filament-compare",
"theme_filter": "all"
},
{
"content_type": "banner_image",
"image_url": "https://lh3.googleusercontent.com/Gax2F8Eaxfp_xrVECCmanlhVSWzQ34sUI0M7ImmUwNMWdGHZqsXw3lbF84uGv3dOnXuAtzoNTkapcxuv5RKA9Wwj5A=w1520-h170",
"link": "https://www.matterhackers.com/articles/anatomy-of-a-3d-printer",
"theme_filter": "all"
}
],
"content_type": "banner_rotate"
}
],
"Status": "success"

File diff suppressed because it is too large Load diff

@ -1 +1 @@
Subproject commit ae8eac81542e83c4bb551cda3d2262c9411b08ba
Subproject commit 06b2abad9a5ca8f10e8c772175935c5b1c1204ec