private async void DeleteItem_Click(object sender, RoutedEventArgs e) { ResourceLoader rl = new ResourceLoader(); var dialog = new MessageDialog(rl.GetString("DeleteCategory")); dialog.Title = rl.GetString("DeleteElement"); dialog.Commands.Add(new UICommand { Label = rl.GetString("Delete"), Id = 0 }); dialog.Commands.Add(new UICommand { Label = rl.GetString("Cancel"), Id = 1 }); var res = await dialog.ShowAsync(); if ((int)res.Id == 0) { Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); foreach (Category c in cats.categories) { if (c.title != cat.title) { continue; } cats.categories.Remove(c); break; } SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); ExpandItems(MainBorder.Height, 0); } }
private async void RenameCategory(CategoryDialog dialog) { Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); foreach (Category c in cats.categories) { if (c.title == dialog.CategoryName) { await(new MessageDialog((new ResourceLoader()).GetString("CategoryExists")).ShowAsync()); return; } } foreach (Category c in cats.categories) { if (c.title != cat.title) { continue; } c.title = dialog.CategoryName; cat.title = dialog.CategoryName; CategoryTitle.Content = dialog.CategoryName; break; } SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); }
private async void AddNewCategory(CategoryDialog dialog) { Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); Category cat = new Category(); cat.title = dialog.CategoryName; cat.websites = new List <Website>(); foreach (Category c in cats.categories) { if (c.title == dialog.CategoryName) { await(new MessageDialog((new ResourceLoader()).GetString("CategoryExists")).ShowAsync()); return; } } cats.categories.Add(cat); SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); Frame frame = new Frame(); frame.Navigate(typeof(SourcesView), cat); SourcesList.Items.Add(frame); }
private async void Delete_Button_Click(object sender, RoutedEventArgs e) { ListFeed p = (ListFeed)((FrameworkElement)sender).DataContext; string link = p.feedid; ResourceLoader rl = new ResourceLoader(); var dialog = new MessageDialog(rl.GetString("DeleteAction")); dialog.Title = rl.GetString("DeleteElement"); dialog.Commands.Add(new UICommand { Label = rl.GetString("Delete"), Id = 0 }); dialog.Commands.Add(new UICommand { Label = rl.GetString("Cancel"), Id = 1 }); var res = await dialog.ShowAsync(); if ((int)res.Id == 0) { Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); foreach (Website wb in cat.websites) { if (wb.url != link) { continue; } cat.websites.Remove(wb); break; } foreach (Category c in cats.categories) { if (c.title != cat.title) { continue; } foreach (Website wb in c.websites) { if (wb.url != link) { continue; } c.websites.Remove(wb); break; } break; } SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); Display.Items.Remove(p); CountInCategory.Content = cat.websites.Count; ExpandItems(MainBorder.Height, MainBorder.Height - 66); } }
private async void AddButton_Click(object sender, RoutedEventArgs e) { LoadStatus.IsIndeterminate = true; LoadStatus.Opacity = 1; ResourceLoader rl = new ResourceLoader(); string link = RssLink.Text; Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); if (!Regex.IsMatch(link, @"^http(s)?://*")) { var dialog = new MessageDialog(rl.GetString("LinkNotValid")); dialog.Title = rl.GetString("Error"); dialog.Commands.Add(new UICommand { Label = rl.GetString("Ok"), Id = 0 }); var res = await dialog.ShowAsync(); LoadStatus.IsIndeterminate = false; LoadStatus.Opacity = 0; return; } Website wb = new Website(); wb.url = link; cat.websites.Add(wb); foreach (Category c in cats.categories) { if (c.title != cat.title) { continue; } c.websites.Add(wb); break; } SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); ExpandItems(MainBorder.Height, MainBorder.Height + 66); CountInCategory.Content = cat.websites.Count; Display.Items.Add(await GetItem(new SyndicationClient(), link)); LoadStatus.IsIndeterminate = false; LoadStatus.Opacity = 0; }
private async void FavButton_Click(object sender, RoutedEventArgs e) { FavBtn.IsEnabled = false; StorageFile cache = await ApplicationData.Current.LocalFolder.GetFileAsync("saved_cache"); StorageFolder favoritesFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("favorites"); int filecount = (await favoritesFolder.GetFilesAsync()).Count; string favcache = await FileIO.ReadTextAsync(cache); if (!favcache.Contains(Value.link)) { StorageFolder storageFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("favorites"); SerializerExtensions.SerializeObject(Value, await storageFolder.CreateFileAsync(filecount.ToString())); await FileIO.AppendTextAsync(cache, Value.link + ";"); } }
private async void AddToFavs_Click(object sender, RoutedEventArgs e) { PFeedItem item = (PFeedItem)((MenuFlyoutItem)sender).DataContext; StorageFile cache = await ApplicationData.Current.LocalFolder.GetFileAsync("saved_cache"); string favcache = await FileIO.ReadTextAsync(cache); if (!favcache.Contains(item.link)) { StorageFolder favoritesFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("favorites"); int filecount = (await favoritesFolder.GetFilesAsync()).Count; StorageFolder storageFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("favorites"); SerializerExtensions.SerializeObject(item, await storageFolder.CreateFileAsync(filecount.ToString())); await FileIO.AppendTextAsync(cache, item.link + ";"); } }
private async Task LoadContent() { Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); if (cats != null) { await Task.Delay(200); foreach (Category cat in cats.categories) { await Task.Delay(100); Frame frame = new Frame(); frame.Navigate(typeof(SourcesView), cat); SourcesList.Items.Add(frame); } } CategoryAdd.Visibility = Visibility.Visible; }
/// <summary> /// Загружает файл настроек приложения и устанавливает тему оформления в зависимости от содержимого. /// </summary> private async void LoadConfig() { try { try { StorageFile configfile = await ApplicationData.Current.LocalFolder.GetFileAsync("config"); App.config = await SerializerExtensions.DeSerializeObject <App.ConfigFile>(configfile); } catch { StorageFile configfile = await ApplicationData.Current.LocalFolder.CreateFileAsync("config"); SerializerExtensions.SerializeObject(App.config, configfile); } } catch { } }
private async Task Go(ItemsControl list, object NavUri) { await Task.Delay(300); StorageFolder favorites = await(ApplicationData.Current.LocalFolder.GetFolderAsync("favorites")); IReadOnlyList <StorageFile> files = await favorites.GetFilesAsync(); if (files.Count == 0) { Welcome.Visibility = Visibility.Visible; } foreach (StorageFile file in files) { itemlist.Add(await SerializerExtensions.DeSerializeObject <PFeedItem>(file)); } await Task.Delay(TimeSpan.FromMilliseconds(5)); if (NavUri != null) { foreach (PFeedItem item in itemlist) { CompareAddTimeRead(item, list, false); if (item.link == NavUri.ToString()) { ArticleFrame.Navigate(typeof(PArticle), item); } } } else { foreach (PFeedItem item in itemlist) { CompareAddTimeRead(item, list, false); } } }
private async void ToggleNotifications_Click(object sender, RoutedEventArgs e) { Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); foreach (Category c in cats.categories) { if (c.title != cat.title) { continue; } foreach (Website website in c.websites) { if (website.url == website_buffer) { website.notify = !website.notify; } } cat = c; } SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); }
private async void Save() { SerializerExtensions.SerializeObject(App.config, await ApplicationData.Current.LocalFolder.GetFileAsync("config")); }
private async void AddButton_Click(object sender, RoutedEventArgs e) { ListFeed feed = (ListFeed)((FrameworkElement)sender).DataContext; ResourceLoader rl = new ResourceLoader(); bool isEmpty = false; SearchAddDialog addsource = new SearchAddDialog(); Categories cats = new Categories(); ComboBox box = new ComboBox(); addsource.Loaded += async(s, a) => { cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); box = addsource.CategoriesComboBox; foreach (Category cat in cats.categories) { box.Items.Add(cat.title); } if (box.Items.Count < 1) { addsource.CategoriesTextBlock.Visibility = Visibility.Collapsed; addsource.CategoriesComboBox.Visibility = Visibility.Collapsed; addsource.Title = rl.GetString("SearchCreateNewCatTitleFL"); addsource.CategoriesTextBlockBox.Text = rl.GetString("SearchCreateNewCatTextFL"); isEmpty = true; return; } box.SelectedIndex = 0; }; if (await addsource.ShowAsync() == ContentDialogResult.Primary) { string name = addsource.CategoriesText.Text; if (string.IsNullOrWhiteSpace(name) && isEmpty) { return; } if (!string.IsNullOrWhiteSpace(name)) { foreach (Category c in cats.categories) { if (c.title == name) { await(new MessageDialog((new ResourceLoader()).GetString("CategoryExists")).ShowAsync()); return; } } Category newcat = new Category() { title = name, websites = new List <Website>() { new Website() { notify = true, url = feed.feedid } } }; cats.categories.Add(newcat); SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); addsource.Hide(); await(new MessageDialog(string.Format(rl.GetString("SearchAddMessage"), feed.feedtitle, name), rl.GetString("SearchAddSuccess"))).ShowAsync(); return; } name = (string)box.SelectedItem; foreach (Category cat in cats.categories) { if (cat.title != name) { continue; } Website wb = new Website(); wb.url = feed.feedid; cat.websites.Add(wb); break; } SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); addsource.Hide(); await(new MessageDialog(string.Format(rl.GetString("SearchAddMessage"), feed.feedtitle, name), rl.GetString("SearchAddSuccess"))).ShowAsync(); } }
/// <summary> /// Страшный и дикий кусок кода, конвертирующий данные из старого странного формата хранения /// данных в новый. Также проверяет, существуют ли нужные файлы. Если нет - делает новые. /// </summary> private async void CheckFiles() { StorageFolder storageFolder = ApplicationData.Current.LocalFolder; try { string temp_ = await MigrateData("loadimg.txt"); if (temp_ != string.Empty) { App.config.DownloadImages = bool.Parse(temp_); } temp_ = await MigrateData("checktime"); if (temp_ != string.Empty) { App.config.CheckTime = uint.Parse(temp_); } temp_ = await MigrateData("settings.txt"); if (temp_ != string.Empty) { App.config.FontSize = int.Parse(temp_); } StorageFile configfile = await storageFolder.CreateFileAsync("config"); SerializerExtensions.SerializeObject(App.config, configfile); } catch { } try { await storageFolder.GetFileAsync("sites"); } catch { await storageFolder.CreateFileAsync("sites"); Categories cats = new Categories(); cats.categories = new List <Category>(); SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); } /// Here we do some stupid stuff in order to migrade /// from old strange data storing format. string temp = await MigrateData("sources"); if (temp != string.Empty) { try { Categories cats = new Categories(); cats.categories = new List <Category>(); List <string> sourceslist = temp.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList(); if (sourceslist.Count > 0) { sourceslist.Remove(sourceslist.Last()); } foreach (string str in sourceslist) { Category cat = new Category(); List <string> slist = str.Split(';').ToList(); if (slist.Count > 0) { slist.RemoveAt(slist.Count - 1); } if (slist.Count > 0) { cat.title = slist.First(); } if (slist.Count > 0) { slist.Remove(slist.First()); } cat.websites = new List <Website>(); foreach (string s in slist) { Website wb = new Website(); wb.url = s; cat.websites.Add(wb); } cats.categories.Add(cat); } SerializerExtensions.SerializeObject(cats, await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); } catch { } } try { await storageFolder.GetFileAsync("datecutoff"); } catch { await storageFolder.CreateFileAsync("datecutoff"); } try { await storageFolder.GetFolderAsync("favorites"); } catch { await storageFolder.CreateFolderAsync("favorites"); } try { await storageFolder.GetFileAsync("saved_cache"); } catch { await storageFolder.CreateFileAsync("saved_cache"); } try { /// Here we delete info about old articles. App.Read = await FileIO.ReadTextAsync(await storageFolder.GetFileAsync("read.txt")); List <string> read_list = App.Read.Split(';').ToList(); read_list.RemoveAt(read_list.Count - 1); if (read_list.Count > 90) { read_list = read_list.Skip(Math.Max(0, read_list.Count() - 90)).ToList(); } App.Read = string.Empty; foreach (string item in read_list) { App.Read = App.Read + item + ';'; } await FileIO.WriteTextAsync(await storageFolder.GetFileAsync("read.txt"), App.Read); } catch { await storageFolder.CreateFileAsync("read.txt", CreationCollisionOption.ReplaceExisting); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { try { ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile(); bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess; if (!internet) { NetworkError.Visibility = Visibility.Visible; return; } Categories cats = await SerializerExtensions.DeSerializeObject <Categories>( await ApplicationData.Current.LocalFolder.GetFileAsync("sites")); if (e != null) { if (e.Parameter != null) { NotificationStatus.Visibility = Visibility.Visible; NotificationStatus.IsActive = true; string[] data = e.Parameter.ToString().Split(';'); await SearchArticleFromNotification(data[0], data[1]); NotificationStatus.IsActive = false; NotificationStatus.Visibility = Visibility.Collapsed; } } if (cats != null) { foreach (Category cat in cats.categories) { PivotItem item = new PivotItem(); item.Header = cat.title; Frame frame = new Frame(); Bag bag = new Bag(); bag.list = cat.websites; bag.frame = ArticleFrame; bag.parentframe = Frame; frame.Navigate(typeof(ItemsControlView), bag); item.Content = frame; item.Margin = new Thickness(0, 0, 0, 0); Categories.Items.Add(item); } if (cats.categories.Count == 0) { Welcome.Visibility = Visibility.Visible; } } else { Welcome.Visibility = Visibility.Visible; } await FileIO.WriteTextAsync(await ApplicationData.Current.LocalFolder.GetFileAsync("datecutoff"), DateTime.Now.ToString()); } catch (FileNotFoundException ex) { Welcome.Visibility = Visibility.Visible; } catch (Exception ex) { NetworkError.Visibility = Visibility.Visible; } }