public async Task CreateSecondaryTileForSubreddit(TypedThing<Subreddit> subreddit)
{
try
{
string id = "";
if (subreddit != null)
id = subreddit.Data.DisplayName;
SecondaryTile tile = new SecondaryTile();
tile.TileOptions = TileOptions.ShowNameOnWideLogo | TileOptions.ShowNameOnLogo;
tile.DisplayName = "Baconography";
tile.ShortName = "/r/" + id;
if (subreddit != null)
{
// Download and create a local copy of the header image
var rawImage = await _imagesService.SaveFileFromUriAsync(new Uri(subreddit.Data.HeaderImage), subreddit.Data.DisplayName + ".jpg", "Images");
// Generate a wide tile appropriate image
var wideImage = await _imagesService.GenerateResizedImage(rawImage, 310, 150) as StorageFile;
// Generate a square tile appropriate image
var squareImage = await _imagesService.GenerateResizedImage(rawImage, 150, 150) as StorageFile;
tile.WideLogo = new Uri("ms-appdata:///local/Images/" + wideImage.Name);
tile.Logo = new Uri("ms-appdata:///local/Images/" + squareImage.Name);
subreddit.Data.PublicDescription = null;
subreddit.Data.Description = null;
subreddit.Data.Headertitle = null;
tile.Arguments = JsonConvert.SerializeObject(subreddit);
}
else
{
Uri logo = new Uri("ms-appx:///Assets/Logo.png");
Uri wideLogo = new Uri("ms-appx:///Assets/WideLogo.png");
tile.Arguments = "/r/";
tile.Logo = logo;
tile.WideLogo = wideLogo;
}
tile.TileId = "r" + id;
// Ask the user to authorize creation of the tile
bool isPinned = await tile.RequestCreateAsync();
}
catch (Exception)
{
// TODO: Do something with exceptions
}
}