public SummaryPage(UserData.Rootobject user, object item)
        {
            InitializeComponent();
            Title = "Summary";

            UserData.Uservaluta userValuta = (UserData.Uservaluta)item;

            lblShortName.Text = userValuta.Valuta.ShortName;
            lblTotal.Text     = (userValuta.Amount * userValuta.Valuta.CurrentPrice).ToString();
            lblAmount.Text    = (userValuta.Amount).ToString();
            lblPrice.Text     = (userValuta.PurchasePrice).ToString();
            lblCurrent.Text   = (userValuta.Valuta.CurrentPrice).ToString();

            double n     = userValuta.Amount * userValuta.Valuta.CurrentPrice;
            double o     = userValuta.Amount * userValuta.PurchasePrice;
            double upper = n - o;
            double lower = o;
            double left  = upper / lower;
            double end   = left * 100;

            lblPercentage.Text = $"{(Math.Round(end, 2)).ToString()}%";

            if (end < 0)
            {
                lblPercentage.TextColor = Color.Red;
            }
            else
            {
                lblPercentage.TextColor = Color.Green;
            }
        }
        protected async void LoginUser()
        {
            if (String.IsNullOrWhiteSpace(unEntry.Text) || String.IsNullOrWhiteSpace(pwEntry.Text))
            {
                lblError.Text      = "Password or username is empty.";
                lblError.IsVisible = true;
                return;
            }

            UserData.Rootobject loggedinUser = new UserData.Rootobject();

            try
            {
                loggedinUser = await FetchAndCheckUser(unEntry.Text, pwEntry.Text);
            }
            catch (ArgumentException ex)
            {
                lblError.Text      = ex.Message;
                lblError.IsVisible = true;
                return;
            }

            if (Application.Current.Properties.ContainsKey("userId"))
            {
                Application.Current.Properties.Remove("userId");
            }
            Application.Current.Properties["userId"] = loggedinUser.Id;

            StartPage startpage = new StartPage();

            startpage.Title = $"Valutas of {loggedinUser.Username}";
            await ReplaceRoot(startpage);
        }
示例#3
0
        public static async Task <UserData.Rootobject> GetSpecficUserAPIAsync(int userId)
        {
            string     api          = $"{baseUrl}users/{userId}";
            HttpClient httpClient   = new HttpClient();
            var        responseText = await httpClient.GetStringAsync(api);

            UserData.Rootobject data = JsonConvert.DeserializeObject <UserData.Rootobject>(responseText);
            return(data);
        }
示例#4
0
        private async Task <float> GetSumCrypto()
        {
            float sum = 0;

            UserData.Rootobject user = await Connector.GetSpecficUserAPIAsync((int)Application.Current.Properties["userId"]);

            foreach (UserData.Uservaluta userValuta in user.UserValutas)
            {
                sum += (userValuta.Amount * userValuta.Valuta.CurrentPrice);
            }

            return(sum);
        }
示例#5
0
        private async Task ValutaListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            UserData.Rootobject user = await Connector.GetSpecficUserAPIAsync(userId);

            UserData.Uservaluta userValuta = (UserData.Uservaluta)e.Item;
            var graphPage = new TabbedPage
            {
                Children =
                {
                    new SummaryPage(user, e.Item)

                    ,
                    new ContentPage {
                        Title   = "Candle",
                        Content = new PlotView
                        {
                            Model             = CreateCandlePlotModel(user, e.Item),
                            VerticalOptions   = LayoutOptions.Fill,
                            HorizontalOptions = LayoutOptions.Fill,
                        }
                    },
                    new ContentPage {
                        Title   = "Linear",
                        Content = new PlotView
                        {
                            Model             = CreatePlotModel(user, e.Item),
                            VerticalOptions   = LayoutOptions.Fill,
                            HorizontalOptions = LayoutOptions.Fill,
                        },
                    },
                    new ContentPage {
                        Title   = "Bar",
                        Content = new PlotView
                        {
                            Model             = CreateBarPlotModel(user, e.Item),
                            VerticalOptions   = LayoutOptions.Fill,
                            HorizontalOptions = LayoutOptions.Fill,
                        }
                    }
                },
                Title = $"{userValuta.Valuta.Name}"
            };

            await Navigation.PushAsync(graphPage);
        }
示例#6
0
        public PlotModel CreatePlotModel(UserData.Rootobject loggedinUser, object userValutaItem)
        {
            UserData.Uservaluta userValuta = (UserData.Uservaluta)userValutaItem;

            UserData.Rootobject userData = loggedinUser;
            var plotModel = new PlotModel();

            plotModel.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left
            });
            plotModel.Axes.Add(new DateTimeAxis
            {
                Position          = AxisPosition.Bottom,
                MinorIntervalType = DateTimeIntervalType.Hours,
                IntervalType      = DateTimeIntervalType.Hours,
                StringFormat      = "HH-dd"
            });

            var linearPlot = new LineSeries
            {
                MarkerType   = MarkerType.Circle,
                MarkerSize   = 4,
                MarkerStroke = OxyColors.White
            };

            foreach (UserData.Usergraph userGraph in userData.UserGraphs)
            {
                if (userGraph.Graph.Valuta.Id == userValuta.Valuta.Id)
                {
                    plotModel.Title = userGraph.Graph.Name;
                    foreach (UserData.Graphdata graphPoint in userGraph.Graph.graphData)
                    {
                        double dateTimeX = DateTimeAxis.ToDouble(UnixTimeStampToDateTime(graphPoint.TimeStamp));
                        linearPlot.Points.Add(new DataPoint(dateTimeX, graphPoint.Open));
                    }
                }
            }



            plotModel.Series.Add(linearPlot);

            return(plotModel);
        }
示例#7
0
        public App()
        {
            InitializeComponent();

            if (Application.Current.Properties.ContainsKey("userId") && (int)Application.Current.Properties["userId"] > 0)
            {
                UserData.Rootobject loggedinUser = Task.Run(() => Connector.GetSpecficUserAPIAsync((int)Application.Current.Properties["userId"])).Result;

                ContentPage page = new CryptoFrontEnd.StartPage();
                page.Title = $"Valutas of {loggedinUser.Username}";
                MainPage   = new NavigationPage(page);
            }
            else
            {
                ContentPage page = new CryptoFrontEnd.Login();
                page.Title = "Login";
                MainPage   = new NavigationPage(page);
            }
        }
示例#8
0
        private PlotModel CreateBarPlotModel(UserData.Rootobject user, object item)
        {
            UserData.Uservaluta userValuta = (UserData.Uservaluta)item;
            var model = new PlotModel();

            List <BarItem>  values     = new List <BarItem>();
            List <DateTime> timeStamps = new List <DateTime>();

            foreach (UserData.Usergraph userGraph in user.UserGraphs)
            {
                if (userGraph.Graph.Valuta.Id == userValuta.Valuta.Id)
                {
                    model.Title = userGraph.Graph.Name;
                    foreach (UserData.Graphdata dataPoint in userGraph.Graph.graphData)
                    {
                        values.Add(new BarItem {
                            Value = (dataPoint.Open)
                        });
                        timeStamps.Add(UnixTimeStampToDateTime(dataPoint.TimeStamp));
                    }
                }
            }

            model.Axes.Add(new CategoryAxis
            {
                Position    = AxisPosition.Left,
                Key         = "CurrencyAxis",
                ItemsSource = timeStamps
            });

            var barSeries = new BarSeries
            {
                ItemsSource    = values,
                LabelPlacement = LabelPlacement.Outside,
            };

            model.Series.Add(barSeries);
            return(model);
        }
示例#9
0
        private PlotModel CreateCandlePlotModel(UserData.Rootobject user, object item)
        {
            var model = new PlotModel();
            var s1    = new CandleStickSeries()
            {
                Color = OxyColors.Black,
            };

            UserData.Uservaluta userValuta = (UserData.Uservaluta)item;

            foreach (UserData.Usergraph userGraph in user.UserGraphs)
            {
                if (userGraph.Graph.Valuta.Id == userValuta.Valuta.Id)
                {
                    model.Title = userGraph.Graph.Name;
                    foreach (UserData.Graphdata graphPoint in userGraph.Graph.graphData)
                    {
                        s1.Items.Add(new HighLowItem(DateTimeAxis.ToDouble(UnixTimeStampToDateTime(graphPoint.TimeStamp)), graphPoint.High, graphPoint.Low, graphPoint.Open, graphPoint.Close));
                    }
                }
            }

            model.Series.Add(s1);
            model.Axes.Add(new LinearAxis()
            {
                MaximumPadding = 0.3, MinimumPadding = 0.3
            });
            model.Axes.Add(new DateTimeAxis
            {
                Position          = AxisPosition.Bottom,
                MinorIntervalType = DateTimeIntervalType.Hours,
                IntervalType      = DateTimeIntervalType.Hours,
                StringFormat      = "HH-dd"
            });

            return(model);
        }