public async void DownloadImage(string url, string suggestedFilename, bool animeCover)
        {
            if (url == null)
            {
                return;
            }
            try
            {
                var sp = new FileSavePicker();
                sp.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                sp.FileTypeChoices.Add("Portable Network Graphics (*.png)", new List <string> {
                    ".png"
                });
                sp.SuggestedFileName = $"{suggestedFilename}-cover_art";

                var file = await sp.PickSaveFileAsync();

                if (file == null)
                {
                    return;
                }
                await Download(url, file, animeCover);

                UWPUtilities.GiveStatusBarFeedback("File saved successfully.");
            }
            catch (Exception)
            {
                UWPUtilities.GiveStatusBarFeedback("Error. File didn't save properly.");
            }
        }
示例#2
0
        private async void CropImage(bool wide = false)
        {
            IsCropEnabled = false;
            try
            {
                var             img           = wide ? _previewImageWide : _previewImageNormal;
                WriteableBitmap resizedBitmap = new WriteableBitmap(CropWidth, CropHeight);
                //if (img.UriSource == null)
                //await resizedBitmap.LoadAsync(_originaPickedStorageFile);
                /*else*/
                if (!img.UriSource.ToString().Contains("ms-appdata"))
                {
                    var imgFile = await SaveImage(img, wide);

                    await resizedBitmap.LoadAsync(imgFile);
                }
                else
                {
                    await resizedBitmap.LoadAsync(await StorageFile.GetFileFromApplicationUriAsync(img.UriSource));
                }

                if (wide)
                {
                    resizedBitmap = resizedBitmap.Crop(CropLeftWide, CropTopWide, CropWidthWide + CropLeftWide, CropTopWide + CropHeightWide);
                }
                else
                {
                    resizedBitmap = resizedBitmap.Crop(CropLeft, CropTop, CropWidth + CropLeft, CropTop + CropHeight);
                }

                var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync($"_cropTemp{(wide ? "Wide" : "")}.png", CreationCollisionOption.GenerateUniqueName);

                if (wide)
                {
                    _lastCroppedFileNameWide = file.Name;
                }
                else
                {
                    _lastCroppedFileName = file.Name;
                }

                await resizedBitmap.SaveAsync(file, BitmapEncoder.PngEncoderId);

                if (wide)
                {
                    PreviewImageWide = new BitmapImage(new Uri($"ms-appdata:///temp/{file.Name}"));
                }
                else
                {
                    PreviewImageNormal = new BitmapImage(new Uri($"ms-appdata:///temp/{file.Name}"));
                    UndoCropVisibility = Visibility.Visible;
                }
            }
            catch (Exception)
            {
                UWPUtilities.GiveStatusBarFeedback("An error occured...");
            }
            IsCropEnabled = true;
        }
示例#3
0
        public void SetText(string text)
        {
            var dp = new DataPackage();

            dp.SetText(text);
            Clipboard.SetContent(dp);
            UWPUtilities.GiveStatusBarFeedback("Copied to clipboard...");
        }
        private void CopyLinkToClipboardCommand(object sender, RoutedEventArgs e)
        {
            FlyoutMore.Hide();
            var dp = new DataPackage();

            dp.SetText($"http://www.myanimelist.net/{(ViewModel.AnimeMode ? "anime" : "manga")}/{ViewModel.Id}");
            Clipboard.SetContent(dp);
            UWPUtilities.GiveStatusBarFeedback("Copied to clipboard...");
        }
示例#5
0
 private async void LaunchUri(string url)
 {
     try
     {
         ResourceLocator.SystemControlsLauncherService.LaunchUri(new Uri(url));
     }
     catch (Exception)
     {
         //wrong url provided
         UWPUtilities.GiveStatusBarFeedback("Invalid target url...");
     }
 }
        public async void DownloadImageDefault(string url, string suggestedFilename, bool animeCover)
        {
            try
            {
                var lib = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);

                var folder = await lib.SaveFolder.CreateFolderAsync("MALCLient Images", CreationCollisionOption.OpenIfExists);

                var file = await folder.CreateFileAsync(UWPUtilities.SanitizeFileName(suggestedFilename) + ".png");
                await Download(url, file, animeCover);

                UWPUtilities.GiveStatusBarFeedback("File saved successfully.");
            }
            catch (Exception)
            {
                UWPUtilities.GiveStatusBarFeedback("Error. File didn't save properly.");
            }
        }
示例#7
0
        private async Task <StorageFile> SaveImage(BitmapImage img, bool wide)
        {
            try
            {
                var uri = img.UriSource;

                var    http     = new HttpClient();
                byte[] response = { };
                var    file     = await ApplicationData.Current.TemporaryFolder.CreateFileAsync($"_cropTemp{(wide ? "Wide" : "")}.png", CreationCollisionOption.GenerateUniqueName);

                //get bytes
                await Task.Run(async() => response = await http.GetByteArrayAsync(uri));


                var fs = await file.OpenStreamForWriteAsync(); //get stream

                var writer = new DataWriter(fs.AsOutputStream());

                writer.WriteBytes(response); //write
                await writer.StoreAsync();

                await writer.FlushAsync();

                writer.Dispose();
                return(file);
            }
            catch (Exception)
            {
                UWPUtilities.GiveStatusBarFeedback("An error occured...");
                return(null);
            }


            //var bmp = new WriteableBitmap(img.PixelWidth, img.PixelHeight);
            //bmp = await bmp.LoadFromBitmapImageSourceAsync(img);

            //await bmp.SaveAsync(file, BitmapEncoder.PngEncoderId);
            //return file;
        }
示例#8
0
        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;
        }