示例#1
0
 /*
  * Constructor for Edit Task which encapsulates TierUpdatecs, List<TimerUpdatecs>, User and the Label.
  * Param
  * time: Parse the current timer statistics
  * listtime: Parse a list of all timerUpdatecs timers
  * user: the user parsed
  * label: the label id parsed
  * Returns Nothing
  */
 public EditTaskView(TimerUpdatecs time, List <TimerUpdatecs> listtimes, UserModel user, Label label, StackLayout inner, StackLayout outer)
 {
     Deleted         = false;
     this.label      = label;
     this.user       = user;
     this.timeStats  = time;
     this.ListTimers = listtimes;
     this.timerlads  = inner;
     this.outer      = outer;
     InitializeComponent();
 }
示例#2
0
        /*
         * This method is responsible for displaying the finish button and updating the
         * current timer file with new timer information and removing the current element from the ListTimer
         *
         * PARAM
         * timerlads: the stacklayout that is to be updated with the finish button
         * times: the current TimerUpdatecs to be removed from the ListTimer list
         *
         * RETURN Nothing
         */
        public void DisplayFinishButton(StackLayout timerlads, TimerUpdatecs times, StackLayout buttons)
        {
            var finishButton = new Button
            {
                Text            = "Finish",
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HeightRequest   = 40,
                BackgroundColor = Color.FromHex("#00CC33"),
                TextColor       = Color.White,
                FontSize        = 12,
                WidthRequest    = 80,
                CornerRadius    = 16,
            };

            finishButton.Clicked += async(s, a) =>
            {
                await Task.Run(async() =>
                {
                    Animations.CloseStackLayout(timerlads, "Timer", 30, 500);
                });

                UserModel.Rewrite("Updated:", DateTime.Now.ToString(), Currentuser.LocalLogin);
                try
                {
                    Currentuser.UserLogin.Object.Updated = DateTime.Now.ToString();
                    await Currentuser.RewriteDATA();
                }
                catch { }
                timers.Children.Remove(timerlads);
                ListTimer.Remove(times);
                await Currentuser.UpdateCurrenttimesAsync(ListTimer);

                await items.GiveKeyAsync(1);

                await this.DisplayAlert("Congratulations", "You finished a task!\n\nHere's a key", "Receive");
            };

            buttons.Children.Clear();
            buttons.Children.Add(finishButton);
            timerlads.Children.Add(buttons);
            timers.Children.Add(timerlads);
        }
示例#3
0
        /*
         * This method is responsible for creating timers based on DateTime and TimeSpan
         * information which is parse from the DatePicker page
         *
         * PARAM
         * Task: A string which contains the title of the task
         * Trg: The end date of the task
         * Rem: The leftover time remaining
         *
         * RETURN Nothing
         */
        public void Timer(string Original, DateTime Trg, TimeSpan Rem)
        {
            string TaskName  = Original;
            bool   TimerStop = false;
            var    rand      = new Random();

            // Initialize Stacklayout and its properties
            var timerlads = new StackLayout
            {
                Orientation          = StackOrientation.Horizontal,
                BackgroundColor      = Color.White,
                MinimumHeightRequest = 38,
                Margin = new Thickness(0, 0, 6, 0)
            };

            var buttons = new StackLayout
            {
                HorizontalOptions = LayoutOptions.Start,
            };

            var colorTag = new Label
            {
                Text = "",
                HorizontalOptions = LayoutOptions.Start,
                WidthRequest      = 8,
            };

            var taskName = new Label
            {
                Text          = TaskName,
                Margin        = new Thickness(8, 14),
                TextColor     = Color.FromHex("#212121"),
                LineBreakMode = LineBreakMode.WordWrap,
            };

            var editButton = new Button
            {
                Text              = "Edit",
                FontSize          = 10,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                BackgroundColor   = Color.White,
                WidthRequest      = 45
            };

            var countdownFinish = new Button
            {
                IsEnabled       = false,
                BackgroundColor = Color.FromHex("#00CC33"),
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HeightRequest   = 40,
                FontSize        = 12,
                WidthRequest    = 80,
                CornerRadius    = 16,
            };

            // Initialize labels and TimerUpdatecs object
            TimerUpdatecs time = new TimerUpdatecs(Trg, Rem, TaskName);

            time.R = time.T - DateTime.Now;

            // If the current time is overdue then time remainging is 00:00:00
            if (DateTime.Now >= time.T)
            {
                time.R = DateTime.Now - DateTime.Now;
            }

            countdownFinish.Text = string.Format("{0}:{1}:{2}", time.R.TotalHours.ToString("00"),
                                                 time.R.Minutes.ToString("00"), time.R.Seconds.ToString("00"));

            // Set random color tags for tasks
            int num = rand.Next(1, 5);

            if (num == 1)
            {
                colorTag.BackgroundColor = Color.Accent;
            }
            if (num == 2)
            {
                colorTag.BackgroundColor = Color.FromHex("#F44336");
            }
            if (num == 3)
            {
                colorTag.BackgroundColor = Color.FromHex("#212121");
            }
            if (num == 4)
            {
                colorTag.BackgroundColor = Color.FromHex("#FFCA28");
            }

            // When the user clicks on the edit button
            editButton.Clicked += async(s, a) =>
            {
                UserModel.Rewrite("Updated:", DateTime.Now.ToString(), Currentuser.LocalLogin);
                try
                {
                    Currentuser.UserLogin.Object.Updated = DateTime.Now.ToString();
                    await Currentuser.RewriteDATA();
                }
                catch { }
                EditTaskView EditCurrent = new EditTaskView(time, ListTimer, Currentuser, taskName, timerlads, timers);
                EditCurrent.Disappearing += (s2, e2) =>
                {
                    TimerStop = EditCurrent.Deleted;
                };
                await this.Navigation.PushModalAsync(EditCurrent);
            };

            ListTimer.Add(time);                            // Add the TimerUpdatecs time variable to the ListTimer list
            Currentuser.UpdateCurrenttimesAsync(ListTimer); // Update the current times on the file

            if (DateTime.Now < Trg)                         // Check whenever the current date is still under the end date of the task.
            {
                Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {                                   // Start timer to be run by a background thread
                    time.R = time.T - DateTime.Now; // Update remaining time
                    countdownFinish.Text = string.Format("{0}:{1}:{2}", time.R.TotalHours.ToString("00"),
                                                         time.R.Minutes.ToString("00"), time.R.Seconds.ToString("00"));

                    if (truthtime.TasksRun == false) // Check whenever the truthtime boolean encapsulation class is false
                    {
                        return(false);
                    }

                    if (TimerStop == true)
                    {
                        return(false);
                    }

                    if (DateTime.Now >= Trg) // If the timer is equal to the end date or over
                    {
                        timerlads.Children.Remove(buttons);
                        DisplayFinishButton(timerlads, time, buttons);
                        return(false);
                    }
                    return(true); // Return true to continue thread and timer operation
                });

                buttons.Children.Add(countdownFinish);
                timerlads.Children.Add(colorTag);
                timerlads.Children.Add(taskName);
                timerlads.Children.Add(editButton);
                timerlads.Children.Add(buttons);
                timers.Children.Add(timerlads); // Add all controls to stack layouts
            }

            else // If over due display finish button
            {
                timerlads.Children.Add(colorTag);
                timerlads.Children.Add(taskName);
                timerlads.Children.Add(editButton);
                timers.Children.Add(timerlads); // Add all controls to stack layouts
                DisplayFinishButton(timerlads, time, buttons);
            }
        }