Esempio n. 1
0
        protected override async void OnResume()
        {
            base.OnResume();

            try
            {
                Car car = await HttpManager.HttpGet <Car>(String.Format(HttpManager.GetHostAddress() + "/cars/{0}", _carId));

                _brandDetail.Text      = car.Brand;
                _typeDetail.Text       = car.Type;
                _stateDetail.Text      = CarStateManager.ConvertCarStateFromDatabaseValue(car.State);
                _kilometersDetail.Text = String.Format("{0}km", car.Kilometers);
                _powerDetail.Text      = String.Format("{0}kW", car.Power);
                _torqueDetail.Text     = String.Format("{0}Nm", car.Torque);
                _priceDetail.Text      = String.Format("{0}€", car.Price);
                Bitmap bmp = null;

                await Task.Run(() => { bmp = BitmapDownloader.GetImageBitmapFromUrl(car.Picture); });

                _pictureZoom.SetImageBitmap(bmp);
            }
            catch (WebException e)
            {
                DialogProvider.ShowOkDialogWithoutAction(this, "Connection lost!", "Connection", (sender, args) => { Finish(); });
            }
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Detail);

            _carId = Intent.GetLongExtra(CarIdExtras, 0);

            _backButton       = FindViewById <Button>(Resource.Id.BackButton);
            _editButton       = FindViewById <Button>(Resource.Id.EditButton);
            _brandDetail      = FindViewById <TextView>(Resource.Id.BrandDetail);
            _typeDetail       = FindViewById <TextView>(Resource.Id.TypeDetail);
            _stateDetail      = FindViewById <TextView>(Resource.Id.StateDetail);
            _kilometersDetail = FindViewById <TextView>(Resource.Id.KilometersDetail);
            _powerDetail      = FindViewById <TextView>(Resource.Id.PowerDetail);
            _torqueDetail     = FindViewById <TextView>(Resource.Id.TorqueDetail);
            _pictureZoom      = FindViewById <ImageView>(Resource.Id.PictureZoom);
            _priceDetail      = FindViewById <TextView>(Resource.Id.PriceDetail);
            _buyButton        = FindViewById <Button>(Resource.Id.BuyButton);

            _backButton.Click += (sender, args) =>
            {
                Finish();
            };

            _editButton.Click += (sender, args) =>
            {
                EditActivity.StartActivity(this, _carId);
            };

            _pictureZoom.Click += (sender, args) =>
            {
                ZoomActivity.StartActivity(this, _carId);
            };

            _buyButton.Click += async(sender, args) =>
            {
                try
                {
                    await HttpManager.HttpDelete(HttpManager.GetHostAddress() + "/cars/" + _carId);

                    DialogProvider.ShowOkDialogWithoutAction(this, "You buy this car. Thanks for your purchase!", "Congratulation!", (o, eventArgs) => { Finish(); });
                }
                catch (WebException e)
                {
                    DialogProvider.ShowOkDialogWithoutAction(this, "Connection lost!", "Connection", null);
                }
            };
        }
Esempio n. 3
0
        protected override async void OnResume()
        {
            base.OnResume();

            try
            {
                Car car = await HttpManager.HttpGet <Car>(String.Format(HttpManager.GetHostAddress() + "/cars/{0}", _carId));

                Bitmap bmp = null;

                await Task.Run(() => { bmp = BitmapDownloader.GetImageBitmapFromUrl(car.Picture); });

                _picture.SetImageBitmap(bmp);
            }
            catch (WebException e)
            {
                DialogProvider.ShowOkDialogWithoutAction(this, "Connection lost!", "Connection", (sender, args) => { Finish(); });
            }
        }
Esempio n. 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.LoginScreen);

            _username    = FindViewById <EditText>(Resource.Id.Username);
            _password    = FindViewById <EditText>(Resource.Id.Password);
            _loginButton = FindViewById <Button>(Resource.Id.LoginButton);

            _loginButton.Click += (sender, args) =>
            {
                if (_username.Text == "FerkoUzasny" && _password.Text == "FerkoUzasny")
                {
                    StartActivity(typeof(ListActivity));
                }
                else
                {
                    DialogProvider.ShowOkDialogWithoutAction(this, "Username or password is incorrect!", "Error", null);
                }
            };
        }
Esempio n. 5
0
        private async Task RefreshList(bool showPopup = true)
        {
            try
            {
                IEnumerable <Car> cars =
                    await HttpManager.HttpGet <IEnumerable <Car> >(HttpManager.GetHostAddress() + "/cars");

                CarAdapter adapter = new CarAdapter();
                _carList         = FindViewById <ListView>(Resource.Id.CarList);
                _carList.Adapter = adapter;
                adapter.AddItems(cars);
                adapter.NotifyDataSetChanged();
            }
            catch (WebException e)
            {
                if (showPopup)
                {
                    DialogProvider.ShowOkDialogWithoutAction(this, "Connection lost!", "Connection", null);
                }

                await Task.Run(() => { Thread.Sleep(1000); });
                await RefreshList(false);
            }
        }
Esempio n. 6
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Edit);
            Car car = null;

            try
            {
                car = await HttpManager.HttpGet <Car>(String.Format(HttpManager.GetHostAddress() + "/cars/{0}", Intent.GetLongExtra(CarIdExtras, 0)));
            }
            catch (WebException e)
            {
                DialogProvider.ShowOkDialogWithoutAction(this, "Connection lost!", "Connection", (sender, args) => { Finish(); });
                return;
            }



            _backButton     = FindViewById <Button>(Resource.Id.BackButton);
            _brandEdit      = FindViewById <EditText>(Resource.Id.BrandEdit);
            _typeEdit       = FindViewById <EditText>(Resource.Id.TypeEdit);
            _stateEdit      = FindViewById <Spinner>(Resource.Id.StateEdit);
            _kilometersEdit = FindViewById <EditText>(Resource.Id.KilometersEdit);
            _powerEdit      = FindViewById <EditText>(Resource.Id.PowerEdit);
            _torqueEdit     = FindViewById <EditText>(Resource.Id.TorqueEdit);
            _priceEdit      = FindViewById <EditText>(Resource.Id.PriceEdit);
            _editButton     = FindViewById <Button>(Resource.Id.EditButton);

            _pictureLoadButton = FindViewById <Button>(Resource.Id.PictureLoadButton);
            _imageUrlEditText  = FindViewById <EditText>(Resource.Id.PictureUrlEditText);
            _loadedPicture     = FindViewById <ImageView>(Resource.Id.LoadedPictureImageView);

            _brandEdit.Text        = car.Brand;
            _typeEdit.Text         = car.Type;
            _kilometersEdit.Text   = car.Kilometers.ToString();
            _powerEdit.Text        = car.Power.ToString();
            _torqueEdit.Text       = car.Torque.ToString();
            _priceEdit.Text        = car.Price.ToString();
            _imageUrlEditText.Text = car.Picture;


            Bitmap curentBmp = null;

            await Task.Run(() => { curentBmp = BitmapDownloader.GetImageBitmapFromUrl(_imageUrlEditText.Text); });

            _loadedPicture.SetImageBitmap(curentBmp);


            ArrayAdapter <string> adapter = new ArrayAdapter <string>(this,
                                                                      Android.Resource.Layout.SimpleSpinnerItem, CarStateManager.GetItems());

            _stateEdit.Adapter = adapter;

            _stateEdit.SetSelection(CarStateManager.GetItemPossition(car.State));

            _backButton.Click += (sender, args) =>
            {
                Finish();
            };

            _pictureLoadButton.Click += async(sender, args) =>
            {
                _imageUrlEditText.Enabled = false;
                _loadedPicture.Enabled    = false;
                _loadedPicture.SetImageBitmap(null);
                Bitmap bmp = null;

                await Task.Run(() => { bmp = BitmapDownloader.GetImageBitmapFromUrl(_imageUrlEditText.Text); });

                _loadedPicture.SetImageBitmap(bmp);
                _imageUrl = _imageUrlEditText.Text;
                _imageUrlEditText.Enabled = true;
                _loadedPicture.Enabled    = true;
            };

            _editButton.Click += async(sender, args) =>
            {
                if (int.TryParse(_kilometersEdit.Text, out int kilometers) &&
                    int.TryParse(_powerEdit.Text, out int power) &&
                    int.TryParse(_torqueEdit.Text, out int torque) &&
                    float.TryParse(_priceEdit.Text, out float price))
                {
                    Car editCar = new Car();
                    editCar.Brand      = _brandEdit.Text;
                    editCar.Type       = _typeEdit.Text;
                    editCar.State      = CarStateManager.ConvertCarStateToDatabaseValue(_stateEdit.SelectedItem.ToString());
                    editCar.Kilometers = kilometers;
                    editCar.Power      = power;
                    editCar.Torque     = torque;
                    editCar.Price      = price;
                    editCar.Picture    = _imageUrl;
                    try
                    {
                        await HttpManager.HttpPut(editCar, HttpManager.GetHostAddress() + "/cars/" + car.Id);

                        Finish();
                    }
                    catch (WebException e)
                    {
                        DialogProvider.ShowOkDialogWithoutAction(this, "Connection lost!", "Connection", null);
                    }
                }
                else
                {
                    DialogProvider.ShowOkDialogWithoutAction(this, "Some informations are not correct", "Error", null);
                }
            };
        }
Esempio n. 7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Add);

            _backButton       = FindViewById <Button>(Resource.Id.BackButton);
            _brandAdd         = FindViewById <EditText>(Resource.Id.BrandAdd);
            _typeAdd          = FindViewById <EditText>(Resource.Id.TypeAdd);
            _stateAdd         = FindViewById <Spinner>(Resource.Id.StateAdd);
            _kilometersAdd    = FindViewById <EditText>(Resource.Id.KilometersAdd);
            _powerAdd         = FindViewById <EditText>(Resource.Id.PowerAdd);
            _torqueAdd        = FindViewById <EditText>(Resource.Id.TorqueAdd);
            _priceAdd         = FindViewById <EditText>(Resource.Id.PriceAdd);
            _sellButton       = FindViewById <Button>(Resource.Id.SellButton);
            _imageUrlEditText = FindViewById <EditText>(Resource.Id.PictureUrlEditText);

            ArrayAdapter <string> adapter = new ArrayAdapter <string>(this,
                                                                      Android.Resource.Layout.SimpleSpinnerItem, CarStateManager.GetItems());

            _stateAdd.Adapter = adapter;

            _pictureLoadButton = FindViewById <Button>(Resource.Id.PictureLoadButton);
            _loadedPicture     = FindViewById <ImageView>(Resource.Id.LoadedPictureImageView);

            _backButton.Click += (sender, args) =>
            {
                Finish();
            };

            _pictureLoadButton.Click += async(sender, args) =>
            {
                _imageUrlEditText.Enabled = false;
                _loadedPicture.Enabled    = false;
                _imageUrl = "";
                _loadedPicture.SetImageBitmap(null);
                Bitmap bmp = null;

                await Task.Run(() => { bmp = BitmapDownloader.GetImageBitmapFromUrl(_imageUrlEditText.Text); });

                _loadedPicture.SetImageBitmap(bmp);
                _imageUrl = _imageUrlEditText.Text;
                _imageUrlEditText.Enabled = true;
                _loadedPicture.Enabled    = true;
            };

            _sellButton.Click += async(sender, args) =>
            {
                bool a, b, c;
                a = int.TryParse(_kilometersAdd.Text, out int kilometerss);
                b = int.TryParse(_powerAdd.Text, out int powesr);


                if (int.TryParse(_kilometersAdd.Text, out int kilometers) && int.TryParse(_powerAdd.Text, out int power) && int.TryParse(_torqueAdd.Text, out int torque) && float.TryParse(_priceAdd.Text, out float price))
                {
                    Car newCar = new Car();
                    newCar.Brand      = _brandAdd.Text;
                    newCar.Type       = _typeAdd.Text;
                    newCar.State      = CarStateManager.ConvertCarStateToDatabaseValue(_stateAdd.SelectedItem.ToString());
                    newCar.Kilometers = kilometers;
                    newCar.Power      = power;
                    newCar.Torque     = torque;
                    newCar.Price      = price;
                    newCar.Picture    = _imageUrl;
                    try
                    {
                        await HttpManager.HttpPost(newCar, HttpManager.GetHostAddress() + "/cars");

                        DialogProvider.ShowOkDialogWithoutAction(this, "You sell your car to our bazar!", "Congratulation!", (o, eventArgs) => { Finish(); });
                    }
                    catch (WebException e)
                    {
                        DialogProvider.ShowOkDialogWithoutAction(this, "Connection lost!", "Connection", null);
                    }
                }
                else
                {
                    DialogProvider.ShowOkDialogWithoutAction(this, "Some informations are not correct", "Error", null);
                }
            };
        }