LondonBike.TripLog.StartNewTripItem C# (CSharp) Method

StartNewTripItem() public static method

public static StartNewTripItem ( ) : void
return void
        public static void StartNewTripItem()
        {
            currentTripLog = new TripLog ();
            currentTripLog.Ticks = DateTime.Now.Ticks;
            currentTripLog.TimeInSeconds = -1;
            currentTripLog.DistanceInMeters = -1;

            GetCurrentLocation (currentTripLog, true, delegate {

                Util.Log ("Found Start location");

            #if DEBUG
            #if FAKEDATA
                currentTripLog.StartLat = Locations.HydePark.Latitude;
                currentTripLog.StartLon = Locations.HydePark.Longitude;
            #endif
            #endif

                BikeLocation loc = BikeLocation.FindClosestBike (currentTripLog.StartLat, currentTripLog.StartLon);
                if (loc != null) {
                    if (loc.DistanceFromCurrentPoint > 500) {
                        currentTripLog.StartStation = "Unknown";

                    } else {
                        currentTripLog.StartStation = loc.Name;

                    }
                } else {
                    currentTripLog.StartStation = "Unknown";
                }

                Util.Log ("Station: " + currentTripLog.StartStation);

                NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

                defaults.SetString (currentTripLog.AsLine, "triplog_line");
                defaults.Synchronize ();

            });
        }

Usage Example

Beispiel #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            LoadTimerUserDefaults();

            if (Running)
            {
                StartButton.SetImage(Resources.StopButton, UIControlState.Normal);
                clockTimer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), UpdateTimerDisplay);
            }
            else
            {
                StartButton.SetImage(Resources.StartButton, UIControlState.Normal);
            }
            StartButton.TouchUpInside += delegate {
                if (Running)
                {
                    Running = false;

                    SetTimerUserDefaults();

                    TimeSpan elapsedTime = DateTime.Now - StartDate;

                    int totalSeconds = (int)Math.Truncate(elapsedTime.TotalSeconds);

                    TripLog.StopTripItem(totalSeconds);

                    ClearNotifications();

                    StartButton.SetImage(Resources.StartButton, UIControlState.Normal);
                    //StartButton.SetTitle("Start", UIControlState.Normal);
                    clockTimer.Invalidate();
                    clockTimer = null;

                    //CostLabel.Text = "£0.00";
                    //ElapsedLabel.Text = "0h 00m";
                    PriceIncreaseLabel.Text = "0m";
                    StartedLabel.Text       = "00:00";

                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_TIMER_STOP, "", 1);
                    Analytics.Dispatch();
                    //BackgroundLocationManager.Instance.StopLocationManager();
                }
                else
                {
                    StartDate = DateTime.Now;
                    Running   = true;

                    TripLog.StartNewTripItem();

                    SetNotification(StartDate.AddMinutes(30));


                    SetTimerUserDefaults();

                    StartButton.SetImage(Resources.StopButton, UIControlState.Normal);
                    //StartButton.SetTitle("Stop", UIControlState.Normal);
                    UpdateTimerDisplay();

                    clockTimer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), UpdateTimerDisplay);
                    //BackgroundLocationManager.Instance.StartLocationManager();


                    Analytics.TrackPageView("/timerstart");
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_TIMER_START, "", 1);
                    Analytics.Dispatch();
                }
            };
        }