/* * StartButtonClicked - Method that start, pauses and resumes a session. */ void StartButtonClicked(object sender, EventArgs args) { if (Start.Text.CompareTo("Start") == 0) { Session new_session = new Session(); DateTime toBeClonedDateTime = DateTime.Now; DateTime initial = toBeClonedDateTime; new_session.start = initial; new_session.end = null; new_session.project = selected_project.Id; new_session.taskId = selected_task.Id; int id = database.SaveSession(new_session); new_session.Id = id; current = new_session; Start.Text = "Pause"; getlocation = true; askLocation(); //Timer_Counter.Text = "Session is live"; accelometeractive = true; GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; RefreshTime(); } else if (Start.Text.CompareTo("Pause") == 0) { accelometeractive = false; GlobalUtilities.accelerometer.ReadingAvailable -= Accelerometer_ReadingAvailable; getlocation = false; Start.Text = "Resume"; if (database.GetliveInterrupt() is null) { interrupt = new Interrupts(); interrupt.reason = "User reason"; DateTime toBeClonedDateTime = DateTime.Now; interrupt.start = toBeClonedDateTime; interrupt.sessionId = current.Id; interrupt.Id = database.SaveInterrupt(interrupt); } Timer_Counter.Text = "Session is paused"; } else if (Start.Text.CompareTo("Resume") == 0) { Start.Text = "Pause"; interrupt = database.GetliveInterrupt(); DateTime toBeClonedDateTime = DateTime.Now; interrupt.end = toBeClonedDateTime; database.UpdateInterrupt(interrupt); getlocation = true; Timer_Counter.Text = "Session is live"; accelometeractive = true; GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; } }
/* * SessionLive - Initialize the Content view when a session is being resume. * @param databaseAccess - The database. */ public SessionLive(Database_Controller databaseAccess) { InitializeComponent(); RefreshTime(); database = databaseAccess; current = database.GetliveSession(); selected_project = database.GetOneProject(current.project); selected_task = database.GetOneTask(current.taskId); this.Task_Name.Text = selected_task.name; this.Project_Name.Text = selected_project.name; interrupt = database.GetliveInterrupt(); if (!Resolver.IsSet) { var container = new SimpleContainer(); container.Register <IAccelerometer, Accelerometer>(); Resolver.SetResolver(container.GetResolver()); } GlobalUtilities.accelerometer = Resolver.Resolve <IAccelerometer>(); GlobalUtilities.accelerometer.Interval = AccelerometerInterval.Normal; if (interrupt is null) { Start.Text = "Pause"; getlocation = true; askLocation(); accelometeractive = true; GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; } else { Start.Text = "Resume"; getlocation = false; askLocation(); } }
/* * OnAppearing - Get live session. */ protected override void OnAppearing() { live = database.GetliveSession(); if (live != null) { interrupt = database.GetliveInterrupt(); if (interrupt is null) { getlocation = true; askLocation(); accelometeractive = true; GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; } } }
/* * OnAppearing - Get live session, calculates the engage time and estimation time for the project. */ protected override void OnAppearing() { overlay.IsVisible = false; Tasks_List.IsVisible = true; View_Sessions.IsVisible = true; Delete_Project.IsVisible = true; tapped = null; live = database.GetliveSession(); Estimation_Time.Text = "Estimation: "; Engage_Time.Text = "Time spend: "; double auxEstimation = GetEstimation(selectedProject); double auxSpend = GetEngageTime(selectedProject); Estimation_Time.Text += TimeSpan.FromMinutes(Math.Round(auxEstimation, 3)).ToString(); Engage_Time.Text += TimeSpan.FromMinutes(Math.Round(auxSpend, 3)).ToString(); if (auxEstimation < auxSpend) { Engage_Time.BackgroundColor = Color.Red; } else { Engage_Time.BackgroundColor = Color.Green; } if (live != null) { Resume_Session.IsVisible = true; LiveSession = true; interrupt = database.GetliveInterrupt(); if (interrupt is null) { getlocation = true; askLocation(); accelometeractive = true; GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; } } else { Resume_Session.IsVisible = false; LiveSession = false; } }
/* * OnAppearing - Overrride to the screen appearing, refresh the project list, * gets the live session. */ protected override void OnAppearing() { user.projects = database.GetProjectUser(user.Id); list.Clear(); if (!Resolver.IsSet) { var container = new SimpleContainer(); container.Register <IAccelerometer, Accelerometer>(); Resolver.SetResolver(container.GetResolver()); } GlobalUtilities.accelerometer = Resolver.Resolve <IAccelerometer>(); GlobalUtilities.accelerometer.Interval = AccelerometerInterval.Normal; if (user.projects != null) { foreach (var ProjectTemp in user.projects) { ProjectTemp.tasks = database.GetTaskOfProjects(ProjectTemp.Id); list.Add(ProjectTemp); } } Proyects.ItemTemplate = new DataTemplate(typeof(Objects)); Proyects.ItemsSource = list; live = database.GetliveSession(); if (live != null) { Resume_Session.IsVisible = true; interrupt = database.GetliveInterrupt(); if (interrupt is null) { getlocation = true; askLocation(); accelometeractive = true; GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; } } else { Resume_Session.IsVisible = false; } }
/* * OnAppearing - Get live session, calculates the engage time for the session. */ protected override void OnAppearing() { overlayLocation.IsVisible = false; Interrupt_List.IsVisible = true; live = database.GetliveSession(); if (live != null) { Resume_Session.IsVisible = true; LiveSession = true; interrupt = database.GetliveInterrupt(); if (interrupt is null) { getlocation = true; askLocation(); accelometeractive = true; GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; } } else { Resume_Session.IsVisible = false; LiveSession = false; } Start_Time.Text = selectedSession.start.ToString(); End_Time.Text = selectedSession.end.ToString(); Task_Name.Text = "Task: " + database.GetOneTask(selectedSession.taskId).name; Time_Spend.Text = "Time Spend: "; List <Interrupts> interruptsList = database.GetInterruptsOfSession(selectedSession.Id); double lessTime = 0; foreach (var interrupt in interruptsList) { try { if (interrupt.end is null) { lessTime += 0; } else { lessTime += ((double)((TimeSpan)(interrupt.end - interrupt.start)).TotalMinutes); } } catch (Exception ex) { lessTime += 0; } } try { if (selectedSession.end is null) { } else { double aux = (double)(((TimeSpan)(selectedSession.end - selectedSession.start)).TotalMinutes); Time_Spend.Text += TimeSpan.FromMinutes((aux - lessTime)).ToString(); } } catch (Exception ex) { Time_Spend.Text += TimeSpan.FromMinutes(0); } }