private async void EditCategoryAppButton_Click(object sender, RoutedEventArgs e) { var CurrentCategory = (Categories)CategoryBox.SelectedValue; TextBox inputTextBox = new TextBox(); inputTextBox.Text = CurrentCategory.Name; inputTextBox.AcceptsReturn = false; inputTextBox.Height = 32; ContentDialog dialog = new ContentDialog(); dialog.Content = inputTextBox; dialog.Title = "Edit Category"; dialog.IsSecondaryButtonEnabled = true; dialog.PrimaryButtonText = "Update"; dialog.SecondaryButtonText = "Cancel"; if (await dialog.ShowAsync() == ContentDialogResult.Primary) { if (inputTextBox.Text.Trim() != "") { CurrentCategory.Name = inputTextBox.Text.Trim(); GifologyDatabase.InsertUpdateCategory(CurrentCategory); LoadCategoryList(0); } } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); GifologyDatabase.CreateDatabase(); GifologyDatabase.CreateSettingsDatabase(); GifologyDatabase.GetSettings(); }
private async void LoadCategoryList(int SelectedIndex) { Categories = await GifologyDatabase.GetCategories(); CategoryBox.ItemsSource = Categories; CategoryBox.SelectedIndex = SelectedIndex; }
/* * Downloads file for sharing * Displays Share UI */ public static async void ShareImage(object sender, RoutedEventArgs e, Image img) { string fileName = img.Name + ".gif"; if (await ApplicationData.Current.TemporaryFolder.TryGetItemAsync(fileName) == null) { var httpClient = new HttpClient(); var OriginalUrl = ((BitmapImage)img.Source).UriSource.OriginalString; var RequestUri = Uri.IsWellFormedUriString(GiphyImage.ConvertSourceType(OriginalUrl, SettingsItem.GifQuality), UriKind.Absolute) ? new Uri(GiphyImage.ConvertSourceType(OriginalUrl, SettingsItem.GifQuality)) : new Uri(GiphyImage.ConvertSourceType(OriginalUrl, "High")); HttpResponseMessage message = await httpClient.GetAsync(RequestUri); StorageFolder myfolder = ApplicationData.Current.TemporaryFolder; StorageFile SampleFile = await myfolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); byte[] file = await message.Content.ReadAsByteArrayAsync(); await FileIO.WriteBytesAsync(SampleFile, file); var files = await myfolder.GetFilesAsync(); } Global.shareFileName = fileName; DataTransferManager.ShowShareUI(); //Add to Recents database var data = new Recents(); data.Giphy_Id = img.Name; data.Url = ((BitmapImage)img.Source).UriSource.OriginalString; GifologyDatabase.InsertUpdateRecent(data); }
private async void DeleteCategoryAppButton_Click(object sender, RoutedEventArgs e) { var CurrentCategory = (Categories)CategoryBox.SelectedValue; NotificationControl SuccessNotification; DeleteCategoryDialog dialog = new DeleteCategoryDialog(); await dialog.ShowAsync(); switch (dialog.Result) { case Results.Delete: //Remove all favorites in category GifologyDatabase.DeleteImageInCategory(CurrentCategory); GifologyDatabase.DeleteCategories(CurrentCategory); SuccessNotification = Notifications.CreateNotification("SuccessNotification", "Category Deleted", "Success", false); SuccessNotification.ShowHideNotification(true); break; case Results.Keep: //Don't delete favorites GifologyDatabase.MoveImageToUncategorized(CurrentCategory); GifologyDatabase.DeleteCategories(CurrentCategory); SuccessNotification = Notifications.CreateNotification("SuccessNotification", "Category Deleted", "Success", false); SuccessNotification.ShowHideNotification(true); break; case Results.Cancel: return; default: break; } LoadCategoryList(0); }
private async void CategoryAppButton_Click(object sender, RoutedEventArgs e) { var img = GetSelectedImage(); if (img != null) { CategoryList.Clear(); var giphy_id = img.Name; var SelectedCategories = await GifologyDatabase.GetImageCategory(giphy_id); var AllCategories = await GifologyDatabase.GetCategoryList(); for (int i = 0; i < AllCategories.Count; i++) { CategoryList.Add(new CategoryListItem { Id = (int)AllCategories[i].Id, Name = AllCategories[i].Name, IsChecked = SelectedCategories.IndexOf((int)AllCategories[i].Id) != -1 }); } CategoryListControl.SelectedCategories = SelectedCategories; CategoryListControl.SelectedImage = img; CategoryListControl.CategoryList = CategoryList; CategoryListControl.Visibility = Visibility.Visible; } }
private void UnfavoriteAppButton_Click(object sender, RoutedEventArgs e) { this.ProgressRing.Visibility = Visibility.Visible; var img = GetSelectedImage(); if (img != null) { try { var item = GifologyDatabase.GetFavorite(img.Name); GiphyImage.UnfavoriteImage(sender, e, item); var SuccessNotification = Notifications.CreateNotification("SuccessNotification", "Image Unfavorited", "Success", false); SuccessNotification.ShowHideNotification(true); FavoriteAppButton.Visibility = Visibility.Visible; UnfavoriteAppButton.Visibility = Visibility.Collapsed; } catch (SQLite.SQLiteException ex) { Debug.WriteLine("DB EXCEPTION: " + ex.Message); } } this.ProgressRing.Visibility = Visibility.Collapsed; }
private async void AddCategoryButton_Click(object sender, RoutedEventArgs e) { TextBox inputTextBox = new TextBox(); inputTextBox.AcceptsReturn = false; inputTextBox.Height = 32; ContentDialog dialog = new ContentDialog(); dialog.Content = inputTextBox; dialog.Title = "Add Category"; dialog.IsSecondaryButtonEnabled = true; dialog.PrimaryButtonText = "Add"; dialog.SecondaryButtonText = "Cancel"; if (await dialog.ShowAsync() == ContentDialogResult.Primary) { if (inputTextBox.Text.Trim() != "") { GifologyDatabase.InsertUpdateCategory(new Categories { Name = inputTextBox.Text.Trim() }); ReloadCategories(); if (LoadCategoryList != null) { LoadCategoryList(); } } } }
/* * Event handler to add image to favorites */ public static void FavoriteImage(object sender, RoutedEventArgs e, Image img) { var data = new Favorites(); data.Giphy_Id = img.Name; data.Url = ConvertSourceType(((BitmapImage)img.Source).UriSource.OriginalString, "original"); GifologyDatabase.InsertUpdateFavorite(data); }
/* * Create flyout menu options for specific image */ public static MenuFlyout GenerateFlyout(Image img) { MenuFlyout flyout = new MenuFlyout(); MenuFlyoutItem share = new MenuFlyoutItem { Text = "Share" }; MenuFlyoutItem copyUrl = new MenuFlyoutItem { Text = "Copy URL" }; flyout.Items.Add(share); flyout.Items.Add(copyUrl); share.Tapped += (sender, e) => { ShareImage(sender, e, img); }; copyUrl.Tapped += (sender, e) => { CopyImageUrl(sender, e, img); }; flyout.Items.Add(new MenuFlyoutSeparator()); /* * Check if image is already favorited, if so "Unfavorite", else favorite */ try { using (var conn = new SQLiteConnection(Global.databaseFile)) { var item = GifologyDatabase.GetFavorite(img.Name); if (item != null) { MenuFlyoutItem unfavorite = new MenuFlyoutItem { Text = "Remove from Favorites" }; flyout.Items.Add(unfavorite); unfavorite.Tapped += (sender, e) => { UnfavoriteImage(sender, e, item); }; } else { MenuFlyoutItem favorite = new MenuFlyoutItem { Text = "Add to Favorites" }; flyout.Items.Add(favorite); favorite.Tapped += (sender, e) => { FavoriteImage(sender, e, img); }; } } } catch (SQLiteException e) { Debug.WriteLine("DB EXCEPTION: " + e.Message); } return(flyout); }
/* * Event handler to copy image URL to clipboard */ public static void CopyImageUrl(object sender, RoutedEventArgs e, Image img) { DataPackage dataPackage = new DataPackage(); var url = ConvertSourceType(((BitmapImage)img.Source).UriSource.OriginalString, "original"); dataPackage.RequestedOperation = DataPackageOperation.Copy; dataPackage.SetText(url); Clipboard.SetContent(dataPackage); Clipboard.Flush(); //Add to Recents database var data = new Recents(); data.Giphy_Id = img.Name; data.Url = url; GifologyDatabase.InsertUpdateRecent(data); }
private async void ReloadCategories() { var List = await GifologyDatabase.GetCategoryList(); var NewList = new ObservableCollection <CategoryListItem>(); for (int i = 0; i < List.Count; i++) { NewList.Add(new CategoryListItem { Id = (int)List[i].Id, Name = List[i].Name, IsChecked = SelectedCategories.IndexOf((int)List[i].Id) != -1 }); } CategoryList = NewList; }
private void SaveCategoryButton_Click(object sender, RoutedEventArgs e) { try { if (SelectedCategories.Count == 0) { if (GifologyDatabase.GetFavorite(SelectedImage.Name) != null) { GifologyDatabase.DeleteFavoriteId(SelectedImage.Name); Favorites data = new Favorites { Giphy_Id = SelectedImage.Name, Url = GiphyImage.ConvertSourceType(((BitmapImage)SelectedImage.Source).UriSource.OriginalString, "original"), Category = 1 }; GifologyDatabase.InsertUpdateFavorite(data); } } else { GifologyDatabase.DeleteFavoriteId(SelectedImage.Name); for (int i = 0; i < SelectedCategories.Count; i++) { Favorites data = new Favorites { Giphy_Id = SelectedImage.Name, Url = GiphyImage.ConvertSourceType(((BitmapImage)SelectedImage.Source).UriSource.OriginalString, "original"), Category = SelectedCategories[i] }; GifologyDatabase.InsertUpdateFavorite(data); } } } catch (SQLite.SQLiteException ex) { SelectedCategories.Clear(); Debug.WriteLine("DB EXCEPTION: " + ex.Message); } _this.Visibility = Visibility.Collapsed; }
private void ShowSingleImageIcons() { var img = GetSelectedImage(); if (img == null) { return; } if (GifologyDatabase.GetFavorite(img.Name) != null) { UnfavoriteAppButton.Visibility = Visibility.Visible; FavoriteAppButton.Visibility = Visibility.Collapsed; } else { UnfavoriteAppButton.Visibility = Visibility.Collapsed; FavoriteAppButton.Visibility = Visibility.Visible; } IsImageSelected = true; }
/* ================================== * START RECENT FUNCTIONS * ================================== */ private async void GetRecents() { MyGifs.PreviousOffset = MyGifs.Offset; var list = await GifologyDatabase.GetRecents(MyGifs.Offset); MyGifs.Offset += Global.limit; this.NextAppButton.IsEnabled = MyGifs.NextEnabled = list.Count > Global.limit; if (SettingsItem.InfiniteScroll == 0) { MyGifs.ColumnOneList.Clear(); MyGifs.ColumnTwoList.Clear(); } for (int i = 0; i < list.Count; i++) { if (i % 2 == 0) { MyGifs.ColumnOneList.Add(new GiphyImage { Name = list[i].Giphy_Id, Url = GetListUri(list[i].Url) }); } else { MyGifs.ColumnTwoList.Add(new GiphyImage { Name = list[i].Giphy_Id, Url = GetListUri(list[i].Url) }); } } this.PreviousAppButton.IsEnabled = MyGifs.Offset - Global.limit > 0; }
/* * Event handler to remove image from favorites` */ public static void UnfavoriteImage(object sender, RoutedEventArgs e, Gifology.Database.Favorites favorite) { GifologyDatabase.DeleteFavorite(favorite); }
private async void Pivot_NavSelectionChanged(object sender, SelectionChangedEventArgs e) { EditCategoryAppButton.Visibility = Visibility.Collapsed; DeleteCategoryAppButton.Visibility = Visibility.Collapsed; if (!InternetStatus()) { return; } switch (NavDictionary[PivotNavigation.SelectedIndex]) { case "Search": this.PreviousAppButton.IsEnabled = Search.PreviousEnabled; this.NextAppButton.IsEnabled = Search.NextEnabled; break; case "Trending": if (Trending.ColumnOneList.Count == 0 && Trending.ColumnTwoList.Count == 0) { GetTrending(); } this.PreviousAppButton.IsEnabled = Trending.PreviousEnabled; this.NextAppButton.IsEnabled = Trending.NextEnabled; break; case "MyGifs": Categories = await GifologyDatabase.GetCategories(); CategoryBox.ItemsSource = Categories; if (ViewBox.SelectedValue == null) { ViewBox.SelectedValue = "Favorite"; } else if (((ComboBoxItem)ViewBox.SelectedItem).Tag.ToString() == "Favorite") { MyGifs.Offset = MyGifs.PreviousOffset; GetFavorites(); } else if (((ComboBoxItem)ViewBox.SelectedItem).Tag.ToString() == "Recent") { MyGifs.Offset = MyGifs.PreviousOffset; GetRecents(); } else if (((ComboBoxItem)ViewBox.SelectedItem).Tag.ToString() == "Category") { CategoryBox.SelectedIndex = 0; if (((Categories)CategoryBox.SelectedValue).Id != 1) { EditCategoryAppButton.Visibility = Visibility.Visible; DeleteCategoryAppButton.Visibility = Visibility.Visible; } } this.PreviousAppButton.IsEnabled = MyGifs.PreviousEnabled; this.NextAppButton.IsEnabled = MyGifs.NextEnabled; break; } if (GetSelectedImage() == null) { ShowFullListIcons(); } else { ShowSingleImageIcons(); } }