public async void refreshData()
        {
            activityView.StartAnimating();

            projectNameBtn.SetTitle("loading current project ...", UIControlState.Normal);
            taskNameBtn.SetTitle("loading current task ...", UIControlState.Normal);

            try
            {
                List <DTO.Task> projectsList = await PDashAPI.Controller.GetRecentTasks();

                RecentTaskItems = projectsList;
                currentProject  = RecentTaskItems[0].Project;
                currentTask     = RecentTaskItems[0];

                projectNameBtn.SetTitle(currentProject.Name, UIControlState.Normal);
                taskNameBtn.SetTitle(currentTask.FullName, UIControlState.Normal);

                refreshControlButtons();

                recentTaskTableView.Source = new TaskTableSource(RecentTaskItems.GetRange(1, RecentTaskItems.Count - 1), this);
                recentTaskTableView.ReloadData();
            }
            catch (Exception ex)
            {
                ViewControllerHelper.ShowAlert(this, null, ex.Message + " Please try again later.");
            }
            finally
            {
                activityView.StopAnimating();
            }
        }
Beispiel #2
0
        public override async void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {
            switch (editingStyle)
            {
            case UITableViewCellEditingStyle.Delete:
                TimeLogEntry item = indexedTableItems[keys[indexPath.Section]][indexPath.Row];

                if (isActiveTimeLog(item))
                {
                    ViewControllerHelper.ShowAlert(owner, "Oops", "You are currently logging time to this time log. Please stop the timmer first.");
                }
                else
                {
                    try
                    {
                        await PDashAPI.Controller.DeleteTimeLog(item.Id.ToString());
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(owner, "Delete Time Log", ex.Message + " Please try again later.");
                    }
                }

                indexedTableItems[keys[indexPath.Section]].RemoveAt(indexPath.Row);
                tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);
                // save the time log entry deletion to server

                break;

            case UITableViewCellEditingStyle.None:
                Console.WriteLine("CommitEditingStyle:None called");
                break;
            }
        }
Beispiel #3
0
        public async void refreshData()
        {
            if (!this.RefreshControl.Refreshing)
            {
                this.RefreshControl.BeginRefreshing();
            }

            try
            {
                List <Project> projectsList = await PDashAPI.Controller.GetProjects();

                projectsCache            = projectsList;
                projectsTableView.Source = new ProjectsTableSource(projectsCache, this);
                projectsTableView.ReloadData();

                String refreshTime = DateTime.Now.ToString("g");
                String subTitle    = "Last refresh: " + refreshTime;
                this.RefreshControl.AttributedTitle = new Foundation.NSAttributedString(subTitle);
            }
            catch (Exception ex)
            {
                ViewControllerHelper.ShowAlert(this, null, ex.Message + " Please try again later.");
            }
            finally
            {
                if (this.RefreshControl.Refreshing)
                {
                    this.RefreshControl.EndRefreshing();
                }
            }
        }
Beispiel #4
0
        public async void refreshData()
        {
            // TODO: Fixed the Refreshcontrol, refreshing the list of tasks.
            //if (!RefreshControl.Refreshing)
            //{
            //	RefreshControl.BeginRefreshing();
            //}

            try
            {
                List <Task> tasksList = await PDashAPI.Controller.GetTasks(projectId);

                tasksCache = tasksList;
                TasksTableSource source = new TasksTableSource(tasksCache, this);
                tasksTableView.Source = source;
                tasksTableView.ReloadData();

                String refreshTime = DateTime.Now.ToString("g");
                String subTitle    = "Last refresh: " + refreshTime;
            }
            catch (Exception ex)
            {
                ViewControllerHelper.ShowAlert(this, null, ex.Message + " Please try again later.");
            }

            try
            {
                int pos = 0;
                int i   = 0;
                while (i < tasksCache.Count && tasksCache[i].CompletionDate != null)
                {
                    i++;
                }
                pos = i <= 4 ? i : i - 4;

                // The scroll bar should be scrolled so that the first incomplete task is the first task in the screen.
                if (tasksCache.Count != 0)
                {
                    tasksTableView.ScrollToRow(NSIndexPath.FromRowSection(pos, 0), UITableViewScrollPosition.Top, true);
                }
            }
            catch (Exception ex)
            {
                ;
            }

            // TODO: Fixed the Refreshcontrol, refreshing the list of tasks.
            //RefreshControl.AttributedTitle = new Foundation.NSAttributedString(subTitle);

            // TODO: Fixed the Refreshcontrol, refreshing the list of tasks.
            //if (this.RefreshControl.Refreshing)
            //{
            //	this.RefreshControl.EndRefreshing();
            //}
        }
Beispiel #5
0
 private void refreshPicker()
 {
     if (TaskItem.CompletionDate == null)
     {
         saveButton.Title = "Mark Complete";
         CompleteTimePicker.SetDate(ViewControllerHelper.DateTimeUtcToNSDate(DateTime.UtcNow), true);
     }
     else
     {
         saveButton.Title = "Mark Incomplete";
         CompleteTimePicker.SetDate(ViewControllerHelper.DateTimeUtcToNSDate(Util.GetInstance().GetServerTime(TaskItem.CompletionDate.Value)), true);
     }
 }
        private async void refreshData()
        {
            try
            {
                timeLogCache = await PDashAPI.Controller.GetTimeLogs(0, null, null, taskId, null);

                TaskTimeLogTable.Source = new TaskTimeLogTableSource(timeLogCache, this);
                TaskTimeLogTable.ReloadData();
            }
            catch (Exception ex)
            {
                ViewControllerHelper.ShowAlert(this, null, ex.Message + " Please try again later.");
            }
        }
        public async void refreshData()
        {
            try
            {
                task = await PDashAPI.Controller.GetTask(task.Id);

                PlanTable.Source = new TaskDetailTableSource(task, this);
                PlanTable.ReloadData();
                refreshControlButtons();
            }
            catch (Exception ex)
            {
                ViewControllerHelper.ShowAlert(this, null, ex.Message + " Please try again later.");
            }
        }
        public async void refreshData()
        {
            activityView.StartAnimating();
            try
            {
                globalTimeLogCache = await PDashAPI.Controller.GetTimeLogs(0, null, null, null, null);

                TimelogTableSource source = new TimelogTableSource(globalTimeLogCache, this);
                TimelogsTable.Source = source;
                TimelogsTable.ReloadData();
                TimelogsTable.ScrollToRow(NSIndexPath.FromRowSection(0, source.keys.Length - 1), UITableViewScrollPosition.Top, true);
            }
            catch (Exception ex)
            {
                ViewControllerHelper.ShowAlert(this, null, ex.Message + " Please try again later.");
            }
            finally
            {
                activityView.StopAnimating();
            }
        }
        public async void CommentButtonClicked(object sender, UIButtonEventArgs e)
        {
            UIAlertView parent_alert = (UIAlertView)sender;

            if (e.ButtonIndex == 1)
            {
                CommentText.SetTitle(parent_alert.GetTextField(0).Text, UIControlState.Normal);
                timeLogEntry.Comment = parent_alert.GetTextField(0).Text;

                if (!isAddingMode)
                {
                    try
                    {
                        await PDashAPI.Controller.UpdateTimeLog(timeLogEntry.Id.ToString(), timeLogEntry.Comment, null, timeLogEntry.Task.Id, null, null, false);
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(this, "Change Comment", ex.Message + " Please try again later.");
                    }
                }
            }
        }
        public void newCompleteDatePicker()
        {
            completedDateText = new UITextField(new CGRect(0, 0, 0, 0));
            View.Add(completedDateText);

            CompleteTimePicker = new UIDatePicker(new CoreGraphics.CGRect(0, this.View.Frame.Height - 250, this.View.Frame.Width, 200f));
            CompleteTimePicker.BackgroundColor = UIColor.FromRGB(220, 220, 220);

            CompleteTimePicker.UserInteractionEnabled = true;
            CompleteTimePicker.Mode        = UIDatePickerMode.DateAndTime;
            CompleteTimePicker.MaximumDate = ViewControllerHelper.DateTimeUtcToNSDate(DateTime.UtcNow);
            //Setup the toolbar
            toolbar                 = new UIToolbar();
            toolbar.BarStyle        = UIBarStyle.Default;
            toolbar.BackgroundColor = UIColor.FromRGB(220, 220, 220);
            toolbar.Translucent     = true;
            toolbar.SizeToFit();

            saveButton = new UIBarButtonItem(saveButtonLabel, UIBarButtonItemStyle.Bordered, null);

            saveButton.Clicked += async(s, e) =>
            {
                completeTimeSelectedDate = ViewControllerHelper.NSDateToDateTimeUtc(CompleteTimePicker.Date);
                if (saveButton.Title.Equals("Mark Complete"))
                {
                    try
                    {
                        await PDashAPI.Controller.UpdateATask(currentTask.Id, null, completeTimeSelectedDate, false);

                        currentTask.CompletionDate = completeTimeSelectedDate;
                        completeBtn.SetImage(UIImage.FromBundle("checkbox-checked"), UIControlState.Normal);
                        PauseBtnOnClick(null, null);
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(this, "Mark Complete", ex.Message + " Please try again later.");
                    }
                }
                else if (saveButton.Title.Equals("Mark Incomplete"))
                {
                    try
                    {
                        await PDashAPI.Controller.UpdateATask(currentTask.Id, null, null, true);

                        currentTask.CompletionDate = null;
                        completeBtn.SetImage(UIImage.FromBundle("checkbox-unchecked"), UIControlState.Normal);
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(this, "Mark Incomplete", ex.Message + " Please try again later.");
                    }
                }
                else
                {
                    // Change Completion Date
                    try
                    {
                        DateTime newCompleteDate = ViewControllerHelper.NSDateToDateTimeUtc(CompleteTimePicker.Date);
                        await PDashAPI.Controller.UpdateATask(currentTask.Id, null, newCompleteDate, false);

                        currentTask.CompletionDate = newCompleteDate;
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(this, "Change Completion Date", ex.Message + " Please try again later.");
                    }
                }
                this.completedDateText.ResignFirstResponder();
            };

            var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace)
            {
                Width = 50
            };

            cancelButton = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Bordered,
                                               (s, e) =>
            {
                this.completedDateText.ResignFirstResponder();
            });

            toolbar.SetItems(new UIBarButtonItem[] { cancelButton, spacer, saveButton }, true);

            if (currentTask.CompletionDate == null)
            {
                saveButton.Title = "Mark Complete";
                CompleteTimePicker.SetDate(ViewControllerHelper.DateTimeUtcToNSDate(DateTime.UtcNow), true);
            }
            else
            {
                saveButton.Title = "Mark Incomplete";
                CompleteTimePicker.SetDate(ViewControllerHelper.DateTimeUtcToNSDate(Util.GetInstance().GetServerTime(currentTask.CompletionDate.Value)), true);
            }

            CompleteTimePicker.ValueChanged += (Object s, EventArgs e) =>
            {
                if (currentTask.CompletionDate != null)
                {
                    saveButton.Title = "Change Completion Date";
                }

                completeTimeSelectedDate = ViewControllerHelper.NSDateToDateTimeUtc((s as UIDatePicker).Date);
            };

            CompleteTimePicker.BackgroundColor = UIColor.White;

            this.completedDateText.InputView          = CompleteTimePicker;
            this.completedDateText.InputAccessoryView = toolbar;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            activityView                  = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
            activityView.Frame            = View.Frame;
            activityView.BackgroundColor  = UIColor.FromRGBA(0, 0, 0, 0.6f);
            activityView.Center           = View.Center;
            activityView.HidesWhenStopped = true;
            View.AddSubview(activityView);

            tlc = TimeLoggingController.GetInstance();

            if (timeLogEntry == null)
            {
                throw new ArgumentException("timeLogEntry is null.");
            }

            if (isAddingMode)
            {
                barBtnItem = new UIBarButtonItem(UIBarButtonSystemItem.Save, async(s, e) =>
                {
                    activityView.StartAnimating();
                    try
                    {
                        await PDashAPI.Controller.AddATimeLog(timeLogEntry.Comment, timeLogEntry.StartDate, timeLogEntry.Task.Id, timeLogEntry.LoggedTime, timeLogEntry.InterruptTime, false);
                        activityView.StopAnimating();
                        NavigationController.PopViewController(true);
                    }
                    catch (Exception ex)
                    {
                        activityView.StopAnimating();
                        ViewControllerHelper.ShowAlert(this, "Add Time Log", ex.Message + " Please try again later.");
                    }
                });
            }
            else
            {
                barBtnItem = new UIBarButtonItem(UIBarButtonSystemItem.Trash, (s, e) =>
                {
                    UIAlertController actionSheetAlert = UIAlertController.Create(null, "This time log will be deleted", UIAlertControllerStyle.ActionSheet);

                    actionSheetAlert.AddAction(UIAlertAction.Create("Delete", UIAlertActionStyle.Destructive, async(action) =>
                    {
                        if (isActiveTimeLog())
                        {
                            ViewControllerHelper.ShowAlert(this, "Oops", "You are currently logging time to this time log. Please stop the timmer first.");
                        }
                        else
                        {
                            activityView.StartAnimating();
                            try
                            {
                                await PDashAPI.Controller.DeleteTimeLog(timeLogEntry.Id.ToString());
                                activityView.StopAnimating();
                                NavigationController.PopViewController(true);
                            }
                            catch (Exception ex)
                            {
                                activityView.StopAnimating();
                                ViewControllerHelper.ShowAlert(this, "Delete Time Log", ex.Message + " Please try again later.");
                            }
                        }
                    }));

                    actionSheetAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (action) => Console.WriteLine("Cancel button pressed.")));

                    UIPopoverPresentationController presentationPopover = actionSheetAlert.PopoverPresentationController;
                    if (presentationPopover != null)
                    {
                        presentationPopover.SourceView = this.View;
                        presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up;
                    }

                    // Display the alertg
                    this.PresentViewController(actionSheetAlert, true, null);
                });
            }

            NavigationItem.RightBarButtonItem = barBtnItem;

            ProjectNameLabel.Text = timeLogEntry.Task.Project.Name;
            TaskNameLabel.Text    = timeLogEntry.Task.FullName;
            StartTimeText.Text    = Util.GetInstance().GetLocalTime(timeLogEntry.StartDate).ToString("g");

            // set up start time customized UIpicker

            StartTimePicker = new UIDatePicker(new CoreGraphics.CGRect(10f, this.View.Frame.Height - 250, this.View.Frame.Width - 20, 200f));
            StartTimePicker.BackgroundColor = UIColor.FromRGB(220, 220, 220);

            StartTimePicker.UserInteractionEnabled = true;
            StartTimePicker.Mode        = UIDatePickerMode.DateAndTime;
            StartTimePicker.MaximumDate = ViewControllerHelper.DateTimeUtcToNSDate(DateTime.UtcNow);

            startTimeSelectedDate = Util.GetInstance().GetServerTime(timeLogEntry.StartDate);

            StartTimePicker.ValueChanged += (Object sender, EventArgs e) =>
            {
                startTimeSelectedDate = ViewControllerHelper.NSDateToDateTimeUtc((sender as UIDatePicker).Date);
            };

            StartTimePicker.BackgroundColor = UIColor.White;
            StartTimePicker.SetDate(ViewControllerHelper.DateTimeUtcToNSDate(Util.GetInstance().GetServerTime(timeLogEntry.StartDate)), true);

            //Setup the toolbar
            toolbar                 = new UIToolbar();
            toolbar.BarStyle        = UIBarStyle.Default;
            toolbar.BackgroundColor = UIColor.FromRGB(220, 220, 220);
            toolbar.Translucent     = true;
            toolbar.SizeToFit();

            // Create a 'done' button for the toolbar and add it to the toolbar

            saveButton = new UIBarButtonItem("Save", UIBarButtonItemStyle.Bordered, null);

            saveButton.Clicked += async(s, e) =>
            {
                this.StartTimeText.Text = Util.GetInstance().GetLocalTime(startTimeSelectedDate).ToString();
                timeLogEntry.StartDate  = startTimeSelectedDate;
                this.StartTimeText.ResignFirstResponder();

                if (!isAddingMode)
                {
                    try
                    {
                        await PDashAPI.Controller.UpdateTimeLog(timeLogEntry.Id.ToString(), null, timeLogEntry.StartDate, timeLogEntry.Task.Id, null, null, false);
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(this, "Change Start Time", ex.Message + " Please try again later.");
                    }
                }
            };

            var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace)
            {
                Width = 50
            };

            cancelButton = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Bordered,
                                               (s, e) =>
            {
                this.StartTimeText.ResignFirstResponder();
            });

            toolbar.SetItems(new UIBarButtonItem[] { cancelButton, spacer, saveButton }, true);

            this.StartTimeText.InputView          = StartTimePicker;
            this.StartTimeText.InputAccessoryView = toolbar;

            DeltaText.Text = TimeSpan.FromMinutes(timeLogEntry.LoggedTime).ToString(@"hh\:mm");

            IntText.Text = TimeSpan.FromMinutes(timeLogEntry.InterruptTime).ToString(@"hh\:mm");

            CommentText.SetTitle(timeLogEntry.Comment ?? "No Comment", UIControlState.Normal);

            CommentText.TouchUpInside += (sender, e) =>
            {
                UIAlertView alert = new UIAlertView();
                alert.Title = "Comment";
                alert.AddButton("Cancel");
                alert.AddButton("Save");
                alert.Message        = "Please enter new Comment";
                alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
                UITextField textField = alert.GetTextField(0);
                textField.Placeholder = timeLogEntry.Comment ?? "No Comment";
                alert.Clicked        += CommentButtonClicked;
                alert.Show();
            };

            /////Delta Picker
            DeltaPicker = new UIPickerView(new CoreGraphics.CGRect(10f, this.View.Frame.Height - 250, this.View.Frame.Width - 20, 200f));
            DeltaPicker.BackgroundColor = UIColor.FromRGB(220, 220, 220);

            DeltaPicker.UserInteractionEnabled = true;
            DeltaPicker.ShowSelectionIndicator = true;

            string[] hours   = new string[24];
            string[] minutes = new string[60];

            for (int i = 0; i < hours.Length; i++)
            {
                hours[i] = i.ToString();
            }
            for (int i = 0; i < minutes.Length; i++)
            {
                minutes[i] = i.ToString("00");
            }

            StatusPickerViewModel deltaModel = new StatusPickerViewModel(hours, minutes);

            int h = (int)timeLogEntry.LoggedTime / 60;
            int m = (int)timeLogEntry.LoggedTime % 60;

            this.deltaSelectedHour   = h.ToString();
            this.deltaSelectedMinute = m.ToString("00");

            deltaModel.NumberSelected += (Object sender, EventArgs e) =>
            {
                this.deltaSelectedHour   = deltaModel.selectedHour;
                this.deltaSelectedMinute = deltaModel.selectedMinute;
            };

            DeltaPicker.Model           = deltaModel;
            DeltaPicker.BackgroundColor = UIColor.White;
            DeltaPicker.Select(h, 0, true);
            DeltaPicker.Select(m, 1, true);

            //Setup the toolbar
            toolbar                 = new UIToolbar();
            toolbar.BarStyle        = UIBarStyle.Default;
            toolbar.BackgroundColor = UIColor.FromRGB(220, 220, 220);
            toolbar.Translucent     = true;
            toolbar.SizeToFit();

            // Create a 'done' button for the toolbar and add it to the toolbar
            saveButton = new UIBarButtonItem("Save", UIBarButtonItemStyle.Bordered, null);

            saveButton.Clicked += async(s, e) =>
            {
                this.DeltaText.Text = this.deltaSelectedHour + ":" + this.deltaSelectedMinute;
                double oldLoggedTime = timeLogEntry.LoggedTime;
                timeLogEntry.LoggedTime = int.Parse(this.deltaSelectedHour) * 60 + int.Parse(this.deltaSelectedMinute);
                this.DeltaText.ResignFirstResponder();

                if (!isAddingMode)
                {
                    if (isActiveTimeLog())
                    {
                        tlc.SetLoggedTime((int)timeLogEntry.LoggedTime);
                    }
                    else
                    {
                        try
                        {
                            await PDashAPI.Controller.UpdateTimeLog(timeLogEntry.Id.ToString(), null, null, timeLogEntry.Task.Id, timeLogEntry.LoggedTime - oldLoggedTime, null, false);
                        }
                        catch (Exception ex)
                        {
                            ViewControllerHelper.ShowAlert(this, "Change Logged Time", ex.Message + " Please try again later.");
                        }
                    }
                }
            };

            cancelButton = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Bordered,
                                               (s, e) =>
            {
                this.DeltaText.ResignFirstResponder();
            });

            toolbar.SetItems(new UIBarButtonItem[] { cancelButton, spacer, saveButton }, true);

            this.DeltaText.InputView          = DeltaPicker;
            this.DeltaText.InputAccessoryView = toolbar;

            ////// Int Picker
            IntPicker = new UIPickerView(new CoreGraphics.CGRect(10f, this.View.Frame.Height - 200, this.View.Frame.Width - 20, 200f));
            IntPicker.BackgroundColor = UIColor.FromRGB(220, 220, 220);

            IntPicker.UserInteractionEnabled = true;
            IntPicker.ShowSelectionIndicator = true;
            IntPicker.BackgroundColor        = UIColor.White;

            IntPicker.Select(0, 0, true);

            StatusPickerViewModel intModel = new StatusPickerViewModel(hours, minutes);

            intModel.NumberSelected += (Object sender, EventArgs e) =>
            {
                this.intSelectedHour   = intModel.selectedHour;
                this.intSelectedMinute = intModel.selectedMinute;
            };

            IntPicker.Model = intModel;

            IntPicker.Select((int)timeLogEntry.InterruptTime / 60, 0, true);
            IntPicker.Select((int)timeLogEntry.InterruptTime % 60, 1, true);

            //Setup the toolbar
            toolbar                 = new UIToolbar();
            toolbar.BarStyle        = UIBarStyle.Default;
            toolbar.BackgroundColor = UIColor.FromRGB(220, 220, 220);
            toolbar.Translucent     = true;
            toolbar.SizeToFit();

            saveButton = new UIBarButtonItem("Save", UIBarButtonItemStyle.Bordered, null);

            saveButton.Clicked += async(s, e) =>
            {
                this.IntText.Text          = this.intSelectedHour + ":" + this.intSelectedMinute;
                timeLogEntry.InterruptTime = int.Parse(this.intSelectedHour) * 60 + int.Parse(this.intSelectedMinute);
                this.IntText.ResignFirstResponder();

                if (!isAddingMode)
                {
                    if (isActiveTimeLog())
                    {
                        tlc.SetInterruptTime((int)timeLogEntry.InterruptTime);
                    }
                    else
                    {
                        try
                        {
                            await PDashAPI.Controller.UpdateTimeLog(timeLogEntry.Id.ToString(), null, null, timeLogEntry.Task.Id, null, timeLogEntry.InterruptTime, false);
                        }
                        catch (Exception ex)
                        {
                            ViewControllerHelper.ShowAlert(this, "Change Interrupt Time", ex.Message + " Please try again later.");
                        }
                    }
                }
            };

            cancelButton = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Bordered,
                                               (s, e) =>
            {
                this.IntText.ResignFirstResponder();
            });

            toolbar.SetItems(new UIBarButtonItem[] { cancelButton, spacer, saveButton }, true);

            this.IntText.InputView          = IntPicker;
            this.IntText.InputAccessoryView = toolbar;
        }
Beispiel #12
0
        public void newCompleteDatePicker()
        {
            CompleteTimePicker = new UIDatePicker(new CoreGraphics.CGRect(0, 300, 400, 200f));
            CompleteTimePicker.BackgroundColor = UIColor.FromRGB(220, 220, 220);

            CompleteTimePicker.UserInteractionEnabled = true;
            CompleteTimePicker.Mode        = UIDatePickerMode.DateAndTime;
            CompleteTimePicker.MaximumDate = ViewControllerHelper.DateTimeUtcToNSDate(DateTime.UtcNow);
            //Setup the toolbar
            toolbar                 = new UIToolbar();
            toolbar.BarStyle        = UIBarStyle.Default;
            toolbar.BackgroundColor = UIColor.FromRGB(220, 220, 220);
            toolbar.Translucent     = true;
            toolbar.SizeToFit();

            // Create a 'done' button for the toolbar and add it to the toolbar
            saveButton = new UIBarButtonItem(saveButtonLabel, UIBarButtonItemStyle.Bordered, null);

            saveButton.Clicked += async(s, e) =>
            {
                if (saveButton.Title.Equals("Mark Complete"))
                {
                    try
                    {
                        completeTimeSelectedDate = ViewControllerHelper.NSDateToDateTimeUtc(CompleteTimePicker.Date);
                        await PDashAPI.Controller.UpdateATask(TaskItem.Id, null, completeTimeSelectedDate, false);

                        TaskItem.CompletionDate    = completeTimeSelectedDate;
                        this.completeDateText.Text = Util.GetInstance().GetLocalTime(completeTimeSelectedDate).ToShortDateString();
                        owner.task = TaskItem;
                        owner.PauseBtnOnClick(null, null);
                        owner.refreshControlButtons();
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(owner, "Mark Complete", ex.Message + " Please try again later.");
                    }
                }
                else if (saveButton.Title.Equals("Mark Incomplete"))
                {
                    try
                    {
                        await PDashAPI.Controller.UpdateATask(TaskItem.Id, null, null, true);

                        TaskItem.CompletionDate    = null;
                        this.completeDateText.Text = "-:-";
                        owner.task = TaskItem;
                        owner.refreshControlButtons();
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(owner, "Mark Incomplete", ex.Message + " Please try again later.");
                    }
                }
                else
                {
                    // Change Completion Date
                    try
                    {
                        DateTime newCompleteDate = ViewControllerHelper.NSDateToDateTimeUtc(CompleteTimePicker.Date);
                        await PDashAPI.Controller.UpdateATask(TaskItem.Id, null, newCompleteDate, false);

                        TaskItem.CompletionDate    = newCompleteDate;
                        this.completeDateText.Text = Util.GetInstance().GetLocalTime(newCompleteDate).ToString("d");
                        owner.task = TaskItem;
                        owner.refreshControlButtons();
                    }
                    catch (Exception ex)
                    {
                        ViewControllerHelper.ShowAlert(owner, "Change Completion Date", ex.Message + " Please try again later.");
                    }
                }

                this.completeDateText.ResignFirstResponder();
                refreshPicker();
            };

            var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace)
            {
                Width = 50
            };

            cancelButton = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Bordered,
                                               (s, e) =>
            {
                this.completeDateText.ResignFirstResponder();
                refreshPicker();
            });

            toolbar.SetItems(new UIBarButtonItem[] { cancelButton, spacer, saveButton }, true);

            refreshPicker();

            CompleteTimePicker.ValueChanged += (Object s, EventArgs e) =>
            {
                if (TaskItem.CompletionDate != null)
                {
                    saveButton.Title = "Change Completion Date";
                }

                completeTimeSelectedDate = ViewControllerHelper.NSDateToDateTimeUtc((s as UIDatePicker).Date);
            };

            CompleteTimePicker.BackgroundColor = UIColor.White;

            this.completeDateText.InputView          = CompleteTimePicker;
            this.completeDateText.InputAccessoryView = toolbar;
        }
Beispiel #13
0
        public void newPlanTimePicker()
        {
            PlanTimePicker = new UIPickerView(new CoreGraphics.CGRect(0, 300, 400, 200f));
            PlanTimePicker.BackgroundColor = UIColor.FromRGB(220, 220, 220);

            PlanTimePicker.UserInteractionEnabled = true;
            PlanTimePicker.ShowSelectionIndicator = true;

            string[] hours   = new string[24];
            string[] minutes = new string[60];

            for (int i = 0; i < hours.Length; i++)
            {
                hours[i] = i.ToString();
            }
            for (int i = 0; i < minutes.Length; i++)
            {
                minutes[i] = i.ToString("00");
            }

            StatusPickerViewModel planModel = new StatusPickerViewModel(hours, minutes);

            int h = (int)TaskItem.EstimatedTime / 60;
            int m = (int)TaskItem.EstimatedTime % 60;

            this.planSelectedHour   = h.ToString();
            this.planSelectedMinute = m.ToString("00");

            planModel.NumberSelected += (Object sender, EventArgs e) =>
            {
                this.planSelectedHour   = planModel.selectedHour;
                this.planSelectedMinute = planModel.selectedMinute;
            };

            PlanTimePicker.Model           = planModel;
            PlanTimePicker.BackgroundColor = UIColor.White;
            PlanTimePicker.Select(h, 0, true);
            PlanTimePicker.Select(m, 1, true);

            //Setup the toolbar
            toolbar                 = new UIToolbar();
            toolbar.BarStyle        = UIBarStyle.Default;
            toolbar.BackgroundColor = UIColor.FromRGB(220, 220, 220);
            toolbar.Translucent     = true;
            toolbar.SizeToFit();

            // Create a 'done' button for the toolbar and add it to the toolbar

            saveButton = new UIBarButtonItem(saveButtonLabel, UIBarButtonItemStyle.Bordered, null);

            saveButton.Clicked += async(s, e) =>
            {
                try
                {
                    double planTime = int.Parse(this.planSelectedHour) * 60 + int.Parse(this.planSelectedMinute);
                    // TODO:
                    // service access Layer should provide nullable markTimeInComplete field!
                    // otherwise, this value may be updated unexpectedly
                    await PDashAPI.Controller.UpdateATask(TaskItem.Id, planTime, null, TaskItem.CompletionDate == null);

                    this.planTimeText.Text = this.planSelectedHour + ":" + this.planSelectedMinute;
                }
                catch (Exception ex)
                {
                    ViewControllerHelper.ShowAlert(owner, "Change Planed Time", ex.Message + " Please try again later.");
                }
                finally
                {
                    this.planTimeText.ResignFirstResponder();
                }
            };

            var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace)
            {
                Width = 50
            };

            cancelButton = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Bordered,
                                               (s, e) =>
            {
                this.planTimeText.ResignFirstResponder();
            });

            toolbar.SetItems(new UIBarButtonItem[] { cancelButton, spacer, saveButton }, true);

            this.planTimeText.InputView          = PlanTimePicker;
            this.planTimeText.InputAccessoryView = toolbar;
        }