Пример #1
0
        private async void MarkReadOrUnread_Click(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text                 = "执行中...";
            ProgressBar.IsVisible            = true;
            UpdateButton.IsEnabled           = false;
            MarkReadOrUnreadButton.IsEnabled = false;
            DeleteButton.IsEnabled           = false;
            AnimeAPI api = new AnimeAPI();

            try
            {
                if ((MarkReadOrUnreadButton.Content as string) == "标记为更新")
                {
                    await api.AddHighlight(subscriptionIndex.aid, "2");
                }
                else
                {
                    await api.DelHighlight(subscriptionIndex.aid);
                }
                if (settings.Contains("MustRefresh"))
                {
                    settings.Remove("MustRefresh");
                }
                settings.Add("MustRefresh", true);
                settings.Save();
                ToastPrompt toast = new ToastPrompt();
                if ((MarkReadOrUnreadButton.Content as string) == "标记为更新")
                {
                    MarkReadOrUnreadButton.Content = "标记为未更新";
                    toast.Title = "成功标记为更新";
                }
                else
                {
                    MarkReadOrUnreadButton.Content = "标记为更新";
                    toast.Title = "成功标记为未更新";
                }
                toast.FontSize = 20;
                toast.Show();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
                if (api.lastError == AnimeAPI.ERROR.ERROR_INVALID_KEY)
                {
                    settings.Remove("UserKey");
                    settings.Save();
                    NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                }
            }
            finally
            {
                UpdateButton.IsEnabled           = true;
                MarkReadOrUnreadButton.IsEnabled = true;
                DeleteButton.IsEnabled           = true;
                ProgressBar.IsVisible            = false;
                ProgressBar.Text = "";
            }
        }
Пример #2
0
        private async void MarkRead_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("", "是否将所有订阅标记为未更新?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return;
            }
            IsMarkReadBusy = true;
            AnimeAPI api = new AnimeAPI();

            try
            {
                foreach (ViewModels.SubscriptionModel item in App.ViewModel.SubscriptionItems)
                {
                    if (item.highlight != "0")
                    {
                        await api.DelHighlight(item.aid);
                    }
                }
                ToastPrompt toast = new ToastPrompt();
                toast.Title    = "成功将所有订阅标记为未更新";
                toast.FontSize = 20;
                toast.Show();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
                if (api.lastError == AnimeAPI.ERROR.ERROR_INVALID_KEY)
                {
                    settings.Remove("UserKey");
                    settings.Save();
                    NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                }
            }
            finally
            {
                IsMarkReadBusy = false;
                RefreshSubscription();
            }
        }
Пример #3
0
/*
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine(((ViewModels.SubscriptionModel)((MenuItem)sender).DataContext).name);
            Debug.WriteLine(App.ViewModel.SubscriptionItems.Count);
            SetBusy("DeleteItem");
            try
            {
                ViewModels.SubscriptionModel vi = (ViewModels.SubscriptionModel)((MenuItem)sender).DataContext;
                HttpEngine httpRequest = new HttpEngine();
                string result = await httpRequest.GetAsync("http://api2.ricter.info/del_anime?key=" + settings["UserKey"] + "&aid=" + vi.aid);
                if (result.Contains("ERROR_"))
                {
                    if (result == "ERROR_INVALID_KEY")
                    {
                        MessageBox.Show("", "您的帐号已在别的客户端登陆,请重新登陆", MessageBoxButton.OK);
                        settings.Remove("UserKey");
                        NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                        return;
                    }
                    if (result == "ERROR_INVALID_ID")
                    {
                        throw new Exception("您选择的内容可能已经被删除,请刷新后重试");
                    }
                    throw new Exception("发生了错误,但我不知道是什么");
                }
                int index = App.ViewModel.SubscriptionItems.IndexOf(vi); 
                App.ViewModel.SubscriptionItems.Remove(vi);
                ((MenuItem)sender).UpdateLayout();
            }
            catch (Exception exception)
            {
                MessageBox.Show("", exception.Message, MessageBoxButton.OK);
            }
            finally
            {
                SetIdle("DeleteItem");
            }
        }
 */
        #endregion

        #region 标记已读
        private async void MarkRead_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("", "确定将所有更新标记为已读?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                return;
            IsMarkReadBusy = true;
            AnimeAPI api = new AnimeAPI();
            try
            {
                foreach (ViewModels.SubscriptionModel item in App.ViewModel.SubscriptionItems)
                {
                    if (item.updated == System.Windows.Visibility.Visible)
                    {
                        await api.DelHighlight(item.aid);
                    }
                }
/*
                foreach (ViewModels.SubscriptionModel Items in App.ViewModel.SubscriptionItems)
                {
                    if (Items.updated == System.Windows.Visibility.Visible)
                    {
                        HttpEngine httpRequest = new HttpEngine();
                        string result = await httpRequest.GetAsync("http://apianime.ricter.info/del_highlight?key=" + settings["UserKey"] + "&id=" + Items.aid + "&hash=" + new Random().Next());
                        if (result.Contains("ERROR_"))
                        {
                            if (result == "ERROR_INVALID_KEY")
                            {
                                MessageBox.Show("", "您的帐号已在别的客户端登陆,请重新登陆", MessageBoxButton.OK);
                                settings.Remove("UserKey");
                                NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                                return;
                            }
                            throw new Exception("发生了错误,但我不知道是什么");
                        }
                    }
                }
 */
                ToastPrompt toast = new ToastPrompt();
                toast.Title = "成功将所有更新标记为已读";
                toast.FontSize = 20;
                toast.Show();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
                if (api.lastError == AnimeAPI.ERROR.ERROR_INVALID_KEY)
                {
                    settings.Remove("UserKey");
                    settings.Save();
                    NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                }
            }
            finally
            {
                IsMarkReadBusy = false;
                RefreshSubscription();
            }
        }
Пример #4
0
        private async void MarkReadOrUnread_Click(object sender, RoutedEventArgs e)
        {
            ProgressBar.Text = "执行中...";
            ProgressBar.IsVisible = true;
            UpdateButton.IsEnabled = false;
            MarkReadOrUnreadButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
            AnimeAPI api = new AnimeAPI();
            try
            {
/*
                HttpEngine httpRequest = new HttpEngine();
                string requestUrl = "";
*/
                if ((MarkReadOrUnreadButton.Content as string) == "标记为未读")
                {
                    await api.AddHighlight(subscriptionIndex.aid, "2");
/*
                    requestUrl = "http://apianime.ricter.info/add_highlight?key=" + settings["UserKey"] + "&id=" + subscriptionIndex.aid + "&hash=" + new Random().Next();
*/
                }
                else
                {
                    await api.DelHighlight(subscriptionIndex.aid);
/*
                    requestUrl = "http://apianime.ricter.info/del_highlight?key=" + settings["UserKey"] + "&id=" + subscriptionIndex.aid + "&hash=" + new Random().Next();
*/
                }
/*
                string result = await httpRequest.GetAsync(requestUrl);
                if (result.Contains("ERROR_"))
                {
                    if (result == "ERROR_INVALID_KEY")
                    {
                        MessageBox.Show("", "您的帐号已在别的客户端登陆,请重新登陆", MessageBoxButton.OK);
                        settings.Remove("UserKey");
                        NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                        return;
                    }
                    throw new Exception("发生了错误,但我不知道是什么");
                }
 */
                if (settings.Contains("MustRefresh"))
                    settings.Remove("MustRefresh");
                settings.Add("MustRefresh", true);
                settings.Save();
                ToastPrompt toast = new ToastPrompt();
                if ((MarkReadOrUnreadButton.Content as string) == "标记为未读")
                {
                    MarkReadOrUnreadButton.Content = "标记为已读";
                    toast.Title = "成功标记为未读";
                }
                else
                {
                    MarkReadOrUnreadButton.Content = "标记为未读";
                    toast.Title = "成功标记为已读";
                }
                toast.FontSize = 20;
                toast.Show();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "错误", MessageBoxButton.OK);
                if (api.lastError == AnimeAPI.ERROR.ERROR_INVALID_KEY)
                {
                    settings.Remove("UserKey");
                    settings.Save();
                    NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
                }
            }
            finally
            {
                UpdateButton.IsEnabled = true;
                MarkReadOrUnreadButton.IsEnabled = true;
                DeleteButton.IsEnabled = true;
                ProgressBar.IsVisible = false;
                ProgressBar.Text = "";
            }
        }