Ejemplo n.º 1
0
        async Task showAQI()
        {
            if (k == 0)
            {
                var status = await Permissions.CheckStatusAsync <Permissions.LocationWhenInUse>();

                if (status == PermissionStatus.Granted)
                {
                    if (Preferences.Get("togl", true))
                    {
                        orderLocation = true;
                    }
                    else
                    {
                        orderLocation = false;
                    }
                }
                else
                {
                    status = await Permissions.RequestAsync <Permissions.LocationWhenInUse>();

                    if (status == PermissionStatus.Granted)
                    {
                        orderLocation = true;
                        Preferences.Set("togl", true);
                    }
                    else
                    {
                        orderLocation = false;
                        Preferences.Set("togl", false);
                    }
                }
                List <Datum> stations = null;
                await Task.Run(async() =>
                {
                    stations = await AQIAPI.GetAvailableSTations();
                });

                if (stations.Count == 0)
                {
                    Label lbb = new Label()
                    {
                        Text = "There is a problem with getting data.\nPlease try again later", HorizontalTextAlignment = TextAlignment.Center
                    };
                    stek.Children.Add(lbb);
                    return;
                }

                List <Example> stt             = new List <Example>();
                List <Example> problemStations = new List <Example>();
                foreach (var st in stations)
                {
                    Example station = null;
                    await Task.Run(async() =>
                    {
                        station = await AQIAPI.GetStationInfo(st);
                    });

                    try
                    {
                        if (orderLocation)
                        {
                            var location = await Geolocation.GetLastKnownLocationAsync();

                            var distance = Location.CalculateDistance(station.data.city.geo[0], station.data.city.geo[1], location, DistanceUnits.Kilometers);
                            station.data.city.distance = distance;
                        }

                        int notImportant = 0;
                        var well         = Int32.TryParse(station.data.aqi, out notImportant);
                        if (well)
                        {
                            stt.Add(station);
                        }
                        else
                        {
                            problemStations.Add(station);
                            station.data.aqi = "0";
                        }
                    }
                    catch (Exception e)
                    {
                        problemStations.Add(station);
                        station.data.aqi = "0";
                    }
                }
                if (!orderLocation)
                {
                    ordered = stt.OrderBy(f => Int32.Parse(f.data.aqi)).ToList();
                }
                else
                {
                    ordered = stt.OrderBy(f => f.data.city.distance).ToList();
                    ordered.Reverse();
                }
                ordered.AddRange(problemStations);
                all = ordered;
            }
            stek.Children.Clear();

            for (int i = ordered.Count - 1; i >= 0; i--)
            {
                if (ordered[i].data.city.name.ToLower().Contains("kosovo"))
                {
                    continue;
                }
                Frame frfr = new Frame()
                {
                    CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), BackgroundColor = Color.FromHex("#121212")
                };
                Grid grgr = new Grid();


                grgr.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(3, GridUnitType.Star)
                });
                grgr.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                grgr.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                grgr.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                grgr.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                grgr.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                grgr.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                Label name, AQI;

                name = new Label()
                {
                    FontSize = 18, FontAttributes = FontAttributes.Bold, Text = ordered[i].data.city.name, TextColor = Color.White
                };
                try
                {
                    AQI = new Label()
                    {
                        FontSize = 23, FontAttributes = FontAttributes.Bold, Text = ordered[i].data.aqi.ToString() + "\nAQI", HorizontalTextAlignment = TextAlignment.End
                    };
                    if (Int32.Parse(ordered[i].data.aqi) <= 50)
                    {
                        AQI.TextColor = Color.FromHex("#6cf58e");
                    }
                    else if (Int32.Parse(ordered[i].data.aqi) > 50 && Int32.Parse(ordered[i].data.aqi) < 100)
                    {
                        AQI.TextColor = Color.FromHex("#ff954f");
                    }
                    else
                    {
                        AQI.TextColor = Color.FromHex("#FF7595");
                    }
                }
                catch (Exception e)
                {
                    AQI = new Label()
                    {
                        FontSize = 23, FontAttributes = FontAttributes.Bold, Text = "0\nAQI", HorizontalTextAlignment = TextAlignment.End
                    };
                    AQI.TextColor = Color.FromHex("#6cf58e");
                }



                Label pm10;
                if (ordered[i].data.iaqi.pm10 != null)
                {
                    pm10 = new Label()
                    {
                        FontSize = 15, Text = ordered[i].data.iaqi.pm10.v.ToString(), HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                }
                ;
                else
                {
                    pm10 = new Label()
                    {
                        FontSize = 15, Text = "непознато", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                };

                Label coo;
                if (ordered[i].data.iaqi.co != null)
                {
                    coo = new Label()
                    {
                        FontSize = 15, Text = ordered[i].data.iaqi.co.v.ToString(), HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                }
                ;
                else
                {
                    coo = new Label()
                    {
                        FontSize = 15, Text = "непознато", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                };

                Label so2o;
                if (ordered[i].data.iaqi.so2 != null)
                {
                    so2o = new Label()
                    {
                        FontSize = 15, Text = ordered[i].data.iaqi.so2.v.ToString(), HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                }
                ;
                else
                {
                    so2o = new Label()
                    {
                        FontSize = 15, Text = "непознато", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                };
                Label no2o;
                if (ordered[i].data.iaqi.no2 != null)
                {
                    no2o = new Label()
                    {
                        FontSize = 15, Text = ordered[i].data.iaqi.no2.v.ToString(), HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                }
                ;
                else
                {
                    no2o = new Label()
                    {
                        FontSize = 15, Text = "непознато", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                    }
                };

                Label pm10LABEL = new Label()
                {
                    FontSize = 8, Text = "PM10", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                };
                Label coLABEL = new Label()
                {
                    FontSize = 8, Text = "CO", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                };
                Label so2LABEL = new Label()
                {
                    FontSize = 8, Text = "SO2", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                };
                Label no2LABEL = new Label()
                {
                    FontSize = 8, Text = "NO2", HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White
                };


                grgr.Children.Add(name, 0, 0);
                Grid.SetColumnSpan(name, 3);
                grgr.Children.Add(AQI, 3, 0);
                grgr.Children.Add(pm10, 0, 1);
                grgr.Children.Add(coo, 1, 1);
                grgr.Children.Add(so2o, 2, 1);
                grgr.Children.Add(no2o, 3, 1);
                grgr.Children.Add(pm10LABEL, 0, 2);
                grgr.Children.Add(coLABEL, 1, 2);
                grgr.Children.Add(so2LABEL, 2, 2);
                grgr.Children.Add(no2LABEL, 3, 2);

                frfr.Content = grgr;
                Console.WriteLine(i.ToString());
                stek.Children.Add(frfr);

                CrossMTAdmob.Current.LoadInterstitial("ca-app-pub-6638560950207737/4239069970");
            }
        }
Ejemplo n.º 2
0
        private async void showAkcii()
        {
            stek.Children.Clear();
            if (k == 0)
            {
                Akcii akciiList = null;
                await Task.Run(async() =>
                {
                    akciiList = await AQIAPI.GetAkcii();
                });

                await Task.Run(async() =>
                {
                    cryresult = await GetCrypto.GetResult();
                });

                Label lbb = new Label()
                {
                    Text = "Сеуште не е отворена берзата\nПробајте повторно подоцна", HorizontalTextAlignment = TextAlignment.Center
                };
                if (akciiList.GetTickerJSONResult.Count == 0)
                {
                    stek.Children.Add(lbb);

                    Frame frfr1 = new Frame()
                    {
                        CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212")
                    };
                    Grid  grgr1  = new Grid();
                    Label kripto = new Label()
                    {
                        Text = "Криптовалути:", FontSize = 20, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#6cf58e"), HorizontalTextAlignment = TextAlignment.Start
                    };
                    grgr1.Children.Add(kripto, 0, 0);
                    Grid.SetColumnSpan(kripto, 2);

                    for (int i = 0; i < cryresult.Count; i++)
                    {
                        Label ime = new Label()
                        {
                            Text = cryresult[i].name, FontSize = 14, FontAttributes = FontAttributes.Bold, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Start
                        };
                        Label perCh = new Label()
                        {
                            Text = cryresult[i].price_change_percentage_24h.ToString() + "%", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center
                        };
                        Label cena = new Label()
                        {
                            Text = cryresult[i].current_price.ToString() + "€", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.End
                        };
                        if (cryresult[i].price_change_percentage_24h >= 0)
                        {
                            perCh.TextColor = Color.FromHex("#6cf58e");
                        }
                        else
                        {
                            perCh.TextColor = Color.FromHex("#FF7595");
                        }

                        grgr1.Children.Add(ime, 0, i + 1);
                        grgr1.Children.Add(perCh, 1, i + 1);
                        grgr1.Children.Add(cena, 2, i + 1);
                    }
                    frfr1.Content = grgr1;
                    stek.Children.Add(frfr1);
                    return;
                }


                ordered = akciiList.GetTickerJSONResult.OrderBy(f => f.AvgPerChange).ToList();
                all     = ordered;
            }
            ordered.Reverse();
            int forBrojac = 0;

            foreach (var akcija in ordered)
            {
                if (forBrojac == 2)
                {
                    Frame frfr1 = new Frame()
                    {
                        CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212")
                    };
                    Grid  grgr1  = new Grid();
                    Label kripto = new Label()
                    {
                        Text = "Криптовалути:", FontSize = 20, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#6cf58e"), HorizontalTextAlignment = TextAlignment.Start
                    };
                    grgr1.Children.Add(kripto, 0, 0);
                    Grid.SetColumnSpan(kripto, 2);

                    for (int i = 0; i < cryresult.Count; i++)
                    {
                        Label ime = new Label()
                        {
                            Text = cryresult[i].name, FontSize = 14, FontAttributes = FontAttributes.Bold, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Start
                        };
                        Label perCh = new Label()
                        {
                            Text = cryresult[i].price_change_percentage_24h.ToString() + "%", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center
                        };
                        Label cena = new Label()
                        {
                            Text = cryresult[i].current_price.ToString() + "€", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.End
                        };
                        if (cryresult[i].price_change_percentage_24h >= 0)
                        {
                            perCh.TextColor = Color.FromHex("#6cf58e");
                        }
                        else
                        {
                            perCh.TextColor = Color.FromHex("#FF7595");
                        }

                        grgr1.Children.Add(ime, 0, i + 1);
                        grgr1.Children.Add(perCh, 1, i + 1);
                        grgr1.Children.Add(cena, 2, i + 1);
                    }
                    frfr1.Content = grgr1;
                    stek.Children.Add(frfr1);
                }
                Frame frfr = new Frame()
                {
                    CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212")
                };
                Grid grgr = new Grid();

                grgr.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(2, GridUnitType.Star)
                });
                grgr.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });

                grgr.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(5, GridUnitType.Star)
                });
                grgr.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(3, GridUnitType.Star)
                });

                string titleText = String.Format("{0} ({1})", akcija.Description, akcija.Symbol);
                Label  title     = new Label()
                {
                    Text = titleText, FontSize = 15, FontAttributes = FontAttributes.Bold, TextColor = Color.White
                };
                Label priceNow = new Label()
                {
                    Text = akcija.AvgPrice.ToString() + " den.", FontSize = 15, FontAttributes = FontAttributes.Bold, TextColor = Color.White
                };


                string perChange = akcija.AvgPerChange.ToString() + "%";
                if (akcija.AvgPerChange > 0)
                {
                    perChange = "+" + akcija.AvgPerChange.ToString() + "%";
                }
                string absChange = akcija.AvgAbsChange.ToString() + " den.";
                if (akcija.AvgAbsChange > 0)
                {
                    absChange = "+" + akcija.AvgAbsChange.ToString() + " den.";
                }

                if (akcija.AvgPerChange > 0)
                {
                    priceNow.TextColor = Color.FromHex("#6cf58e");
                }
                else
                {
                    priceNow.TextColor = Color.FromHex("#FF7595");
                }

                Label percent = new Label()
                {
                    Text = perChange, FontSize = 13, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, TextColor = Color.White
                };
                Label abs = new Label()
                {
                    Text = absChange, FontSize = 13, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, TextColor = Color.White
                };

                grgr.Children.Add(title, 0, 0);
                grgr.Children.Add(priceNow, 0, 1);
                grgr.Children.Add(percent, 1, 0);
                grgr.Children.Add(abs, 1, 1);

                frfr.Content = grgr;
                stek.Children.Add(frfr);
                forBrojac++;
            }
            if (ordered.Count < 2)
            {
                Frame frfr1 = new Frame()
                {
                    CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212")
                };
                Grid  grgr1  = new Grid();
                Label kripto = new Label()
                {
                    Text = "Криптовалути:", FontSize = 20, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#6cf58e"), HorizontalTextAlignment = TextAlignment.Start
                };
                grgr1.Children.Add(kripto, 0, 0);
                Grid.SetColumnSpan(kripto, 2);

                for (int i = 0; i < cryresult.Count; i++)
                {
                    Label ime = new Label()
                    {
                        Text = cryresult[i].name, FontSize = 14, FontAttributes = FontAttributes.Bold, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Start
                    };
                    Label perCh = new Label()
                    {
                        Text = cryresult[i].price_change_percentage_24h.ToString() + "%", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center
                    };
                    Label cena = new Label()
                    {
                        Text = cryresult[i].current_price.ToString() + "€", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.End
                    };
                    if (cryresult[i].price_change_percentage_24h >= 0)
                    {
                        perCh.TextColor = Color.FromHex("#6cf58e");
                    }
                    else
                    {
                        perCh.TextColor = Color.FromHex("#FF7595");
                    }

                    grgr1.Children.Add(ime, 0, i + 1);
                    grgr1.Children.Add(perCh, 1, i + 1);
                    grgr1.Children.Add(cena, 2, i + 1);
                }
                frfr1.Content = grgr1;
                stek.Children.Add(frfr1);
            }
        }