Beispiel #1
0
        private async void Do()
        {
            //base.OnNavigatedTo(e);
            ResourceLoader           resourceLoader  = ResourceLoader.GetForCurrentView();
            ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;

            Line line = card.ParentLine;
            int  i    = card.BusIndex;

            using (var client = new HttpClient()) // get new suggestions
            {
                string fieldvalue, price, price90, price50;
                line.Buses[i].TryGetValue("details", out fieldvalue);
                line.Buses[i].TryGetValue("fare", out price);
                line.Buses[i].TryGetValue("fare_90_percent", out price90);
                line.Buses[i].TryGetValue("fare_50_percent", out price50);
                string tosend = "{\"query\":\"jarat_kifejtes_text_json\",\"start_ls_id\":" + line.FromlsID + ",\"start_ls_name\":\"" + line.From + "\",\"stop_ls_id\":" + line.TolsID + ",\"stop_ls_name\":\"" + line.To + "\",\"fieldvalue\":" + fieldvalue + "}";
                tosend = tosend.Replace(' ', '+');
                var values = new Dictionary <string, string>
                {
                    { "json", tosend }
                };

                var content = new FormUrlEncodedContent(values);
                HttpResponseMessage response = null;
                try { response = await client.PostAsync("http://menetrendek.hu/uj_menetrend/hu/ajax_response_gen.php", content); }
                catch (HttpRequestException)
                {
                    var dialog = new MessageDialog(resourceLoader.GetString("NetworkError"), resourceLoader.GetString("NetworkErrorTitle"));
                    dialog.Commands.Add(new UICommand("OK", (command) => { }));
                    dialog.CancelCommandIndex  = 0;
                    dialog.DefaultCommandIndex = 0;
                    //await dialog.ShowAsync();
                    return;
                }

                var result = await response.Content.ReadAsStringAsync();

                result = Regex.Unescape(result);
                string[] data = Regex.Split(result, "\"\\d+\":{");

                int n = 0;
                for (int j = 1; j < data.Length; j++)
                {
                    BusDetail detail  = new BusDetail();
                    string    toParse = data[j];
                    if (getproperty(toParse, "muvelet") == "indulás")
                    {
                        continue;
                    }
                    else if (getproperty(toParse, "muvelet") == "felszállás")
                    {
                        detail.Type = 1;
                        n++;
                    }
                    else if (getproperty(toParse, "muvelet") == "átszállás" || getproperty(data[j == data.Length - 1 ? 0 : j + 1], "muvelet") == "érkezés")
                    {
                        detail.Type = 3;
                    }
                    else
                    {
                        detail.Type = 2;
                    }
                    detail.Place = getproperty(toParse, "allomas").Replace('+', ' ');
                    detail.Time  = getproperty(toParse, "idopont");

                    if (getproperty(toParse, "utazasi_tavolsag") != "")
                    {
                        detail.Distance = getproperty(toParse, "utazasi_tavolsag") + " km";
                    }
                    if (getproperty(toParse, "tavolsag") != "")
                    {
                        detail.Distance = (getproperty(toParse, "tavolsag") == "0") ? "" : getproperty(toParse, "tavolsag") + " m";
                    }

                    if (getproperty(toParse, "muvelet") == "felszállás")
                    {
                        string extra;
                        line.Buses[i].TryGetValue("extra", out extra);
                        detail.Extra = extra.Split('|')[n];

                        string displayprice;
                        switch ((String)roamingSettings.Values["price"])
                        {
                        case "-50%":
                            line.Buses[i].TryGetValue("fare_50_percent", out displayprice);
                            displayprice = displayprice.Split('|')[n] + " Ft";
                            break;

                        case "-90%":
                            line.Buses[i].TryGetValue("fare_90_percent", out displayprice);
                            displayprice = displayprice.Split('|')[n] + " Ft";
                            break;

                        case "Ingyen":
                            displayprice = (string.IsNullOrEmpty(extra)) ? "0 Ft" : extra.Split('|')[n] + " Ft";
                            break;

                        case "100%":
                        default:
                            line.Buses[i].TryGetValue("fare", out displayprice);
                            displayprice = displayprice.Split('|')[n] + " Ft";
                            break;
                        }
                        detail.Price = displayprice;

                        string num;
                        line.Buses[i].TryGetValue("vonalnev", out num);
                        detail.Linenum = num.Split('|')[n].Trim();
                        if (!string.IsNullOrEmpty(detail.Linenum))
                        {
                            detail.Linenum += ", ";
                        }
                        string info = getproperty(toParse, "vegallomasok");
                        info            = info.Replace("felől", "▶️");
                        info            = info.Replace(" felé", "");
                        info            = info.Replace("Helyből indul", "▶️");
                        detail.Linenum += info;

                        detail.Lowfloor = getproperty(toParse, "alacsonypadlos") == "1";

                        detail.Organisation = getproperty(toParse, "tarsasag");
                    }
                    if (getproperty(toParse, "muvelet") == "átszállás")
                    {
                        Match match = Regex.Match(toParse, "\\d+(?= perc g)");
                        if (match.Value != "")
                        {
                            detail.Duration = match.Value.TrimStart('0') + resourceLoader.GetString("Mins");
                        }
                    }

                    DetailItem item = new DetailItem(detail);
                    if (LineList.Items.Count == 0)
                    {
                        item.Margin = new Thickness(0, 30, 0, 0);
                    }
                    LineList.Items.Add(item);
                    //}
                }

                inprogress.IsActive     = false;
                inprogress.Visibility   = Visibility.Collapsed;
                listscroller.Visibility = Visibility.Visible;
            }
        }
Beispiel #2
0
        //todo: (Line line, int day, int i)
        internal DetailItem(BusDetail bus)
        {
            this.InitializeComponent();
            ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView();

#if WINDOWS_UWP
            rect.Fill = Resources["SystemControlBackgroundAccentBrush"] as SolidColorBrush;
            def2.Fill = Resources["SystemControlBackgroundAccentBrush"] as SolidColorBrush;
#elif WINDOWS_PHONE_APP
            rect.Fill = Resources["PhoneAccentBrush"] as SolidColorBrush;
            def2.Fill = Resources["PhoneAccentBrush"] as SolidColorBrush;
#endif

            LineNumber = bus.Linenum;
            StartTime  = bus.Time;
            From       = bus.Place;
            TravelTime = bus.Duration;
            Distance   = bus.Distance;
            Price      = bus.Price;

            if (LineNumber == "")
            {
                price.SetValue(Canvas.TopProperty, 18);
            }

            if (bus.Type == 1) // bus
            {
                Org           = resourceLoader.GetString("Organization") + bus.Organisation;
                canvas.Height = 77;
                rect.Height   = 69;
                dist.SetValue(Canvas.TopProperty, 39);

                double width = Window.Current.Bounds.Width;
#if WINDOWS_UWP
                if (width < 370)
                {
                    ticket.SetValue(Canvas.LeftProperty, 150);
                    price.SetValue(Canvas.LeftProperty, 103);
                    num.SetValue(Canvas.LeftProperty, 103);
                    org.SetValue(Canvas.LeftProperty, 103);
                    pricenote.SetValue(Canvas.LeftProperty, 168);
                    chair.SetValue(Canvas.LeftProperty, 305);
                    pricenote.Text = resourceLoader.GetString("SupTicketBeginning") + bus.Extra + resourceLoader.GetString("SupTicketShort");
                    if (width < 330)
                    {
                        pricenote.FontSize = 10;
                        chair.SetValue(Canvas.LeftProperty, 290);
                    }
                }
                else
                {
                    pricenote.Text = resourceLoader.GetString("SupTicketBeginning") + bus.Extra + resourceLoader.GetString("SupTicket");
                }
#elif WINDOWS_PHONE_APP
                if (width < 410)
                {
                    pricenote.Text = resourceLoader.GetString("SupTicketBeginning") + bus.Extra + resourceLoader.GetString("SupTicketShort");
                }
                else
                {
                    pricenote.Text = resourceLoader.GetString("SupTicketBeginning") + bus.Extra + resourceLoader.GetString("SupTicket");
                }
#endif
                if (bus.Extra == "0")
                {
                    if (width >= 350)
                    {
                        chair.SetValue(Canvas.LeftProperty, 155);
                    }
                    else
                    {
                        chair.SetValue(Canvas.LeftProperty, 147);
                    }
                }
                if (bus.Extra != "0")
                {
                    ticket.Visibility    = Visibility.Visible;
                    pricenote.Visibility = Visibility.Visible;
                }
                if (bus.Lowfloor)
                {
                    chair.Visibility = Visibility.Visible;
                }
            }

            if (bus.Type == 2) // end
            {
                rect.Visibility = Visibility.Collapsed;
            }

            if (bus.Type == 3) // walk
            {
#if WINDOWS_UWP
                rect.Fill = new SolidColorBrush((Color)Application.Current.Resources["SystemBaseHighColor"]);
#elif WINDOWS_PHONE_APP
                rect.Fill = new SolidColorBrush((Color)Application.Current.Resources["PhoneForegroundColor"]);
#endif

                /*if (Application.Current.RequestedTheme == ApplicationTheme.Dark)
                 *  rect.Fill = new SolidColorBrush(Colors.White);
                 * else
                 *  rect.Fill = new SolidColorBrush(Colors.Black);*/
                if (bus.Duration != null)
                {
                    dist.SetValue(Canvas.TopProperty, 40);
                }
            }
        }