Beispiel #1
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (args.Kind == ActivationKind.ToastNotification)
            {
                var      toastArgs = args as ToastNotificationActivatedEventArgs;
                var      arguments = toastArgs.Argument;
                string[] lineData  = arguments.Split('-');
                Utilities.LineSerializer lineSerializer = new Utilities.LineSerializer(Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse());
                var savedLines = await lineSerializer.readLines();

                foreach (Line line in savedLines)
                {
                    if (lineData[0] == line.FromsID && lineData[1] == line.FromlsID && lineData[2] == line.TosID && lineData[3] == line.TolsID)
                    {
                        rootFrame.Navigate(typeof(Results), line);
                    }
                }
            }

            Window.Current.Activate();
        }
Beispiel #2
0
        private async Task getSavedData(UpdateMethod update = UpdateMethod.IFOUTOFDATE, int toupdate = -1)
        {
            lastRefreshed = DateTime.Now;

            // LOAD SAVED DATA
            lineSerializer = new Utilities.LineSerializer(ResourceLoader.GetForViewIndependentUse());
            savedLines     = await lineSerializer.readLines();

            LineList.Items.Clear();

            //DISPLAY DATA
            if (savedLines.Count == 0) // no data
            {
                error.Visibility          = Visibility.Visible;
                title.Visibility          = Visibility.Collapsed;
                inprogress.IsActive       = false;
                inprogressbg.Visibility   = Visibility.Collapsed;
                inprogresstext.Visibility = Visibility.Collapsed;
#if WINDOWS_UWP
                if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox")
                {
                    Loaded += (s, e) =>
                    {
                        Frame.Navigate(typeof(Search), null, new EntranceNavigationTransitionInfo());
                        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                    };
                }
#endif
            }
            else                       // create cards
            {
                error.Visibility = Visibility.Collapsed;
                title.Visibility = Visibility.Visible;

                inprogress.IsActive     = true;
                inprogressbg.Visibility = Visibility.Visible;
                AppbarUpdate.IsEnabled  = false;

                /*var gridVisual = ElementCompositionPreview.GetElementVisual(this.myGrid);
                 * var compositor = gridVisual.Compositor;
                 * this.effectVisual = compositor.CreateSpriteVisual();
                 * GaussianBlurEffect blurEffect = new GaussianBlurEffect()
                 * {
                 *  BorderMode = EffectBorderMode.Hard, // NB: default mode here isn't supported yet.
                 *  Source = new CompositionEffectSourceParameter("source")
                 * };
                 * var effectFactory = compositor.CreateEffectFactory(blurEffect);
                 * var effectBrush = effectFactory.CreateBrush();
                 * effectBrush.SetSourceParameter("source", compositor.CreateBackdropBrush());
                 * this.effectVisual.Brush = effectBrush;
                 * ElementCompositionPreview.SetElementChildVisual(this.myGrid, this.effectVisual);*/

                string tomorrow;
                Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
                Windows.Storage.ApplicationDataContainer localSettings   = Windows.Storage.ApplicationData.Current.LocalSettings;

                //List<Card> toAdd = new List<Card>();
                for (int i = 0; i < savedLines.Count; i++) // for each line
                {
                    int toDisplay = -1;
                    tomorrow = "";
                    for (int k = 0; k < 2; k++) // try next day as well if there are no more Buses today
                    {
                        toDisplay = -1;
                        DateTime        updateday = DateTime.Today.Date.AddDays(k);
                        var             profile   = NetworkInformation.GetInternetConnectionProfile();
                        NetworkCostType cost      = NetworkCostType.Unknown;
                        if (profile != null)
                        {
                            cost = profile.GetConnectionCost().NetworkCostType;
                        }

                        if (update != UpdateMethod.NEVER && (update == UpdateMethod.ALWAYS || toupdate == i || (((bool)localSettings.Values["alwaysupdate"] || cost == NetworkCostType.Unrestricted) && savedLines[i].LastUpdated < updateday))) // update if we haven't updated yet today
                        {
                            inprogresstext.Visibility = Visibility.Visible;
                            savedLines[i].Buses       = null;
                            try
                            {
                                await savedLines[i].updateOn(updateday);
                                savedLines[i].LastUpdated = updateday;
                                await lineSerializer.saveLine(savedLines[i]);
                            }
                            catch (HttpRequestException)
                            {
                                inprogress.IsActive       = false;
                                inprogresstext.Visibility = Visibility.Collapsed;
                                AppbarUpdate.IsEnabled    = true;
                                var dialog = new MessageDialog(resourceLoader.GetString("NetworkError"), resourceLoader.GetString("NetworkErrorTitle"));
                                dialog.Commands.Add(new UICommand("OK"));
                                dialog.CancelCommandIndex  = 0;
                                dialog.DefaultCommandIndex = 0;
                                try { await dialog.ShowAsync(); } catch (UnauthorizedAccessException) { }
                                await getSavedData(UpdateMethod.NEVER);

                                return;
                            }
                        }
                        for (int j = 0; j < savedLines[i].Buses.Count && savedLines[i].LastUpdated >= DateTime.Today; j++) // get first bus after current time (for each line)
                        {
                            string start, name, from, to;
                            savedLines[i].Buses[j].TryGetValue("indulasi_ido", out start);
                            savedLines[i].Buses[j].TryGetValue("vonalnev", out name);
                            savedLines[i].Buses[j].TryGetValue("indulasi_hely", out from);
                            savedLines[i].Buses[j].TryGetValue("erkezesi_hely", out to);
                            if ((TimeSpan.Parse(start).TotalSeconds >= DateTime.Now.TimeOfDay.TotalSeconds || savedLines[i].LastUpdated > DateTime.Today) && !(!(bool)roamingSettings.Values["canchange"] && name.Split('|')[0] == " ∙∙∙"))
                            {
                                if (!((bool)roamingSettings.Values["exact"] && ((savedLines[i].From != from && savedLines[i].From.Contains(",")) || (savedLines[i].To != to && savedLines[i].To.Contains(",")))))
                                {
                                    toDisplay = j;
                                    break;
                                }
                            }
                        }
                        if (savedLines[i].LastUpdated > DateTime.Today && toDisplay != -1)
                        {
                            tomorrow = resourceLoader.GetString("CardTomorrowLong");
                        }
                        if (toDisplay > -1)
                        {
                            break;
                        }
                        if (savedLines[i].LastUpdated > DateTime.Today)
                        {
                            k++;
                        }

                        /*if (!(bool)localSettings.Values["alwaysupdate"] && cost != NetworkCostType.Unrestricted && (toupdate != i || !update))
                         * {
                         *  if (k == 0 && toDisplay == -1 && savedLines[i].LastUpdated <= DateTime.Today)
                         *      savedLines[i].LastUpdated = DateTime.Today.AddDays(-1);
                         *  k++;
                         * }*/
                    }
                    //if (toDisplay == -1)
                    //    savedLines[i].LastUpdated = DateTime.ParseExact("1000.01.01", "yyyy.MM.dd", System.Globalization.CultureInfo.InvariantCulture);
                    Card newcard = new Card(savedLines[i], toDisplay);    // create card for next bus
                    newcard.LineName = tomorrow + newcard.LineName;

                    if (toDisplay != -1 || savedLines[i].LastUpdated < DateTime.Today)
                    {
                        int num = i;

                        newcard.Tapped += (s, e) => OpenLine(newcard, num);
                        //newcard.KeyUp += LineList_KeyUp;
                    }

                    // Context menu
                    tiles = await SecondaryTile.FindAllForPackageAsync();

#if WINDOWS_UWP
                    if (!ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "ContextFlyout"))
#endif
                    {
                        newcard.RightTapped += (s, e) =>
                        {
                            var contextMenu = CreateContextMenu(newcard);
                            var point       = e.GetPosition((Card)s);
                            contextMenu.ShowAt(newcard /*, point*/);
                        };
                    }
#if WINDOWS_UWP
                    else
                    {
                        newcard.ContextFlyout = CreateContextMenu(newcard);
                    }
#endif

                    //toAdd.Add(newcard);
                    LineList.Items.Add(newcard);
                }
                LineList.SelectedIndex    = 0;
                inprogresstext.Visibility = Visibility.Collapsed;
                //LineList.ItemsSource = toAdd;

                inprogress.IsActive       = false;
                inprogressbg.Visibility   = Visibility.Collapsed;
                inprogresstext.Visibility = Visibility.Collapsed;
            }

            AppbarUpdate.IsEnabled = true;
#if WINDOWS_UWP
            UpdateJumplist();
#endif
            WindowResized(null, null);
        }