//Set the feed icon private async void btn_SetIcon_Clicked(object sender, EventArgs e) { try { Feeds SelectedItem = (Feeds)listview_Items.SelectedItem; if (SelectedItem != null) { List <string> messageAnswers = new List <string>(); messageAnswers.Add("Set custom icon"); messageAnswers.Add("Reset the icon"); messageAnswers.Add("Cancel"); string messageResult = await MessagePopup.Popup("Change the feed icon", "Would you like to set a custom feed icon for " + SelectedItem.feed_title + "?", messageAnswers); if (messageResult == "Set custom icon") { Debug.WriteLine("Changing icon for feed: " + SelectedItem.feed_id + " / " + SelectedItem.feed_title); PickOptions pickOptions = new PickOptions(); pickOptions.FileTypes = FilePickerFileType.Png; FileResult pickResult = await FilePicker.PickAsync(pickOptions); if (pickResult != null) { //Load feed icon Stream imageStream = await pickResult.OpenReadAsync(); //Update feed icon if (imageStream.CanSeek) { imageStream.Position = 0; } SelectedItem.feed_icon = ImageSource.FromStream(() => imageStream); //Save feed icon AVFiles.File_SaveStream(SelectedItem.feed_id + ".png", imageStream, true, true); } } else if (messageResult == "Reset the icon") { //Delete the feed icon AVFiles.File_Delete(SelectedItem.feed_id + ".png", true); //Load default feed icon SelectedItem.feed_icon = ImageSource.FromResource("NewsScroll.Assets.iconRSS-Dark.png"); //Reset the online status OnlineUpdateFeeds = true; ApiMessageError = string.Empty; List <string> messageAnswersReset = new List <string>(); messageAnswersReset.Add("Ok"); await MessagePopup.Popup("Feed icon reset", "The feed icon has been reset and will be refreshed on the next online feed update, you can refresh the feeds by clicking on the refresh icon above.", messageAnswersReset); } } } catch { } }
//Save the image private async void button_iconSave_Tap(object sender, EventArgs e) { try { string fileName = Path.GetFileName(vImageLink); string localFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); string filePath = Path.Combine(localFolder, fileName); //Download image Uri imageUri = new Uri(vImageLink); Stream imageStream = await dependencyAVImages.DownloadResizeImage(imageUri, 999999, 999999); //Save image AVFiles.File_SaveStream(filePath, imageStream, true, false); } catch { List <string> messageAnswers = new List <string>(); messageAnswers.Add("Ok"); await MessagePopup.Popup("Failed to save", "Failed to save the image, please check your internet connection and try again.", messageAnswers); Debug.WriteLine("Failed to save the image."); } }