예제 #1
0
 public MedicActivity()
 {
     _userService      = new UserService();
     _medicsFetched    = new List <Medic>();
     _storageService   = new StorageService();
     _functionsService = new FirebaseFunctionsService(this, this);
 }
예제 #2
0
        /*async void EditorCompleted(object sender, EventArgs e)
         * {
         *  var text = ((Editor)sender).Text; // sender is cast to an Editor to enable reading the `Text` property of the view.
         *  Console.WriteLine("Doing something" + carousel.CurrentItem.ToString());
         *
         *  //Painful process to get the source of the photo on the carousel view.
         *  string pain = carousel.CurrentItem.ToString();
         *  int startIndex = pain.IndexOf("=") + 2;
         *  int endIndex = pain.IndexOf(", ");
         *  string photo_source = pain.Substring(startIndex, endIndex-startIndex);
         *
         *  //evil code, don't change anything in this if statement.
         *  if(photo_source.Substring(0,5)=="Uri: ")
         *      photo_source = "" + photo_source.Substring(5);
         *
         *  Console.Write("pain" + pain);
         *  Console.Write("photo_source" + photo_source);
         *  foreach (List<string> list in App.User.photoURIs)
         *  {
         *      if (photo_source == list[0])
         *      {
         *          list[2] = text;
         *          await FirebaseFunctionsService.PostPhoto(list[4], text, list[5]);
         *          Console.WriteLine(list[4] + "Description : " + text);
         *      }
         *  }
         *  disableBackButton = true;
         * }*/

        async void EditorCompleted2(object sender, EventArgs e)
        {
            var text = ((Editor)sender).Text; // sender is cast to an Editor to enable reading the `Text` property of the view.

            //Painful process to get the source of the photo on the carousel view.
            string pain         = carousel.CurrentItem.ToString();
            int    startIndex   = pain.IndexOf("=") + 2;
            int    endIndex     = pain.IndexOf(", ");
            string photo_source = pain.Substring(startIndex, endIndex - startIndex);

            //evil code, don't change anything in this if statement.
            if (photo_source.Substring(0, 5) == "Uri: ")
            {
                photo_source = "" + photo_source.Substring(5);
            }

            Console.Write("pain" + pain);
            Console.Write("photo_source" + photo_source);
            foreach (List <string> list in App.User.photoURIs)
            {
                if (photo_source == list[0])
                {
                    list[5] = text;
                    await FirebaseFunctionsService.PostPhoto(list[4], list[2], text);

                    Console.WriteLine(list[4] + "Description : " + text);
                }
            }
            disableBackButton = true;
        }
예제 #3
0
 public AnimalAppointments()
 {
     _storageService   = new StorageService();
     _userService      = new UserService();
     _consultType      = new AppointmentCategory();
     _functionsService = new FirebaseFunctionsService(this, this);
 }
예제 #4
0
 public AppointmentAdapter(Appointment[] appointments, Activity context, bool displayUpcomingAppoints)
 {
     _appointments            = appointments;
     _context                 = context;
     _displayUpcomingAppoints = displayUpcomingAppoints;
     _functionsService        = new FirebaseFunctionsService(context, context);
 }
        public TaskCompletePage(int a, int b, bool isRoutine, TaskItemModel _TaskItemModel, GRItemModel _GRItemModel)
        {
            InitializeComponent();
            firebaseFunctionsService = new FirebaseFunctionsService();

            GRItemModel    = _GRItemModel;
            TaskItemModel  = _TaskItemModel;
            this.a         = a;
            this.b         = b;
            this.isRoutine = isRoutine;
            pageModel      = new TaskCompletePageViewModel(this, a, b, isRoutine);
            BindingContext = pageModel;
            itemcount      = pageModel.count;
        }
        protected override async void OnAppearing()
        {
            if (Application.Current.Properties.ContainsKey("accessToken") &&
                Application.Current.Properties.ContainsKey("refreshToken") &&
                Application.Current.Properties.ContainsKey("user_id"))
            {
                App.LoadApplicationProperties();

                firestoreService         = new FirestoreService();
                firebaseFunctionsService = new FirebaseFunctionsService();

                await firestoreService.LoadUser();

                await GoogleService.LoadTodaysEvents();

                await Navigation.PushAsync(new GoalsRoutinesTemplate());
            }
        }
        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++;
            }
        }
예제 #8
0
        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++;
                }
            }
        }
예제 #9
0
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }

            if (e.IsAuthenticated)
            {
                loginButton.Opacity  = 0;
                loginButton.Clicked -= LoginClicked;
                // If the user is authenticated, request their basic user data from Google
                // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
                var request  = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
                var response = await request.GetResponseAsync();

                JObject userJson = null;
                if (response != null)
                {
                    // Deserialize the data and store it in the account store
                    // The users email address will be used to identify data in SimpleDB
                    string userJsonString = await response.GetResponseTextAsync();

                    userJson = JObject.Parse(userJsonString);
                }
                else
                {
                    loginButton.Opacity  = 1;
                    loginButton.Clicked += LoginClicked;
                }

                if (userJson != null)
                {
                    Console.WriteLine("HERE is the TOKEN------------------------------------------------");
                    Console.WriteLine(e.Account.Properties["access_token"]);
                    Console.WriteLine("HERE is the REFRESH TOKEN----------------------------------------");
                    Console.WriteLine(e.Account.Properties["refresh_token"]);
                    Console.WriteLine("----------------------------------------------------------------");

                    //Reset accessToken
                    accessToken  = e.Account.Properties["access_token"];
                    refreshToken = e.Account.Properties["refresh_token"];

                    App.User = new user();
                    firebaseFunctionsService = new FirebaseFunctionsService();

                    //Query for email in Users collection
                    App.User.email = userJson["email"].ToString();
                    App.User.id    = firebaseFunctionsService.FindUserDoc(App.User.email).Result;

                    if (App.User.id == "")
                    {
                        await DisplayAlert("Oops!", "Looks like your trusted advisor hasn't registered your account yet. Please ask for their assistance!", "OK");

                        loginButton.Opacity  = 1;
                        loginButton.Clicked += LoginClicked;
                        return;
                    }

                    firestoreService = new FirestoreService();

                    //Save to App.User AND Update Firebase with pertitnent info
                    var googleService = new GoogleService();
                    await googleService.SaveAccessTokenToFireBase(accessToken);

                    Console.WriteLine(refreshToken);
                    await googleService.SaveRefreshTokenToFireBase(refreshToken);

                    //Save Properies inside phone for auto login
                    Application.Current.Properties["accessToken"]  = accessToken;
                    Application.Current.Properties["refreshToken"] = refreshToken;
                    Application.Current.Properties["user_id"]      = App.User.id;

                    App.LoadApplicationProperties();

                    await googleService.RefreshToken();

                    //Navigate to the Daily Page after Login
                    await Navigation.PushAsync(new LoadingPage());
                }
            }
        }
예제 #10
0
        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());
            }
        }
        public StepsPageViewModel(StepsPage mainPage, int a, int b, bool isRoutine)
        {
            this.mainPage = mainPage;
            Items         = new ObservableCollection <ListViewItemModel>();
            var firestoreService = new FirestoreService();

            firebaseFunctionsService = new FirebaseFunctionsService();

            if (isRoutine)
            {
                TopImage = App.User.routines[a].tasks[b].photo;
                TopLabel = App.User.routines[a].tasks[b].title;
                TaskName = App.User.routines[a].title;
                ExpectedCompletionTime = "Expected to take " +
                                         ((int)App.User.routines[a].expectedCompletionTime.TotalMinutes).ToString()
                                         + " minutes";

                int stepIdx = 0;
                int stepNum = 1;

                Console.WriteLine("step count: " + App.User.routines[a].tasks[b].steps.Count);

                foreach (step step in App.User.routines[a].tasks[b].steps)
                {
                    string        _checkmarkIcon = "graycheckmarkicon.png";
                    Command <int> _completeStep  = new Command <int>((int _stepIdx) => { });;

                    if (App.User.routines[a].tasks[b].steps[stepIdx].isComplete)
                    {
                        _checkmarkIcon = "greencheckmarkicon.png";
                    }
                    else
                    {
                        if (App.User.routines[a].tasks[b].steps[stepIdx].isInProgress)
                        {
                            _checkmarkIcon = "yellowclockicon.png";
                        }

                        _completeStep = new Command <int>(
                            async(int _stepIdx) =>
                        {
                            var routineId             = App.User.routines[a].id;
                            var taskId                = App.User.routines[a].tasks[b].id;
                            string stepDbIdx          = App.User.routines[a].tasks[b].steps[_stepIdx].dbIdx.ToString();
                            bool isPrevStepInProgress =
                                (_stepIdx == 0) ? false : App.User.routines[a].tasks[b].steps[_stepIdx - 1].isInProgress;
                            bool isPrevStepComplete =
                                (_stepIdx == 0) ? true : App.User.routines[a].tasks[b].steps[_stepIdx - 1].isComplete;
                            bool isStepInProgress = App.User.routines[a].tasks[b].steps[_stepIdx].isInProgress;
                            bool isStepComplete   = App.User.routines[a].tasks[b].steps[_stepIdx].isComplete;
                            var indexForCheckmark = _stepIdx;


                            if (!isStepComplete)
                            {
                                if (isPrevStepInProgress)
                                {
                                    if (_stepIdx - 1 >= 0)
                                    {
                                        App.User.routines[a].tasks[b].steps[_stepIdx - 1].isInProgress = false;
                                        App.User.routines[a].tasks[b].steps[_stepIdx - 1].isComplete   = true;
                                        Items[_stepIdx - 1].CheckmarkIcon = "greencheckmarkicon.png";
                                        string prevStepDbIdx = App.User.routines[a].tasks[b].steps[_stepIdx - 1].dbIdx.ToString();


                                        firebaseFunctionsService.UpdateStep(routineId, taskId, prevStepDbIdx);
                                    }

                                    Items[_stepIdx].CheckmarkIcon = "yellowclockicon.png";
                                    App.User.routines[a].tasks[b].steps[indexForCheckmark].isInProgress = true;

                                    firebaseFunctionsService.StartIS(routineId, taskId, stepDbIdx);
                                }
                                else
                                {
                                    if (isPrevStepComplete)
                                    {
                                        if (isStepInProgress)
                                        {
                                            App.User.routines[a].tasks[b].steps[indexForCheckmark].isInProgress = false;
                                            App.User.routines[a].tasks[b].steps[indexForCheckmark].isComplete   = true;
                                            Items[_stepIdx].CheckmarkIcon = "greencheckmarkicon.png";

                                            firebaseFunctionsService.UpdateStep(routineId, taskId, stepDbIdx);
                                        }
                                        else
                                        {
                                            Items[_stepIdx].CheckmarkIcon = "yellowclockicon.png";
                                            App.User.routines[a].tasks[b].steps[indexForCheckmark].isInProgress = true;

                                            firebaseFunctionsService.StartIS(routineId, taskId, stepDbIdx);
                                        }
                                    }
                                    else
                                    {
                                        await Application.Current.MainPage.DisplayAlert("Oops!", "Please complete each step in order", "OK");
                                    }
                                }
                            }
                        }
                            );
                    }

                    Items.Add(new ListViewItemModel
                              (
                                  stepNum + ". " + App.User.routines[a].tasks[b].steps[stepIdx].title,
                                  _checkmarkIcon,
                                  stepIdx,
                                  _completeStep
                              ));

                    stepIdx++;
                    stepNum++;
                }
            }
        }