public override async void ViewWillAppear (bool animated)
        {
            base.ViewWillAppear (animated);

            setInitialUiState();

            rokortService = new Rokort_Service ();

            // Possible TODO: Detect changes to the rower picker and update isTripStarted and UIstate

            setupPickerModels();

            this.rowerPicker.Select (rowerModel.GetRowForRowerId(rokortService.RowerId), 0, true);

            await updateUi();
        }
Ejemplo n.º 2
0
		protected override async void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			Window.RequestFeature (WindowFeatures.NoTitle);

			// Initialize data
			listRowerNames.Clear ();
			listRowerNames.Add (new KeyValuePair<String, String>("Jakob Roesgaard Færch", "1541"));
			listRowerNames.Add (new KeyValuePair<String, String>("Trine Roesgaard Færch", "1542"));

			listBoatIds.Clear ();
			listBoatIds.Add (new KeyValuePair<String, String>("ÅKS Brabrand - Ener", "090"));
			listBoatIds.Add (new KeyValuePair<String, String>("Gæstebåd", "080"));
			listBoatIds.Add (new KeyValuePair<String, String>("Ergometer", "500"));

			customArrayAdapterRowerNames = new CustomArrayAdapter (this, listRowerNames, Resource.Layout.SpinnerItem);
			customArrayAdapterBoatdIds = new CustomArrayAdapter (this, listBoatIds, Resource.Layout.SpinnerItem);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);
			startTripWrapperLayout = FindViewById<LinearLayout> (Resource.Id.start_trip_wrapper);
			stopTripWrapperLayout = FindViewById<LinearLayout> (Resource.Id.stop_trip_wrapper);
			distanceLabelTextView = FindViewById<TextView> (Resource.Id.textViewDistanceLabel);
			distanceLabelTextView.SetTextColor (secondaryTextColor);
			button = FindViewById<Button> (Resource.Id.myButton);
			editTextDistance = FindViewById<EditText> (Resource.Id.editTextDistance);
			editTextDistance.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
				if (editTextDistance.Text.ToString().Equals("")) {
					disableButton();
				} else {
					enableButton ();
				}
			};

			spinnerRowerNames = FindViewById<Spinner> (Resource.Id.spinnerRowerNames);
			spinnerRowerNames.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (spinnerRowerNames_ItemSelected);
			configureSpinner (spinnerRowerNames, customArrayAdapterRowerNames);

			spinnerBoats = FindViewById<Spinner> (Resource.Id.spinnerBoats);
			spinnerBoats.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (spinnerBoats_ItemSelected);
			configureSpinner (spinnerBoats, customArrayAdapterBoatdIds);

			rokortService = new Rokort_Service ();

			// TODO Check for slected user instead

			isTripStarted = await rokortService.hasOngoingTrip ();
			updateUi();

			button.Click += async delegate {
				disableButton ();
				button.Text = GetString (Resource.String.button_disabled_text);

				if (isTripStarted) {
					stopTripWrapperLayout.Visibility = ViewStates.Invisible;
					await rokortService.stopTrip(Convert.ToInt16(editTextDistance.Text));
					isTripStarted = false;
				} else {
					startTripWrapperLayout.Visibility = ViewStates.Invisible;
					rokortService.RowerId = selectedRowerId;
					await rokortService.startTrip (selectedBoatId);
					isTripStarted = true;
				}
				updateUi();
			};
		}