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); } }; }
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); } }; }