private void PopulateEvent(EventsItems event_, StackLayout stackLayout) { Frame frame = new Frame { CornerRadius = 10, HasShadow = false, Padding = new Thickness(10, 10, 10, 10), Margin = new Thickness(0, 2, 0, 2), BackgroundColor = Color.Goldenrod }; StackLayout stackLayoutOuter = new StackLayout { Orientation = StackOrientation.Horizontal }; StackLayout stackLayoutInner = new StackLayout { HorizontalOptions = LayoutOptions.StartAndExpand, }; Label EventTimeLabel = new Label { Text = event_.Start.DateTime.ToString("h:mm tt") + " - " + event_.End.DateTime.ToString("h:mm tt"), FontSize = 10, TextColor = Color.White, VerticalOptions = LayoutOptions.Start, FontFamily = labelFont }; Label EventTitleLabel = new Label { Text = event_.EventName, FontSize = 20, VerticalOptions = LayoutOptions.StartAndExpand, FontFamily = labelFont }; Label expectedTimeLabel = new Label { Text = event_.EventName, FontSize = 10, TextColor = Color.DimGray, VerticalOptions = LayoutOptions.EndAndExpand, FontFamily = labelFont }; CachedImage image = new CachedImage() { Source = Xamarin.Forms.ImageSource.FromFile("eventIcon.jpg"), WidthRequest = 50, HeightRequest = 50, HorizontalOptions = LayoutOptions.End, Transformations = new List <ITransformation>() { new CircleTransformation(), }, }; stackLayoutInner.Children.Add(EventTimeLabel); stackLayoutInner.Children.Add(EventTitleLabel); stackLayoutInner.Children.Add(expectedTimeLabel); stackLayoutOuter.Children.Add(stackLayoutInner); stackLayoutOuter.Children.Add(image); frame.Content = stackLayoutOuter; stackLayout.Children.Add(frame); }
public GoalsRoutinesTemplateViewModel(GoalsRoutinesTemplate mainPage) { this.mainPage = mainPage; firebaseFunctionsService = new FirebaseFunctionsService(); setUpTime(); complete = new List <bool>(); Items = new ObservableCollection <GRItemModel>(); int itemCount = 0; int eventNum = 0; int routineNum = 0; int goalNum = 0; Items.Add(new GRItemModel( App.User.Me.pic, "About Me", Color.Default, Color.Black, new DateTime(1, 1, 1), "Tap to Learn More", App.User.Me.message_day, true ? .6 : 1, false, false, new Command <MyDayIndexes>( async(MyDayIndexes indexes) => { await mainPage.Navigation.PushAsync(new GreetingPage()); }), new MyDayIndexes(itemCount, eventNum, 0) )); itemCount++; eventNum++; List <object> list = new List <object>(); foreach (EventsItems calendarEvent in App.User.CalendarEvents) { list.Add(calendarEvent); } foreach (routine routine in App.User.routines) { list.Add(routine); } foreach (goal goal in App.User.goals) { list.Add(goal); } //insertion sort, sort events,routines,and goals by start time. for (int j = 0; j < list.Count; j++) { DateTime start; if (list[j].GetType().Name == "routine") { routine routine = (routine)list[j]; start = DateTime.Now.Date + routine.availableStartTime; } else if (list[j].GetType().Name == "goal") { goal goal = (goal)list[j]; start = DateTime.Now.Date + goal.availableStartTime; } else { EventsItems item = (EventsItems)list[j]; start = item.Start.DateTime.DateTime; } //int swap = 0; object temp = list[j]; object min = list[j]; int swap = j; for (int i = j + 1; i < list.Count; i++) { DateTime start2; if (list[i].GetType().Name == "routine") { routine routine2 = (routine)list[i]; start2 = DateTime.Now.Date + routine2.availableStartTime; } else if (list[i].GetType().Name == "goal") { goal goal2 = (goal)list[i]; start2 = DateTime.Now.Date + goal2.availableStartTime; } else { EventsItems item2 = (EventsItems)list[i]; start2 = item2.Start.DateTime.DateTime; } if (start.CompareTo(start2) > 0) { start = start2; min = list[i]; swap = i; } } list[swap] = temp; list[j] = min; } //generate items to card view. foreach (object obj in list) { if (obj.GetType().Name == "routine") { routine routine = (routine)obj; //calculate the sum duration for the routine from step level. if (routine.isSublistAvailable == true) { int sum_duration = 0; foreach (task task in routine.tasks) { if (task.isSublistAvailable == true) { int step_duration = 0; foreach (step step in task.steps) { step_duration += (int)step.expectedCompletionTime.TotalMinutes; } if (step_duration == 0) { sum_duration += (int)task.expectedCompletionTime.TotalMinutes; } else { sum_duration += step_duration; } } else { sum_duration += (int)task.expectedCompletionTime.TotalMinutes; } } // update the duration for routine if (sum_duration != 0) { routine.expectedCompletionTime = TimeSpan.FromMinutes(sum_duration); } } if (isInTimeRange(routine.availableStartTime, routine.availableEndTime)) { string buttonText = "Tap to Start"; if (routine.isInProgress) { buttonText = "Tap to Continue"; } else if (routine.isComplete) { buttonText = "Done"; } DateTime startTime = DateTime.Now.Date + routine.availableStartTime; complete.Add(false); Items.Add(new GRItemModel( routine.photo, routine.title, Color.Default, Color.Black, startTime, buttonText, "Expected to take " + routine.expectedCompletionTime.TotalMinutes + " minutes", (routine.isComplete || routine.isInProgress) ? .6 : 1, routine.isComplete, routine.isInProgress, new Command <MyDayIndexes>( async(MyDayIndexes indexes) => { string routineId = App.User.routines[indexes.RoutineIndex].id; string routineDbIdx = App.User.routines[indexes.RoutineIndex].dbIdx.ToString(); bool isRoutineInProgress = App.User.routines[indexes.RoutineIndex].isInProgress; bool isRoutineComplete = App.User.routines[indexes.RoutineIndex].isComplete; ((GRItemModel)Items[indexes.ItemsIndex]).GrImageOpactiy = .6; if (App.User.routines[indexes.RoutineIndex].isSublistAvailable) { if (!isRoutineComplete) { App.User.routines[indexes.RoutineIndex].isInProgress = true; ((GRItemModel)Items[indexes.ItemsIndex]).IsInProgress = true; ((GRItemModel)Items[indexes.ItemsIndex]).Text = "Tap to Continue"; firebaseFunctionsService.startGR(routineId, routineDbIdx); } await mainPage.Navigation.PushAsync(new TaskPage(indexes.RoutineIndex, true, (GRItemModel)Items[indexes.ItemsIndex])); } else { if (!isRoutineComplete) { if (isRoutineInProgress) { App.User.routines[indexes.RoutineIndex].isInProgress = false; App.User.routines[indexes.RoutineIndex].isComplete = true; ((GRItemModel)Items[indexes.ItemsIndex]).IsInProgress = false; ((GRItemModel)Items[indexes.ItemsIndex]).IsComplete = true; ((GRItemModel)Items[indexes.ItemsIndex]).Text = "Done"; firebaseFunctionsService.CompleteRoutine(routineId, routineDbIdx); } else { App.User.routines[indexes.RoutineIndex].isInProgress = true; ((GRItemModel)Items[indexes.ItemsIndex]).IsInProgress = true; ((GRItemModel)Items[indexes.ItemsIndex]).Text = "Tap to Continue"; firebaseFunctionsService.startGR(routineId, routineDbIdx); } } } }), new MyDayIndexes(itemCount, routineNum, 0) )); itemCount++; } routineNum++; } else if (obj.GetType().Name == "goal") { goal goal = (goal)obj; //calculate the sum duration for the goal from instruction level. if (goal.isSublistAvailable == true) { int goal_duration = 0; foreach (action action in goal.actions) { if (action.isSublistAvailable == true) { int instruction_duration = 0; foreach (instruction instruction in action.instructions) { instruction_duration += (int)instruction.expectedCompletionTime.TotalMinutes; } if (instruction_duration == 0) { goal_duration += (int)action.expectedCompletionTime.TotalMinutes; } else { goal_duration += instruction_duration; } } else { goal_duration += (int)action.expectedCompletionTime.TotalMinutes; } } // update the duration for goal if (goal_duration != 0) { goal.expectedCompletionTime = TimeSpan.FromMinutes(goal_duration); } } if (isInTimeRange(goal.availableStartTime, goal.availableEndTime)) { string buttonText = "Tap to Start"; if (goal.isInProgress) { buttonText = "Tap to Continue"; } else if (goal.isComplete) { buttonText = "Done"; } DateTime startTime = DateTime.Now.Date + goal.availableStartTime; complete.Add(false); Items.Add(new GRItemModel( goal.photo, goal.title, Color.FromHex("#272E32"), Color.White, startTime, buttonText, "Expected to take " + goal.expectedCompletionTime.TotalMinutes + " minutes", (goal.isComplete || goal.isInProgress) ? .6 : 1, goal.isComplete, goal.isInProgress, new Command <MyDayIndexes>( async(MyDayIndexes indexes) => { string goalId = App.User.goals[indexes.GoalIndex].id; string goalDbIdx = App.User.goals[indexes.GoalIndex].dbIdx.ToString(); bool isGoalInProgress = App.User.goals[indexes.GoalIndex].isInProgress; bool isGoalComplete = App.User.goals[indexes.GoalIndex].isComplete; ((GRItemModel)Items[indexes.ItemsIndex]).GrImageOpactiy = .6; if (App.User.goals[indexes.GoalIndex].isSublistAvailable) { if (!isGoalComplete) { App.User.goals[indexes.GoalIndex].isInProgress = true; ((GRItemModel)Items[indexes.ItemsIndex]).Text = "Tap to Continue"; ((GRItemModel)Items[indexes.ItemsIndex]).IsInProgress = true; firebaseFunctionsService.startGR(goalId, goalDbIdx); } await mainPage.Navigation.PushAsync(new TaskPage(indexes.GoalIndex, false, (GRItemModel)Items[indexes.ItemsIndex])); } else { if (!isGoalComplete) { if (isGoalInProgress) { App.User.goals[indexes.GoalIndex].isInProgress = false; App.User.goals[indexes.GoalIndex].isComplete = true; ((GRItemModel)Items[indexes.ItemsIndex]).IsInProgress = false; ((GRItemModel)Items[indexes.ItemsIndex]).IsComplete = true; ((GRItemModel)Items[indexes.ItemsIndex]).Text = "Done"; firebaseFunctionsService.CompleteRoutine(goalId, goalDbIdx); } else { App.User.goals[indexes.GoalIndex].isInProgress = true; ((GRItemModel)Items[indexes.ItemsIndex]).IsInProgress = true; ((GRItemModel)Items[indexes.ItemsIndex]).Text = "Tap to Continue"; firebaseFunctionsService.startGR(goalId, goalDbIdx); } } } }), new MyDayIndexes(itemCount, 0, goalNum) )); itemCount++; } goalNum++; } else { EventsItems calendarEvent = (EventsItems)obj; Items.Add(new GRItemModel( "eventIcon.jpg", calendarEvent.EventName, Color.Goldenrod, Color.Black, calendarEvent.Start.DateTime.DateTime, calendarEvent.Description, "Start Time: " + calendarEvent.Start.DateTime.TimeOfDay + "\n" + "End Time: " + calendarEvent.End.DateTime.TimeOfDay + "", true ? .6 : 1, false, true, new Command <MyDayIndexes>( async(MyDayIndexes indexes) => { }), new MyDayIndexes(itemCount, eventNum, 0) )); itemCount++; eventNum++; } } }