Example #1
0
        private async void Search(string text, bool addToHistory = true)
        {
            if (rules == null)
            {
                return;
            }
            if (text.Length < 3)
            {
                var dialog = new MessageDialog("Search term must have at least 3 characters");
                await dialog.ShowAsync();

                return;
            }

            using (ProgressRingViewer.Show()) {
                List <Rule> source = new List <Rule>();

                foreach (var rule in rules)
                {
                    if (rule.Title.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0 ||
                        rule.Text.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        source.Add(rule);
                    }
                    foreach (var rule2 in rule.SubRules)
                    {
                        if (rule2.Title.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0 ||
                            rule2.Text.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            source.Add(rule2);
                        }
                        source.AddRange(
                            rule2.SubRules.Where(
                                rule3 => rule3.Title.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                rule3.Text.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0
                                )
                            );
                    }
                }

                if (addToHistory)
                {
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                        AppViewBackButtonVisibility.Visible;
                    ScrollViewer scrollViewer =
                        VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(list, 0), 0) as ScrollViewer;
                    if (scrollViewer != null)
                    {
                        actualSearch.VerticalOffset = scrollViewer.VerticalOffset;
                    }
                    history.Add(actualSearch);
                    actualSearch = new HistoryItem(HistoryType.Search, text);
                }
                list.ItemsSource = source;

                CustomEventlogger.Log("SearchText");

                homeButton.IsEnabled = true;
            }
        }
Example #2
0
        private async void OnDonateButtonClick(object sender, RoutedEventArgs args)
        {
            using (ProgressRingViewer.Show()) {
                MessageDialog dialog = new MessageDialog("");
                try {
                    ListingInformation info = await CurrentApp.LoadListingInformationAsync();

                    ProductListing donation;
                    if (info.ProductListings.TryGetValue("donation", out donation))
                    {
                        if (await FulfillDonation())
                        {
                            PurchaseResults purchaseResult =
                                await CurrentApp.RequestProductPurchaseAsync(donation.ProductId);

                            if (purchaseResult.Status == ProductPurchaseStatus.Succeeded)
                            {
                                dialog.Content = ResourceLoader.GetForCurrentView().GetString("thanksForDonation") +
                                                 "\n" + ResourceLoader.GetForCurrentView().GetString("youCanRate");
                            }
                            else if (purchaseResult.Status == ProductPurchaseStatus.NotPurchased)
                            {
                                dialog.Content =
                                    ResourceLoader.GetForCurrentView().GetString("anywayThanksForUsingApp") +
                                    "\n" + ResourceLoader.GetForCurrentView().GetString("youCanRate");
                            }
                            else
                            {
                                dialog.Content = ResourceLoader.GetForCurrentView().GetString("errorOcurred") +
                                                 "\n" +
                                                 ResourceLoader.GetForCurrentView()
                                                 .GetString("thanksAnywayTryAgainOrRate");
                            }
                        }
                        else
                        {
                            dialog.Content =
                                ResourceLoader.GetForCurrentView().GetString("errorOcurredDonationPendingOrServerError") +
                                "\n" + ResourceLoader.GetForCurrentView().GetString("thanksAnywayTryAgainOrRate");
                        }
                    }
                    else
                    {
                        dialog.Content = ResourceLoader.GetForCurrentView().GetString("noActiveDonations") +
                                         "\n" + ResourceLoader.GetForCurrentView().GetString("youCanRate");
                    }
                } catch {
                    dialog.Content = ResourceLoader.GetForCurrentView().GetString("errorOcurred") +
                                     "\n" + ResourceLoader.GetForCurrentView().GetString("thanksAnywayTryAgainOrRate");
                }

                await dialog.ShowAsync();
            }
        }
Example #3
0
        private async void OnChangeRulesButtonClick(object sender, RoutedEventArgs args)
        {
            using (ProgressRingViewer.Show()) {
                int n = await ShowRulesListPicker(ResourceLoader.GetForCurrentView().GetString("selectTheRules"));

                if (n >= 0 && n < rulesSources.Count)
                {
                    if (await LoadDataAsync(n))
                    {
                        ShowByNumber(0, false);
                        history.Clear();
                    }
                    else
                    {
                        MessageDialog dialog =
                            new MessageDialog(ResourceLoader.GetForCurrentView().GetString("errorLoadingRules"));
                        await dialog.ShowAsync();
                    }
                }
            }
        }
Example #4
0
        private async void OnLoaded(object sender, RoutedEventArgs args)
        {
            ProgressRingViewer.page = this;
            if (rules == null)
            {
                using (ProgressRingViewer.Show()) {
                    if (!await LoadDataAsync(rulesSources.Count - 1))
                    {
                        MessageDialog dialog =
                            new MessageDialog(ResourceLoader.GetForCurrentView().GetString("errorLoadingLastRules"));
                        await dialog.ShowAsync();
                    }
                    else
                    {
                        ShowByNumber(0, false);
                        homeButton.IsEnabled = false;

                        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                            AppViewBackButtonVisibility.Collapsed;
                        SystemNavigationManager.GetForCurrentView().BackRequested += OnBackButtonRequested;
                    }
                }
            }
        }
Example #5
0
        private async void OnExperimentalButtonClick(object sender, RoutedEventArgs args)
        {
            using (ProgressRingViewer.Show()) {
                int n1 = await ShowRulesListPicker(ResourceLoader.GetForCurrentView().GetString("selectOldRules"));

                if (n1 < 0 || n1 >= rulesSources.Count)
                {
                    return;
                }

                int n2 = await ShowRulesListPicker(ResourceLoader.GetForCurrentView().GetString("selectNewRules"));

                if (n2 < 0 || n2 >= rulesSources.Count)
                {
                    return;
                }

                List <Rule> from = await Rule.getRules(rulesSources[n1]),
                            to   = await Rule.getRules(rulesSources[n2]);

                if (from == null || to == null)
                {
                    MessageDialog dialog =
                        new MessageDialog(ResourceLoader.GetForCurrentView().GetString("errorLoadingRules"));
                    await dialog.ShowAsync();

                    return;
                }
                clearCacheButton.IsEnabled = true;

                List <Rule> li = new List <Rule>();

                Rule rule;

                foreach (Rule r1 in from)
                {
                    rule = Compare(r1, FindRule(to, r1.Title));
                    if (rule != null)
                    {
                        li.Add(rule);
                    }
                    foreach (Rule r2 in r1.SubRules)
                    {
                        rule = Compare(r2, FindRule(to, r2.Title));
                        if (rule != null)
                        {
                            li.Add(rule);
                        }
                        foreach (Rule r3 in r2.SubRules)
                        {
                            rule = Compare(r3, FindRule(to, r3.Title));
                            if (rule != null)
                            {
                                li.Add(rule);
                            }
                        }
                    }
                }

                foreach (Rule r1 in to)
                {
                    rule = FindRule(from, r1.Title);
                    if (rule == null)
                    {
                        li.Add(new Rule("(+) " + r1.Title, r1.Text));
                    }
                    foreach (Rule r2 in r1.SubRules)
                    {
                        rule = FindRule(from, r2.Title);
                        if (rule == null)
                        {
                            li.Add(new Rule("(+) " + r2.Title, r2.Text));
                        }
                        foreach (Rule r3 in r2.SubRules)
                        {
                            rule = FindRule(from, r3.Title);
                            if (rule == null)
                            {
                                li.Add(new Rule("(+) " + r3.Title, r3.Text));
                            }
                        }
                    }
                }

                list.ItemsSource = li;

                CustomEventlogger.Log("CompareRules");
            }
        }