public GoalsRoutinesTemplateViewModel(GoalsRoutinesTemplate mainPage) { this.mainPage = mainPage; firebaseFunctionsService = new FirebaseFunctionsService(); setUpTime(); complete = new List <bool>(); Items = new ObservableCollection <object>(); AboutMeCommand = new Command( async() => { await mainPage.Navigation.PushAsync(new GreetingPage()); }); Items.Add(new { Source = App.User.Me.pic, Title = "About Me", Ind = _imageCount++, BackgroundColor = Color.Default, TextColor = Color.Black, Length = App.User.Me.message_day, Text = "Tap to Learn More", IsComplete = false, IsInProgress = false, Navigate = AboutMeCommand }); int itemCount = 1; int routineNum = 0; foreach (routine routine in App.User.routines) { //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"; } complete.Add(false); Items.Add(new GRItemModel( routine.photo, routine.title, Color.Default, Color.Black, 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; Console.WriteLine("indexes.ItemsIndex: " + indexes.ItemsIndex); Console.WriteLine("indexes.RoutineIndex: " + indexes.RoutineIndex); ((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++; } int goalNum = 0; foreach (goal goal in App.User.goals) { //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"; } complete.Add(false); Items.Add(new GRItemModel( goal.photo, goal.title, Color.FromHex("#272E32"), Color.White, 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; Console.WriteLine("indexes.ItemsIndex: " + indexes.ItemsIndex); Console.WriteLine("indexes.GoalIndex: " + indexes.GoalIndex); ((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++; } }
private void PopulateRoutine(routine routine, int routineIdx, StackLayout stackLayout) { int stackLayoutIdx = stackLayout.Children.Count; StackLayout itemStackLayout = new StackLayout() { Orientation = StackOrientation.Horizontal }; Frame frame = new Frame { CornerRadius = 10, HasShadow = false, HorizontalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(10, 10, 10, 10), Margin = new Thickness(0, 2, 0, 2) }; StackLayout stackLayoutOuter = new StackLayout { Orientation = StackOrientation.Horizontal }; StackLayout stackLayoutInner = new StackLayout { HorizontalOptions = LayoutOptions.StartAndExpand, }; Label routineTitleLabel = new Label { Text = routine.title, FontSize = 20, VerticalOptions = LayoutOptions.Start, FontFamily = labelFont }; Label startTimeLabel = new Label { Text = "Starts at " + DateTime.ParseExact(routine.availableStartTime.ToString(), "HH:mm:ss", null).ToString("hh:mm tt", CultureInfo.GetCultureInfo("en-US")), FontSize = 10, TextColor = Color.DimGray, VerticalOptions = LayoutOptions.EndAndExpand, FontFamily = labelFont }; Label expectedTimeLabel = new Label { Text = "Expected to take " + routine.expectedCompletionTime.TotalMinutes.ToString() + " minutes", FontSize = 10, TextColor = Color.DimGray, VerticalOptions = LayoutOptions.StartAndExpand, FontFamily = labelFont }; CachedImage image = new CachedImage() { Source = routine.photo, WidthRequest = 50, HeightRequest = 50, HorizontalOptions = LayoutOptions.End, Transformations = new List <ITransformation>() { new CircleTransformation(), }, }; var indicator = new ActivityIndicator { Color = Color.Gray, }; indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsLoading"); indicator.BindingContext = image; stackLayoutInner.Children.Add(routineTitleLabel); stackLayoutInner.Children.Add(startTimeLabel); stackLayoutInner.Children.Add(expectedTimeLabel); stackLayoutOuter.Children.Add(stackLayoutInner); stackLayoutOuter.Children.Add(image); frame.Content = stackLayoutOuter; CachedImage checkmarkImage = new CachedImage() { Source = "", WidthRequest = 0, HeightRequest = 0, IsVisible = false, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.CenterAndExpand }; if (routine.isComplete || routine.isInProgress) { checkmarkImage.IsVisible = true; if (routine.isInProgress) { checkmarkImage.Source = "yellowclockicon.png "; } else { if (routine.isComplete) { checkmarkImage.Source = "greencheckmarkicon.png"; } } checkmarkImage.WidthRequest = 30; checkmarkImage.HeightRequest = 30; } itemStackLayout.Children.Add(checkmarkImage); itemStackLayout.Children.Add(frame); stackLayout.Children.Add(itemStackLayout); var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += async(s, e) => { StackLayout updatedStackLayout = (StackLayout)s; updatedStackLayout.Children[0].WidthRequest = 30; updatedStackLayout.Children[0].HeightRequest = 30; ((CachedImage)updatedStackLayout.Children[0]).IsVisible = true; if (routine.isSublistAvailable) { if (!routine.isInProgress) { ((CachedImage)updatedStackLayout.Children[0]).Source = "yellowclockicon.png"; routine.isInProgress = true; firebaseFunctionsService.startGR(routine.id.ToString(), routine.dbIdx.ToString()); App.ListPageScrollPosY = mainScrollView.ScrollY; } await Navigation.PushAsync(new TaskPage(routineIdx, true)); } else { if (!routine.isComplete) { if (routine.isInProgress) { ((CachedImage)updatedStackLayout.Children[0]).Source = "greencheckmarkicon.png"; routine.isInProgress = false; routine.isComplete = true; firebaseFunctionsService.CompleteRoutine(routine.id.ToString(), routine.dbIdx.ToString()); } else { ((CachedImage)updatedStackLayout.Children[0]).Source = "yellowclockicon.png"; routine.isInProgress = true; firebaseFunctionsService.startGR(routine.id.ToString(), routine.dbIdx.ToString()); } } } }; stackLayout.Children[stackLayoutIdx].GestureRecognizers.Add(tapGestureRecognizer); }
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++; } } }
public async void nextpage(object sender, EventArgs args) { var completeActionCounter = 0; var goalId = App.User.goals[a].id; var actionId = App.User.goals[a].actions[b].id; if (next.Text == "Done") { var firestoreService = new FirestoreService(); firebaseFunctionsService.UpdateTask(goalId, actionId, App.User.goals[a].actions[b].dbIdx.ToString()); // Set data model completion status App.User.goals[a].actions[b].isComplete = true; App.User.goals[a].actions[b].isInProgress = false; TaskItemModel.IsComplete = true; TaskItemModel.IsInProgress = false; App.User.goals[a].actions[b].dateTimeCompleted = DateTime.Now; foreach (action action in App.User.goals[a].actions) { if (action.isComplete) { completeActionCounter++; } } if (completeActionCounter == App.User.goals[a].actions.Count) { firebaseFunctionsService.CompleteRoutine(goalId, App.User.goals[a].dbIdx.ToString()); // Set data model completion status App.User.goals[a].isComplete = true; App.User.goals[a].isInProgress = false; if (App.ParentPage != "ListView") { GRItemModel.IsComplete = true; GRItemModel.IsInProgress = false; GRItemModel.Text = "Done"; } App.User.goals[a].dateTimeCompleted = DateTime.Now; } await Navigation.PopAsync(); } else if (next.Text == "Start") { int idx = 0; while (App.User.goals[a].actions[b].instructions[idx].isComplete) { idx++; Console.WriteLine("instruction complete idx: " + idx); } //App.user.goals[a].actions[b].instructions[0].isComplete = true; next.Text = "Next"; CarouselTasks.Position = idx; Console.WriteLine("CarouselTasks.Position: " + CarouselTasks.Position); await Task.Delay(2000); } else if (CarouselTasks.Position != App.User.goals[a].actions[b].instructions.Count - 1) { /*var firestoreService = new FirestoreService(App.User.id); * var goalId = App.user.goals[a].id; * var actionId = App.user.goals[a].actions[b].id; * var isInstructionComplete = await firestoreService.UpdateInstruction(goalId, actionId, App.user.goals[a].actions[b].instructions[CarouselTasks.Position].dbIdx.ToString()); * if (isInstructionComplete) * { * App.user.goals[a].actions[b].instructions[CarouselTasks.Position].isComplete = true; * App.user.goals[a].actions[b].instructions[CarouselTasks.Position].dateTimeCompleted = DateTime.Now; * }*/ App.User.goals[a].actions[b].instructions[CarouselTasks.Position].isComplete = true; pageModel.Items[CarouselTasks.Position].OkToCheckmark = true; firebaseFunctionsService.UpdateInstruction(goalId, actionId, App.User.goals[a].actions[b].instructions[CarouselTasks.Position].dbIdx.ToString()); CarouselTasks.Position = CarouselTasks.Position + 1; } else if (CarouselTasks.Position == App.User.goals[a].actions[b].instructions.Count - 1) { App.User.goals[a].actions[b].instructions[CarouselTasks.Position].isComplete = true; pageModel.Items[CarouselTasks.Position].OkToCheckmark = true; firebaseFunctionsService.UpdateInstruction(goalId, actionId, App.User.goals[a].actions[b].instructions[CarouselTasks.Position].dbIdx.ToString()); next.Text = "Done"; } else if (CarouselTasks.Position != App.User.goals[a].actions[b].instructions.Count - 1) { App.User.goals[a].actions[b].instructions[CarouselTasks.Position].isComplete = true; pageModel.Items[CarouselTasks.Position].OkToCheckmark = true; firebaseFunctionsService.UpdateInstruction(goalId, actionId, App.User.goals[a].actions[b].instructions[CarouselTasks.Position].dbIdx.ToString()); next.Text = "Done"; } }
public async void DoneClicked(object sender, EventArgs args) { DoneButton.IsEnabled = false; var completeCounter = 0; var completeTasksCounter = 0; foreach (step step in App.User.routines[a].tasks[b].steps) { if (step.isComplete) { completeCounter++; } } if (completeCounter == App.User.routines[a].tasks[b].steps.Count) { DoneButton.IsEnabled = false; var routineId = App.User.routines[a].id; var taskId = App.User.routines[a].tasks[b].id; firebaseFunctionsService = new FirebaseFunctionsService(); taskItemModel.IsComplete = true; taskItemModel.IsInProgress = false; App.User.routines[a].tasks[b].isComplete = true; App.User.routines[a].tasks[b].isInProgress = false; App.User.routines[a].tasks[b].dateTimeCompleted = DateTime.Now; //TaskPage.pageModel.Items[b].IsComplete = true; firebaseFunctionsService.UpdateTask(routineId, taskId, App.User.routines[a].tasks[b].dbIdx.ToString()); await Navigation.PopAsync(); } else { DoneButton.IsEnabled = true; await DisplayAlert("Oops!", "Please complete all steps before marking this task as done", "OK"); } foreach (task task in App.User.routines[a].tasks) { if (task.isComplete) { completeTasksCounter++; } } if (completeTasksCounter == App.User.routines[a].tasks.Count) { var routineId = App.User.routines[a].id; App.User.routines[a].isComplete = true; App.User.routines[a].isInProgress = false; App.User.routines[a].dateTimeCompleted = DateTime.Now; if (App.ParentPage != "ListView") { GRItemModel.IsComplete = true; GRItemModel.IsInProgress = false; GRItemModel.Text = "Done"; } var firebaseFunctionsService = new FirebaseFunctionsService(); var okToCheckmark = await firebaseFunctionsService.CompleteRoutine(routineId, App.User.routines[a].dbIdx.ToString()); } }