public static async Task PinTile(IAnimeData entry, Uri imgUri, Uri wideImgUri, PinTileSettings settings, PinTileActionSetting action) { try { //prepare images if (imgUri != null) { var file = await StorageFile.GetFileFromApplicationUriAsync(imgUri); var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("PinnedTilesImages", CreationCollisionOption.OpenIfExists); await file.CopyAsync(folder, entry.Id + ".png", NameCollisionOption.ReplaceExisting); if (!imgUri.Equals(wideImgUri)) { file = await StorageFile.GetFileFromApplicationUriAsync(wideImgUri); await file.CopyAsync(folder, entry.Id + "Wide.png", NameCollisionOption.ReplaceExisting); wideImgUri = new Uri($"ms-appdata:///local/PinnedTilesImages/{entry.Id}Wide.png"); } else wideImgUri = new Uri($"ms-appdata:///local/PinnedTilesImages/{entry.Id}.png"); imgUri = new Uri($"ms-appdata:///local/PinnedTilesImages/{entry.Id}.png"); } else { imgUri = new Uri("ms-appx:///Assets/Square150x150Logo.scale-200.png"); wideImgUri = new Uri("ms-appx:///Assets/Wide310x150Logo.scale-200.png"); } //pin tile if (action.Action == TileActions.OpenUrl) if (!action.Param.Contains("http")) action.Param = "http://" + action.Param; var tile = new SecondaryTile(entry.Id.ToString(), "MALClient", string.Join(";", action.Action.ToString(), action.Param), imgUri, TileSize.Square150x150); tile.WideLogo = wideImgUri; RegisterTile(entry.Id.ToString()); await tile.RequestCreateAsync(); RegisterTileCache(entry.Id, new PinnedTileCache { ImgUri = imgUri, WideImgUri = wideImgUri, Settings = settings }); if (settings.AnythingAtAll) UpdateTile(entry, imgUri, wideImgUri, settings); ResourceLocator.TelemetryProvider.TelemetryTrackEvent(TelemetryTrackedEvents.PinnedTile); } catch (Exception) { //who knows? } }
private async void PinThing() { IsPinEnabled = false; try { if (SelectedImageOptionIndex == 0) { //if we didn't crop if (string.IsNullOrEmpty(_lastCroppedFileName)) { var file = await SaveImage(PreviewImageNormal, false); _lastCroppedFileName = file.Name; //if we din't crop wide either if (string.IsNullOrEmpty(_lastCroppedFileNameWide)) _lastCroppedFileNameWide = file.Name; //set source to this } //if we didn't crop wide... you get the idea if (string.IsNullOrEmpty(_lastCroppedFileNameWide)) { //we may have not even opened wide pivot image -> no img loaded -> no width -> assume normal picture if (PreviewImageWide.PixelWidth == 0) _lastCroppedFileNameWide = _lastCroppedFileName; else { var file = await SaveImage(PreviewImageWide, true); _lastCroppedFileNameWide = file.Name; if (string.IsNullOrEmpty(_lastCroppedFileName)) _lastCroppedFileName = file.Name; } } } var action = new PinTileActionSetting(); switch (SelectedActionIndex) { case 0: action.Action = TileActions.OpenUrl; action.Param = TargetUrl ?? ""; break; case 1: action.Action = TileActions.OpenUrl; action.Param = Settings.SelectedApiType == ApiType.Mal ? $"https://myanimelist.net/{(EntryData.ParentAbstraction.RepresentsAnime ? "anime" : "manga")}/{EntryData.Id}" : $"https://hummingbird.me/{(EntryData.ParentAbstraction.RepresentsAnime ? "anime" : "manga")}/{EntryData.Id}"; break; default: action.Action = TileActions.OpenDetails; action.Param = $"https://myanimelist.net/{(EntryData.ParentAbstraction.RepresentsAnime ? "anime" : "manga")}/{EntryData.Id}/{EntryData.Title}"; break; } await LiveTilesManager.PinTile(EntryData, (SelectedImageOptionIndex == 0 ? new Uri($"ms-appdata:///temp/{_lastCroppedFileName}") : null), (SelectedImageOptionIndex == 0 ? new Uri($"ms-appdata:///temp/{_lastCroppedFileNameWide}") : null), PinSettings, action); GeneralVisibility = Visibility.Collapsed; } catch (Exception) { UWPUtilities.GiveStatusBarFeedback("An error occured..."); } IsPinEnabled = true; }