예제 #1
0
        private async void AddData(View view)
        {
            var projectName  = view.FindViewById <TextView>(Resource.Id.TaskDetails_ProjectName);
            var taskName     = view.FindViewById <TextView>(Resource.Id.TaskDetails_TaskName);
            var notes        = view.FindViewById <EditText>(Resource.Id.TaskDetails_Notes);
            var timeinfo     = view.FindViewById <ListView>(Resource.Id.TaskDetails_TimeInfo);
            var taskComplete = view.FindViewById <CheckBox>(Resource.Id.TaskDetails_TaskComplete);

            if (_completionDate.HasValue)
            {
                taskComplete.Checked = true;
            }

            _play  = view.FindViewById <Button>(Resource.Id.TaskDetails_Play);
            _pause = view.FindViewById <Button>(Resource.Id.TaskDetails_Pause);

            Debug.WriteLine("We are in the begining ");
            if (TimeLoggingController.GetInstance().IsTimerRunning() && TimeLoggingController.GetInstance().GetTimingTaskId().Equals(_taskId))
            {
                ModifyPlayPauseState(true);
            }
            var pb = new ProgressDialog(_mActivity)
            {
                Indeterminate = true
            };

            pb.SetTitle("Loading");
            pb.SetCanceledOnTouchOutside(false);
            if (_taskName != null)
            {
                taskName.Text = _taskName;
            }

            if (_projectName != null)
            {
                projectName.Text = _projectName;
            }

            Debug.WriteLine(" 0 ");
            Entry[] output = new Entry[3];

            output[0] = new Entry();
            output[1] = new Entry();
            output[2] = new Entry();

            output[0].name = "Planned Time";

            if (_estimatedTime.HasValue)
            {
                Debug.WriteLine("We have a value in estimated time");
                output[0].value = "" + TimeSpan.FromMinutes(_estimatedTime.Value).ToString(@"hh\:mm");
            }
            else
            {
                Debug.WriteLine("No value in estimated time");
                output[0].value = "";
            }
            Debug.WriteLine(" 1 ");


            output[1].name = "Actual Time";
            if (_actualTime.HasValue)
            {
                output[1].value = "" + TimeSpan.FromMinutes(_actualTime.Value).ToString(@"hh\:mm");
            }
            else
            {
                output[1].value = "";
            }

            output[2].name = "Completion Date";
            Debug.WriteLine(" 2 ");
            if (_completionDate.HasValue)
            {
                output[2].value = Util.GetInstance().GetLocalTime(_completionDate.Value).ToShortDateString();
            }
            else
            {
                output[2].value = "-";
            }

            var listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                     output);


            Debug.WriteLine("We have reached the end ");

            timeinfo.Adapter = listAdapter;

            pb.Show();
            Task taskDetail = null;

            try

            {
                // Get data from server
                taskDetail = await((MainActivity)Activity).Ctrl.GetTask(AccountStorage.DataSet, _taskId);

                _play.Click += (sender, args) =>
                {
                    Debug.WriteLine("Play Clicked");

                    //var timerServiceIntent = new Intent("com.tumasolutions.processdashboard.TimerService");

                    //var timerServiceConnection = new TimerServiceConnection((MainActivity)this.Activity);

                    //Activity.ApplicationContext.BindService(timerServiceIntent, timerServiceConnection, Bind.AutoCreate);
                    Intent intent = new Intent(Activity, typeof(TimerService));
                    intent.PutExtra("taskId", taskDetail.Id);
                    Activity.StartService(intent);
                };



                _pause.Click += (sender, args) =>
                {
                    Debug.WriteLine("Pause Clicked");
                    Activity.StopService(new Intent(Activity, typeof(TimerService)));
                    Toast.MakeText(this.Activity, "Time Log Entry Saved", ToastLength.Short).Show();
                };

                projectName.Click += (obj, args) =>
                {
                    var projectId   = taskDetail.Project.Id;
                    var projectname = taskDetail.Project.Name;

                    ((MainActivity)Activity).ListOfProjectsCallback(projectId, projectname);
                };
            }
            catch (CannotReachServerException)
            {
                if (pb.IsShowing)
                {
                    pb.Dismiss();
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                builder.SetTitle("Unable to Connect")
                .SetMessage("Please check your network connection and try again")
                .SetNeutralButton("Okay", (sender, args) =>
                {
                    builder.Dispose();
                    ((MainActivity)Activity).FragmentManager.PopBackStack();
                })
                .SetCancelable(false);
                AlertDialog alert = builder.Create();
                alert.Show();
            }
            catch (WebException we)
            {
                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    var response = we.Response as HttpWebResponse;
                    if (response != null)
                    {
                        Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                        if (response.StatusCode == HttpStatusCode.Forbidden)
                        {
                            try
                            {
                                if (pb.IsShowing)
                                {
                                    pb.Dismiss();
                                }
                                Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show();
                                AccountStorage.ClearStorage();
                                Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                ((MainActivity)(Activity)).SetDrawerState(false);
                                ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login);
                            }
                            catch (System.Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                            }
                        }
                    }
                    else
                    {
                        // no http status code available
                        Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                    }
                }
                else
                {
                    // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                }
            }
            catch (StatusNotOkayException se)
            {
                if (pb.IsShowing)
                {
                    pb.Dismiss();
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                builder.SetTitle("An Error has occured")
                .SetMessage("Error :" + se.GetMessage())
                .SetNeutralButton("Okay", (sender, args) =>
                {
                    builder.Dispose();
                })
                .SetCancelable(false);
                AlertDialog alert = builder.Create();
                alert.Show();
            }
            catch (Exception e)
            {
                // For any other weird exceptions
                if (pb.IsShowing)
                {
                    pb.Dismiss();
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                builder.SetTitle("An Error has occured")
                .SetNeutralButton("Okay", (sender, args) =>
                {
                    builder.Dispose();
                })
                .SetMessage("Error :" + e.Message)
                .SetCancelable(false);
                AlertDialog alert = builder.Create();
                alert.Show();
            }
            if (taskDetail == null)
            {
                Debug.WriteLine("T is null");
            }

            if (taskDetail != null)
            {
                projectName.Text = taskDetail.Project.Name;

                timeinfo.ItemClick += (sender, args) =>
                {
                    if (args.Position == 0)
                    {
                        LinearLayout ll = new LinearLayout(Activity);
                        ll.Orientation = (Orientation.Horizontal);

                        NumberPicker aNumberPicker = new NumberPicker(Activity);
                        aNumberPicker.MaxValue = (100);
                        aNumberPicker.MinValue = (0);

                        double temp;

                        temp = taskDetail.EstimatedTime;


                        aNumberPicker.Value = TimeSpan.FromMinutes(temp).Hours;

                        NumberPicker aNumberPickerA = new NumberPicker(Activity)
                        {
                            MaxValue = (59),
                            MinValue = (0),
                            Value    = TimeSpan.FromMinutes(temp).Minutes
                        };


                        LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(50, 50);
                        parameters.Gravity = GravityFlags.Center;

                        LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                        numPicerParams.Weight = 1;

                        LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                        qPicerParams.Weight = 1;

                        ll.LayoutParameters = parameters;
                        ll.AddView(aNumberPicker, numPicerParams);
                        ll.AddView(aNumberPickerA, qPicerParams);

                        //((TaskDetailsAdapter)(timeinfo.Adapter)).GetEntry()


                        //var ts = DateTime.ParseExact("", "HH.mm", CultureInfo.InvariantCulture);

                        AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll);

                        np.SetTitle("Update Planned Time");
                        np.SetNegativeButton("Cancel", (s, a) =>
                        {
                            np.Dispose();
                        });
                        np.SetPositiveButton("Ok", (s, a) =>
                        {
                            //Update Planned Time
                            string number = aNumberPicker.Value.ToString("D2") + ":" + aNumberPickerA.Value.ToString("D2");
                            Debug.WriteLine(number);
                            double val = Convert.ToDouble(TimeSpan.ParseExact(number, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes);
                            Debug.WriteLine("The updated val is :" + val);
                            try
                            {
                                ((MainActivity)(Activity)).Ctrl.UpdateATask(AccountStorage.DataSet,
                                                                            _taskId, val, null, false);
                            }
                            catch (CannotReachServerException)
                            {
                                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                                builder.SetTitle("Unable to Connect")
                                .SetMessage("Please check your network connection and try again")
                                .SetNeutralButton("Okay", (sender2, args2) =>
                                {
                                    builder.Dispose();
                                    ((MainActivity)Activity).FragmentManager.PopBackStack();
                                })
                                .SetCancelable(false);
                                AlertDialog alert = builder.Create();
                                alert.Show();
                            }
                            catch (WebException we)
                            {
                                if (we.Status == WebExceptionStatus.ProtocolError)
                                {
                                    var response = we.Response as HttpWebResponse;
                                    if (response != null)
                                    {
                                        Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                                        if (response.StatusCode == HttpStatusCode.Forbidden)
                                        {
                                            try
                                            {
                                                if (pb.IsShowing)
                                                {
                                                    pb.Dismiss();
                                                }
                                                Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show();
                                                System.Diagnostics.Debug.WriteLine("We are about to logout");
                                                AccountStorage.ClearStorage();
                                                System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                                System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount);
                                                System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                                Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                                System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount);
                                                ((MainActivity)(Activity)).SetDrawerState(false);
                                                ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login);
                                            }
                                            catch (System.Exception e)
                                            {
                                                System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // no http status code available
                                        Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                                    }
                                }
                                else
                                {
                                    // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                                }
                            }
                            catch (StatusNotOkayException se)
                            {
                                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                                builder.SetTitle("An Error has occured")
                                .SetMessage("Error :" + se.GetMessage())
                                .SetNeutralButton("Okay", (sender2, args2) =>
                                {
                                    builder.Dispose();
                                })
                                .SetCancelable(false);
                                AlertDialog alert = builder.Create();
                                alert.Show();
                            }
                            catch (Exception e)
                            {
                                // For any other weird exceptions


                                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                                builder.SetTitle("An Error has occured")
                                .SetNeutralButton("Okay", (sender2, args2) =>
                                {
                                    builder.Dispose();
                                })
                                .SetMessage("Error :" + e.Message)
                                .SetCancelable(false);
                                AlertDialog alert = builder.Create();
                                alert.Show();
                            }
                            output[0].value = TimeSpan.FromMinutes(val).ToString(@"hh\:mm");

                            listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                                 output);
                            Debug.WriteLine("We have changed content ");
                            timeinfo.Adapter = listAdapter;

                            Toast.MakeText(_mActivity, "Planned Time Updated", ToastLength.Short).Show();
                            np.Dispose();
                        });
                        np.Show();
                        //Planned Time
                    }
                    else if (args.Position == 1)
                    {
                        //Actual Time
                        ((MainActivity)Activity).PassTimeLogInfo(taskDetail.Id, taskDetail.Project.Name,
                                                                 taskDetail.FullName);
                    }
                    else if (args.Position == 2)
                    {
                        // Completion Date


                        DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time)
                        {
                            Debug.WriteLine("The received date is :" + time.ToShortDateString());

                            output[2].value = time.ToShortDateString();

                            listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                                 output);
                            Debug.WriteLine("We have changed content ");
                            timeinfo.Adapter = listAdapter;

                            try
                            {
                                ((MainActivity)(Activity)).Ctrl.UpdateATask(AccountStorage.DataSet,
                                                                            _taskId, null, Util.GetInstance().GetServerTime(time), false);
                            }
                            catch (CannotReachServerException)
                            {
                                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                                builder.SetTitle("Unable to Connect")
                                .SetMessage("Please check your network connection and try again")
                                .SetNeutralButton("Okay", (sender2, args2) =>
                                {
                                    builder.Dispose();
                                    ((MainActivity)Activity).FragmentManager.PopBackStack();
                                })
                                .SetCancelable(false);
                                AlertDialog alert = builder.Create();
                                alert.Show();
                            }
                            catch (WebException we)
                            {
                                if (we.Status == WebExceptionStatus.ProtocolError)
                                {
                                    var response = we.Response as HttpWebResponse;
                                    if (response != null)
                                    {
                                        Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                                        if (response.StatusCode == HttpStatusCode.Forbidden)
                                        {
                                            try
                                            {
                                                if (pb.IsShowing)
                                                {
                                                    pb.Dismiss();
                                                }
                                                Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show();
                                                System.Diagnostics.Debug.WriteLine("We are about to logout");
                                                AccountStorage.ClearStorage();
                                                System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                                System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount);
                                                System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                                Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                                System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount);
                                                ((MainActivity)(Activity)).SetDrawerState(false);
                                                ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login);
                                            }
                                            catch (System.Exception e)
                                            {
                                                System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // no http status code available
                                        Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                                    }
                                }
                                else
                                {
                                    // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                                }
                            }
                            catch (StatusNotOkayException se)
                            {
                                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                                builder.SetTitle("An Error has occured")
                                .SetMessage("Error :" + se.GetMessage())
                                .SetNeutralButton("Okay", (sender2, args2) =>
                                {
                                    builder.Dispose();
                                })
                                .SetCancelable(false);
                                AlertDialog alert = builder.Create();
                                alert.Show();
                            }
                            catch (Exception e)
                            {
                                // For any other weird exceptions


                                AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                                builder.SetTitle("An Error has occured")
                                .SetNeutralButton("Okay", (sender2, args2) =>
                                {
                                    builder.Dispose();
                                })
                                .SetMessage("Error :" + e.Message)
                                .SetCancelable(false);
                                AlertDialog alert = builder.Create();
                                alert.Show();
                            }


                            Toast.MakeText(_mActivity, "Completion Date Updated", ToastLength.Short).Show();
                        });
                        //frag.StartTime = DateTime.SpecifyKind(DateTime.Parse(""+output[2].value), DateTimeKind.Local);

                        if (taskDetail.CompletionDate.HasValue)
                        {
                            frag.StartTime = Util.GetInstance().GetLocalTime(taskDetail.CompletionDate.Value);
                        }
                        Debug.WriteLine(frag.StartTime);
                        frag.Show(FragmentManager, DatePickerFragment.TAG);
                    }
                };

                taskName.Text   = taskDetail.FullName;
                output[0].value = TimeSpan.FromMinutes(taskDetail.EstimatedTime).ToString(@"hh\:mm");
                output[1].value = TimeSpan.FromMinutes(taskDetail.ActualTime).ToString(@"hh\:mm");
                output[2].value = taskDetail.CompletionDate.HasValue ? Util.GetInstance().GetLocalTime(taskDetail.CompletionDate.Value).ToShortDateString() : "-";
                listAdapter     = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                         output);


                Debug.WriteLine("We have changed content ");

                timeinfo.Adapter = listAdapter;
                if (string.IsNullOrEmpty(taskDetail.Note))
                {
                    notes.Text    = "-";
                    notes.Gravity = GravityFlags.Center;
                }
                else
                {
                    notes.Text = taskDetail.Note;
                }

                var timeLogs = view.FindViewById <Button>(Resource.Id.TaskDetails_TimeLogButton);
                timeLogs.Click +=
                    (sender, args) =>
                {
                    ((MainActivity)Activity).PassTimeLogInfo(taskDetail.Id, taskDetail.Project.Name,
                                                             taskDetail.FullName);
                };


                if (taskDetail.CompletionDate.HasValue && taskDetail.CompletionDate.Value != DateTime.MinValue)
                {
                    taskComplete.Checked = true;
                }
                else
                {
                    taskComplete.Checked = false;
                }

                taskComplete.CheckedChange += (sender, args) =>
                {
                    string text;
                    if (args.IsChecked)
                    {
                        // Mark a task as complete
                        DateTime convertedTime = Util.GetInstance().GetServerTime(DateTime.UtcNow);
                        taskDetail.CompletionDate = convertedTime;

                        try
                        {
                            ((MainActivity)(this.Activity)).Ctrl.UpdateATask(AccountStorage.DataSet,
                                                                             _taskId, null, convertedTime, false);

                            output[2].value = DateTime.Now.ToShortDateString();
                        }
                        catch (CannotReachServerException)
                        {
                            output[2].value      = "-";
                            taskComplete.Checked = false;
                            Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show();
                        }
                        catch (WebException we)
                        {
                            if (we.Status == WebExceptionStatus.ProtocolError)
                            {
                                var response = we.Response as HttpWebResponse;
                                if (response != null)
                                {
                                    Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                                    if (response.StatusCode == HttpStatusCode.Forbidden)
                                    {
                                        try
                                        {
                                            if (pb.IsShowing)
                                            {
                                                pb.Dismiss();
                                            }
                                            Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show();
                                            System.Diagnostics.Debug.WriteLine("We are about to logout");
                                            AccountStorage.ClearStorage();
                                            System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                            System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount);
                                            System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                            Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                            System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount);
                                            ((MainActivity)(Activity)).SetDrawerState(false);
                                            ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login);
                                        }
                                        catch (System.Exception e)
                                        {
                                            System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    // no http status code available
                                    Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                                }
                            }
                            else
                            {
                                // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                            }
                        }
                        catch (StatusNotOkayException)
                        {
                            output[2].value      = "-";
                            taskComplete.Checked = false;
                            Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show();
                        }
                        catch (Exception)
                        {
                            // For any other weird exceptions
                            taskComplete.Checked = false;
                            output[2].value      = "-";
                            Toast.MakeText(Activity, "Unable to make the change. Please try again.", ToastLength.Short).Show();
                        }

                        text = "Task Marked Complete";
                    }
                    else
                    {
                        var previousValue = output[2].value;
                        // Unmark the task
                        taskDetail.CompletionDate = null;

                        try
                        {
                            ((MainActivity)(this.Activity)).Ctrl.UpdateATask(AccountStorage.DataSet,
                                                                             _taskId, null, null, true);

                            output[2].value = "-";
                        }
                        catch (CannotReachServerException)
                        {
                            taskComplete.Checked = true;
                            output[2].value      = previousValue;
                            Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show();
                        }
                        catch (WebException we)
                        {
                            if (we.Status == WebExceptionStatus.ProtocolError)
                            {
                                var response = we.Response as HttpWebResponse;
                                if (response != null)
                                {
                                    Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                                    if (response.StatusCode == HttpStatusCode.Forbidden)
                                    {
                                        try
                                        {
                                            if (pb.IsShowing)
                                            {
                                                pb.Dismiss();
                                            }
                                            Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show();
                                            System.Diagnostics.Debug.WriteLine("We are about to logout");
                                            AccountStorage.ClearStorage();
                                            System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                            System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount);
                                            System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                            Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                            System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount);
                                            ((MainActivity)(Activity)).SetDrawerState(false);
                                            ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login);
                                        }
                                        catch (System.Exception e)
                                        {
                                            System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    // no http status code available
                                    Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                                }
                            }
                            else
                            {
                                // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                            }
                        }
                        catch (StatusNotOkayException)
                        {
                            taskComplete.Checked = true;
                            output[2].value      = previousValue;
                            Toast.MakeText(Activity, "An error has occured. Please try again.", ToastLength.Short).Show();
                        }
                        catch (Exception)
                        {
                            // For any other weird exceptions
                            taskComplete.Checked = true;
                            output[2].value      = previousValue;
                            Toast.MakeText(Activity, "Unable to make the change. Please try again.", ToastLength.Short).Show();
                        }

                        text = "Task Marked Incomplete";
                    }
                    listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem, output);
                    Debug.WriteLine("We have changed content ");
                    timeinfo.Adapter = listAdapter;
                    Toast.MakeText(Activity, text, ToastLength.Short).Show();
                    // await (((MainActivity)(Activity)).Ctrl).UpdateTimeLog(Settings.GetInstance().Dataset,)
                };
            }
            if (pb.IsShowing)
            {
                pb.Dismiss();
            }

            // Dismiss Dialog
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            Debug.WriteLine("Time Log Detail : " + "We are in On create view");

            // Use this to return your custom view for this Fragment
            var v = inflater.Inflate(Resource.Layout.TimeLogEntry, container, false);

            _tn            = v.FindViewById <TextView>(Resource.Id.TimeLogEdit_TaskName);
            _pn            = v.FindViewById <TextView>(Resource.Id.TimeLogEdit_ProjectName);
            _interruptTime = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_InterruptTime);
            _comment       = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_Comment);
            _startTime     = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_StartTime);
            _deltaTime     = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_DeltaTime);

            _startTime.Focusable     = false;
            _deltaTime.Focusable     = false;
            _interruptTime.Focusable = false;
            _comment.Focusable       = false;

            _startTime.Clickable     = true;
            _deltaTime.Clickable     = true;
            _interruptTime.Clickable = true;
            _comment.Clickable       = true;

            if (_timeLog != null)
            {
                _oldLoggedTime    = _timeLog.LoggedTime;
                _oldInterruptTime = _timeLog.InterruptTime;
            }
            else
            {
                _oldLoggedTime    = 0;
                _oldInterruptTime = 0;
            }


            _deltaTime.Click += (sender, args) =>
            {
                LinearLayout ll = new LinearLayout(Activity);
                ll.Orientation = (Orientation.Horizontal);

                NumberPicker aNumberPicker = new NumberPicker(Activity);
                // TODO: Should there be a maximum for the hour column ?
                aNumberPicker.MaxValue = (100);
                aNumberPicker.MinValue = (0);

                double temp = 0;
                if (!_deltaTime.Text.Equals(""))
                {
                    temp = Convert.ToDouble(TimeSpan.ParseExact(_deltaTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes);
                }

                //temp = Double.Parse(_deltaTime.Text);

                aNumberPicker.Value = TimeSpan.FromMinutes(temp).Hours;

                NumberPicker aNumberPickerA = new NumberPicker(Activity)
                {
                    MaxValue = (59),
                    MinValue = (0),
                    Value    = TimeSpan.FromMinutes(temp).Minutes
                };


                LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(50, 50);
                parameters.Gravity = GravityFlags.Center;

                LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                numPicerParams.Weight = 1;

                LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                qPicerParams.Weight = 1;

                ll.LayoutParameters = parameters;
                ll.AddView(aNumberPicker, numPicerParams);
                ll.AddView(aNumberPickerA, qPicerParams);


                AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll);

                np.SetTitle("Update Delta Time");
                np.SetNegativeButton("Cancel", (s, a) =>
                {
                    np.Dispose();
                });

                np.SetPositiveButton("Ok", (s, a) =>
                {
                    //Update Planned Time
                    string number = aNumberPicker.Value.ToString("D2") + ":" + aNumberPickerA.Value.ToString("D2");
                    Debug.WriteLine(number);
                    double val = Convert.ToDouble(TimeSpan.ParseExact(number, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes);
                    Debug.WriteLine("The updated val is :" + val);
                    var updatedLoggedTime = val - _oldLoggedTime;
                    try
                    {
                        if (_timeLog != null)
                        {
                            ((MainActivity)Activity).Ctrl.UpdateTimeLog(AccountStorage.DataSet, "" + _timeLog.Id, null, null, _taskId, updatedLoggedTime, null, false);
                        }
                    }
                    catch (CannotReachServerException)
                    {
                        AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                        builder.SetTitle("Unable to Connect")
                        .SetMessage("Please check your network connection and try again")
                        .SetNeutralButton("Okay", (sender2, args2) =>
                        {
                            builder.Dispose();
                            ((MainActivity)Activity).FragmentManager.PopBackStack();
                        })
                        .SetCancelable(false);
                        AlertDialog alert = builder.Create();
                        alert.Show();
                    }
                    catch (WebException we)
                    {
                        if (we.Status == WebExceptionStatus.ProtocolError)
                        {
                            var response = we.Response as HttpWebResponse;
                            if (response != null)
                            {
                                Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                                if (response.StatusCode == HttpStatusCode.Forbidden)
                                {
                                    try
                                    {
                                        Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show();
                                        System.Diagnostics.Debug.WriteLine("We are about to logout");
                                        AccountStorage.ClearStorage();
                                        System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                        System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount);
                                        System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                        Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                        System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount);
                                        ((MainActivity)(Activity)).SetDrawerState(false);
                                        ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login);
                                    }
                                    catch (System.Exception e)
                                    {
                                        System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                                    }
                                }
                            }
                            else
                            {
                                // no http status code available
                                Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                            }
                        }
                        else
                        {
                            // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                        }
                    }
                    catch (StatusNotOkayException se)
                    {
                        AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                        builder.SetTitle("An Error has occured")
                        .SetMessage("Error :" + se.GetMessage())
                        .SetNeutralButton("Okay", (sender2, args2) =>
                        {
                            builder.Dispose();
                        })
                        .SetCancelable(false);
                        AlertDialog alert = builder.Create();
                        alert.Show();
                    }
                    catch (Exception e)
                    {
                        // For any other weird exceptions
                        AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                        builder.SetTitle("An Error has occured")
                        .SetNeutralButton("Okay", (sender2, args2) =>
                        {
                            builder.Dispose();
                        })
                        .SetMessage("Error :" + e.Message)
                        .SetCancelable(false);
                        AlertDialog alert = builder.Create();
                        alert.Show();
                    }


                    _deltaTime.Text = "" + TimeSpan.FromMinutes(val).ToString(@"hh\:mm");
                    Toast.MakeText(Activity, "Delta Time Updated", ToastLength.Short).Show();
                    np.Dispose();
                });
                np.Show();
            };

            _startTime.Click += (sender, args) =>
            {
                DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time)
                {
                    //TODO: DEBUG: Check whether this is causing any issues.
                    _startTime.Text = time.ToString(CultureInfo.InvariantCulture);
                    Toast.MakeText(Activity, "Start Date Updated", ToastLength.Short).Show();
                    TimePickerFragment frag2 = TimePickerFragment.NewInstance(delegate(int hour, int min)
                    {
                        Toast.MakeText(Activity, "Start Time Updated", ToastLength.Short).Show();
                        DateTime output = new DateTime(time.Year, time.Month, time.Day, hour, min, 0);
                        _startTime.Text = output.ToString("g");
                    });

                    frag2.chosenDate = time;
                    if (_timeLog != null)
                    {
                        frag2.StartHour   = _timeLog.StartDate.Hour;
                        frag2.StartMinute = _timeLog.StartDate.Minute;
                    }
                    else
                    {
                        frag2.StartHour   = time.Hour;
                        frag2.StartMinute = time.Minute;
                    }

                    frag2.Show(FragmentManager, TimePickerFragment.TAG);
                });
                //frag.StartTime = DateTime.SpecifyKind(DateTime.Parse(""+output[2].value), DateTimeKind.Local);

                frag.StartTime = _timeLog != null ? _timeLog.StartDate : DateTime.Now;

                Debug.WriteLine(frag.StartTime);
                frag.Show(FragmentManager, DatePickerFragment.TAG);
            };

            _interruptTime.Click += (sender, args) =>
            {
                LinearLayout ll = new LinearLayout(Activity);
                ll.Orientation = (Orientation.Horizontal);

                NumberPicker aNumberPicker = new NumberPicker(Activity);
                // TODO: Should there be a maximum for the hour column ?
                aNumberPicker.MaxValue = (100);
                aNumberPicker.MinValue = (0);

                double temp = 0;
                if (!_interruptTime.Text.Equals(""))
                {
                    temp = Convert.ToDouble(TimeSpan.ParseExact(_interruptTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes);
                }

                //temp = Double.Parse(_deltaTime.Text);

                aNumberPicker.Value = TimeSpan.FromMinutes(temp).Hours;

                NumberPicker aNumberPickerA = new NumberPicker(Activity)
                {
                    MaxValue = (59),
                    MinValue = (0),
                    Value    = TimeSpan.FromMinutes(temp).Minutes
                };


                LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(50, 50);
                parameters.Gravity = GravityFlags.Center;

                LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                numPicerParams.Weight = 1;

                LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                qPicerParams.Weight = 1;

                ll.LayoutParameters = parameters;
                ll.AddView(aNumberPicker, numPicerParams);
                ll.AddView(aNumberPickerA, qPicerParams);


                AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll);

                np.SetTitle("Update Interrupt Time");
                np.SetNegativeButton("Cancel", (s, a) =>
                {
                    np.Dispose();
                });

                np.SetPositiveButton("Ok", (s, a) =>
                {
                    //Update Planned Time
                    string number = aNumberPicker.Value.ToString("D2") + ":" + aNumberPickerA.Value.ToString("D2");
                    Debug.WriteLine(number);
                    double val = Convert.ToDouble(TimeSpan.ParseExact(number, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes);
                    Debug.WriteLine("The updated val is :" + val);
                    var updatedInterruptTime = val - _oldInterruptTime;
                    if (_timeLog != null)
                    {
                        // This is an update operation
                        try
                        {
                            if (_timeLog != null)
                            {
                                ((MainActivity)Activity).Ctrl.UpdateTimeLog(AccountStorage.DataSet, "" + _timeLog.Id, null,
                                                                            null, _taskId, null, updatedInterruptTime, false);
                            }
                        }
                        catch (CannotReachServerException)
                        {
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                            builder.SetTitle("Unable to Connect")
                            .SetMessage("Please check your network connection and try again")
                            .SetNeutralButton("Okay", (sender2, args2) =>
                            {
                                builder.Dispose();
                                ((MainActivity)Activity).FragmentManager.PopBackStack();
                            })
                            .SetCancelable(false);
                            AlertDialog alert = builder.Create();
                            alert.Show();
                        }
                        catch (WebException we)
                        {
                            if (we.Status == WebExceptionStatus.ProtocolError)
                            {
                                var response = we.Response as HttpWebResponse;
                                if (response != null)
                                {
                                    Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                                    if (response.StatusCode == HttpStatusCode.Forbidden)
                                    {
                                        try
                                        {
                                            Toast.MakeText(this.Activity, "Username and password error.",
                                                           ToastLength.Long).Show();
                                            System.Diagnostics.Debug.WriteLine("We are about to logout");
                                            AccountStorage.ClearStorage();
                                            System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                            System.Diagnostics.Debug.WriteLine("Items in the backstack :" +
                                                                               Activity.FragmentManager
                                                                               .BackStackEntryCount);
                                            System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null);
                                            Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                            System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" +
                                                                               Activity.FragmentManager
                                                                               .BackStackEntryCount);
                                            ((MainActivity)(Activity)).SetDrawerState(false);
                                            ((MainActivity)(Activity)).SwitchToFragment(
                                                MainActivity.FragmentTypes.Login);
                                        }
                                        catch (System.Exception e)
                                        {
                                            System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    // no http status code available
                                    Toast.MakeText(Activity, "Unable to load the data. Please restart the application.",
                                                   ToastLength.Short).Show();
                                }
                            }
                            else
                            {
                                // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                            }
                        }
                        catch (StatusNotOkayException se)
                        {
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                            builder.SetTitle("An Error has occured")
                            .SetMessage("Error :" + se.GetMessage())
                            .SetNeutralButton("Okay", (sender2, args2) =>
                            {
                                builder.Dispose();
                            })
                            .SetCancelable(false);
                            AlertDialog alert = builder.Create();
                            alert.Show();
                        }
                        catch (Exception e)
                        {
                            // For any other weird exceptions
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                            builder.SetTitle("An Error has occured")
                            .SetNeutralButton("Okay", (sender2, args2) =>
                            {
                                builder.Dispose();
                            })
                            .SetMessage("Error :" + e.Message)
                            .SetCancelable(false);
                            AlertDialog alert = builder.Create();
                            alert.Show();
                        }
                    }
                    _interruptTime.Text = "" + TimeSpan.FromMinutes(val).ToString(@"hh\:mm");
                    Toast.MakeText(Activity, "Interrupt Time Updated", ToastLength.Short).Show();
                    np.Dispose();
                });
                np.Show();
            };

            _comment.Click += (sender, args) =>
            {
                LinearLayout ll = new LinearLayout(Activity);
                ll.Orientation = (Orientation.Horizontal);

                EditText et = new EditText(Activity);
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MatchParent,
                    LinearLayout.LayoutParams.WrapContent);
                et.LayoutParameters = lp;
                //et.LayoutParams = (lp);
                ll.AddView(et);

                et.Focusable = (true);


                if (!_comment.Text.Equals("-"))
                {
                    et.Text = _comment.Text;
                }

                AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll);

                np.SetTitle("Update Comments");
                np.SetNegativeButton("Cancel", (s, a) =>
                {
                    np.Dispose();
                });

                np.SetPositiveButton("Ok", (s, a) =>
                {
                    //Update Comments
                    string value = et.Text;
                    if (_timeLog != null)
                    {
                        // This is an update operation
                        try
                        {
                            if (_timeLog != null)
                            {
                                ((MainActivity)Activity).Ctrl.UpdateTimeLog(AccountStorage.DataSet, "" + _timeLog.Id, value,
                                                                            null, _taskId, null, null, false);
                            }
                        }
                        catch (CannotReachServerException)
                        {
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                            builder.SetTitle("Unable to Connect")
                            .SetMessage("Please check your network connection and try again")
                            .SetNeutralButton("Okay", (sender2, args2) =>
                            {
                                builder.Dispose();
                                ((MainActivity)Activity).FragmentManager.PopBackStack();
                            })
                            .SetCancelable(false);
                            AlertDialog alert = builder.Create();
                            alert.Show();
                        }
                        catch (WebException we)
                        {
                            if (we.Status == WebExceptionStatus.ProtocolError)
                            {
                                var response = we.Response as HttpWebResponse;
                                if (response != null)
                                {
                                    Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                                    if (response.StatusCode == HttpStatusCode.Forbidden)
                                    {
                                        try
                                        {
                                            Toast.MakeText(this.Activity, "Username and password error.",
                                                           ToastLength.Long).Show();
                                            AccountStorage.ClearStorage();
                                            Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive);
                                            ((MainActivity)(Activity)).SetDrawerState(false);
                                            ((MainActivity)(Activity)).SwitchToFragment(
                                                MainActivity.FragmentTypes.Login);
                                        }
                                        catch (System.Exception e)
                                        {
                                            System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    // no http status code available
                                    Toast.MakeText(Activity, "Unable to load the data. Please restart the application.",
                                                   ToastLength.Short).Show();
                                }
                            }
                            else
                            {
                                // no http status code available
                                Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show();
                            }
                        }
                        catch (StatusNotOkayException se)
                        {
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                            builder.SetTitle("An Error has occured")
                            .SetMessage("Error :" + se.GetMessage())
                            .SetNeutralButton("Okay", (sender2, args2) =>
                            {
                                builder.Dispose();
                            })
                            .SetCancelable(false);
                            AlertDialog alert = builder.Create();
                            alert.Show();
                        }
                        catch (Exception e)
                        {
                            // For any other weird exceptions
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
                            builder.SetTitle("An Error has occured")
                            .SetNeutralButton("Okay", (sender2, args2) =>
                            {
                                builder.Dispose();
                            })
                            .SetMessage("Error :" + e.Message)
                            .SetCancelable(false);
                            AlertDialog alert = builder.Create();
                            alert.Show();
                        }
                    }

                    _comment.Text = value;
                    Toast.MakeText(Activity, "Comment Updated", ToastLength.Short).Show();
                    np.Dispose();
                });
                np.Show();
            };

            if (_taskName != null && _projectName != null)
            {
                _tn.Text = _taskName;
                _pn.Text = _projectName;
            }

            if (_timeLog == null)
            {
                return(v);
            }

            string c = Util.GetInstance().GetLocalTime(_timeLog.StartDate).ToString("g");

            _startTime.Text     = (c);
            _interruptTime.Text = "" + TimeSpan.FromMinutes(_timeLog.InterruptTime).ToString(@"hh\:mm");
            _comment.Text       = _timeLog.Comment ?? "-";
            _deltaTime.Text     = "" + TimeSpan.FromMinutes(_timeLog.LoggedTime).ToString(@"hh\:mm");

            return(v);
        }
예제 #3
0
        private async void AddData(View view)
        {
            var projectName = view.FindViewById <TextView>(Resource.Id.TaskDetails_ProjectName);
            var taskName    = view.FindViewById <TextView>(Resource.Id.TaskDetails_TaskName);
            var notes       = view.FindViewById <EditText>(Resource.Id.TaskDetails_Notes);
            var timeinfo    = view.FindViewById <ListView>(Resource.Id.TaskDetails_TimeInfo);

            Debug.WriteLine("We are in the begining ");

            var pb = new ProgressDialog(_mActivity)
            {
                Indeterminate = true
            };

            pb.SetTitle("Loading");
            pb.SetCanceledOnTouchOutside(false);
            if (_taskName != null)
            {
                taskName.Text = _taskName;
            }

            if (_projectName != null)
            {
                projectName.Text = _projectName;
            }

            Debug.WriteLine(" 0 ");
            Entry[] output = new Entry[3];

            output[0] = new Entry();
            output[1] = new Entry();
            output[2] = new Entry();

            output[0].name = "Planned Time";

            if (_estimatedTime.HasValue)
            {
                Debug.WriteLine("We have a value in estimated time");
                output[0].value = "" + TimeSpan.FromMinutes(_estimatedTime.Value).ToString(@"hh\:mm");
            }
            else
            {
                Debug.WriteLine("No value in estimated time");
                output[0].value = "";
            }
            Debug.WriteLine(" 1 ");


            output[1].name = "Actual Time";
            if (_actualTime.HasValue)
            {
                output[1].value = "" + TimeSpan.FromMinutes(_actualTime.Value).ToString(@"hh\:mm");
            }
            else
            {
                output[1].value = "";
            }

            output[2].name = "Completion Date";
            Debug.WriteLine(" 2 ");
            if (_completionDate.HasValue)
            {
                output[2].value = Util.GetInstance().GetLocalTime(_completionDate.Value).ToShortDateString();
            }
            else
            {
                output[2].value = "-";
            }

            var listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                     output);


            Debug.WriteLine("We have reached the end ");

            timeinfo.Adapter = listAdapter;

            pb.Show();
            Task taskDetail = null;

            try

            {
                // Get data from server
                taskDetail = await((MainActivity)Activity).Ctrl.GetTask(Settings.GetInstance().Dataset, _taskId);
            }
            catch (CannotReachServerException)
            {
                if (pb.IsShowing)
                {
                    pb.Dismiss();
                }

                Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show();
                Debug.WriteLine("We are going to pop backstack");
                ((MainActivity)Activity).FragmentManager.PopBackStack();
            }
            catch (StatusNotOkayException)
            {
                if (pb.IsShowing)
                {
                    pb.Dismiss();
                }

                Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show();
                Debug.WriteLine("We are going to pop backstack");
                ((MainActivity)Activity).FragmentManager.PopBackStack();
            }
            catch (Exception)
            {
                // For any other weird exceptions
                if (pb.IsShowing)
                {
                    pb.Dismiss();
                }
                Toast.MakeText(Activity, "Invalid values. Please try again.", ToastLength.Short).Show();
                Debug.WriteLine("We are going to pop backstack");
                ((MainActivity)Activity).FragmentManager.PopBackStack();
            }
            if (taskDetail == null)
            {
                Debug.WriteLine("T is null");
            }

            if (taskDetail != null)
            {
                projectName.Text = taskDetail.Project.Name;

                timeinfo.ItemClick += (sender, args) =>
                {
                    if (args.Position == 0)
                    {
                        LinearLayout LL = new LinearLayout(this.Activity);
                        LL.Orientation = (Orientation.Horizontal);

                        NumberPicker aNumberPicker = new NumberPicker(this.Activity);
                        aNumberPicker.MaxValue = (100);
                        aNumberPicker.MinValue = (0);

                        double temp;

                        temp = taskDetail.EstimatedTime;


                        aNumberPicker.Value = TimeSpan.FromMinutes(temp).Hours;

                        NumberPicker aNumberPickerA = new NumberPicker(this.Activity)
                        {
                            MaxValue = (59),
                            MinValue = (0),
                            Value    = TimeSpan.FromMinutes(temp).Minutes
                        };


                        LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(50, 50);
                        parameters.Gravity = GravityFlags.Center;

                        LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                        numPicerParams.Weight = 1;

                        LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                        qPicerParams.Weight = 1;

                        LL.LayoutParameters = parameters;
                        LL.AddView(aNumberPicker, numPicerParams);
                        LL.AddView(aNumberPickerA, qPicerParams);

                        //((TaskDetailsAdapter)(timeinfo.Adapter)).GetEntry()


                        //var ts = DateTime.ParseExact("", "HH.mm", CultureInfo.InvariantCulture);

                        AlertDialog.Builder np = new AlertDialog.Builder(this.Activity).SetView(LL);

                        np.SetTitle("Update Planned Time");
                        np.SetNegativeButton("Cancel", (s, a) =>
                        {
                            np.Dispose();
                        });
                        np.SetPositiveButton("Ok", (s, a) =>
                        {
                            //Update Planned Time
                            string number = aNumberPicker.Value.ToString("D2") + ":" + aNumberPickerA.Value.ToString("D2");
                            System.Diagnostics.Debug.WriteLine(number);
                            double val = Convert.ToDouble(TimeSpan.ParseExact(number, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes);
                            System.Diagnostics.Debug.WriteLine("The updated val is :" + val);
                            try
                            {
                                ((MainActivity)(this.Activity)).Ctrl.UpdateATask(Settings.GetInstance().Dataset,
                                                                                 _taskId, val, null, false);
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine(e.Message);
                            }
                            output[0].value = TimeSpan.FromMinutes(val).ToString(@"hh\:mm");

                            listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                                 output);
                            Debug.WriteLine("We have changed content ");
                            timeinfo.Adapter = listAdapter;

                            Toast.MakeText(_mActivity, "Planned Time Updated", ToastLength.Short).Show();
                            np.Dispose();
                        });
                        np.Show();
                        //Planned Time
                    }
                    else if (args.Position == 1)
                    {
                        //Actual Time
                        ((MainActivity)Activity).PassTimeLogInfo(taskDetail.Id, taskDetail.Project.Name,
                                                                 taskDetail.FullName);
                    }
                    else if (args.Position == 2)
                    {
                        // Completion Date


                        DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time)
                        {
                            System.Diagnostics.Debug.WriteLine("The received date is :" + time.ToShortDateString());

                            output[2].value = time.ToShortDateString();

                            listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                                 output);
                            Debug.WriteLine("We have changed content ");
                            timeinfo.Adapter = listAdapter;

                            try
                            {
                                ((MainActivity)(this.Activity)).Ctrl.UpdateATask(Settings.GetInstance().Dataset,
                                                                                 _taskId, null, Util.GetInstance().GetServerTime(time), false);
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine(e.Message);
                            }


                            Toast.MakeText(_mActivity, "Completion Date Updated", ToastLength.Short).Show();
                        });
                        //frag.StartTime = DateTime.SpecifyKind(DateTime.Parse(""+output[2].value), DateTimeKind.Local);

                        if (taskDetail.CompletionDate.HasValue)
                        {
                            frag.StartTime = Util.GetInstance().GetLocalTime(taskDetail.CompletionDate.Value);
                        }
                        Debug.WriteLine(frag.StartTime);
                        frag.Show(FragmentManager, DatePickerFragment.TAG);
                    }
                };

                taskName.Text   = taskDetail.FullName;
                output[0].value = TimeSpan.FromMinutes(taskDetail.EstimatedTime).ToString(@"hh\:mm");
                output[1].value = TimeSpan.FromMinutes(taskDetail.ActualTime).ToString(@"hh\:mm");
                output[2].value = taskDetail.CompletionDate.HasValue ? Util.GetInstance().GetLocalTime(taskDetail.CompletionDate.Value).ToShortDateString() : "-";
                listAdapter     = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                         output);


                Debug.WriteLine("We have changed content ");

                timeinfo.Adapter = listAdapter;
                if (string.IsNullOrEmpty(taskDetail.Note))
                {
                    notes.Text    = "-";
                    notes.Gravity = GravityFlags.Center;
                }
                else
                {
                    notes.Text = taskDetail.Note;
                }

                var timeLogs = view.FindViewById <Button>(Resource.Id.TaskDetails_TimeLogButton);
                timeLogs.Click +=
                    (sender, args) =>
                {
                    ((MainActivity)Activity).PassTimeLogInfo(taskDetail.Id, taskDetail.Project.Name,
                                                             taskDetail.FullName);
                };

                var taskComplete = view.FindViewById <CheckBox>(Resource.Id.TaskDetails_TaskComplete);

                if (taskDetail.CompletionDate.HasValue && taskDetail.CompletionDate.Value != DateTime.MinValue)
                {
                    taskComplete.Checked = true;
                }
                else
                {
                    taskComplete.Checked = false;
                }
                taskComplete.CheckedChange += (sender, args) =>
                {
                    string text;
                    if (args.IsChecked)
                    {
                        // Mark a task as complete
                        DateTime convertedTime = Util.GetInstance().GetServerTime(DateTime.UtcNow);
                        taskDetail.CompletionDate = convertedTime;

                        try
                        {
                            ((MainActivity)(this.Activity)).Ctrl.UpdateATask(Settings.GetInstance().Dataset,
                                                                             _taskId, null, convertedTime, false);

                            output[2].value = DateTime.Now.ToShortDateString();
                        }
                        catch (CannotReachServerException)
                        {
                            output[2].value      = "-";
                            taskComplete.Checked = false;
                            Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show();
                        }
                        catch (StatusNotOkayException)
                        {
                            output[2].value      = "-";
                            taskComplete.Checked = false;
                            Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show();
                        }
                        catch (Exception)
                        {
                            // For any other weird exceptions
                            taskComplete.Checked = false;
                            output[2].value      = "-";
                            Toast.MakeText(Activity, "Unable to make the change. Please try again.", ToastLength.Short).Show();
                        }

                        text = "Task Marked Complete";
                    }
                    else
                    {
                        var previousValue = output[2].value;
                        // Unmark the task
                        taskDetail.CompletionDate = null;

                        try
                        {
                            ((MainActivity)(this.Activity)).Ctrl.UpdateATask(Settings.GetInstance().Dataset,
                                                                             _taskId, null, null, true);

                            output[2].value = "-";
                        }
                        catch (CannotReachServerException)
                        {
                            taskComplete.Checked = true;
                            output[2].value      = previousValue;
                            Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show();
                        }
                        catch (StatusNotOkayException)
                        {
                            taskComplete.Checked = true;
                            output[2].value      = previousValue;
                            Toast.MakeText(Activity, "An error has occured. Please try again.", ToastLength.Short).Show();
                        }
                        catch (Exception)
                        {
                            // For any other weird exceptions
                            taskComplete.Checked = true;
                            output[2].value      = previousValue;
                            Toast.MakeText(Activity, "Unable to make the change. Please try again.", ToastLength.Short).Show();
                        }

                        text = "Task Marked Incomplete";
                    }
                    listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem,
                                                         output);
                    Debug.WriteLine("We have changed content ");
                    timeinfo.Adapter = listAdapter;
                    Toast.MakeText(Activity, text, ToastLength.Short).Show();
                    // await (((MainActivity)(Activity)).Ctrl).UpdateTimeLog(Settings.GetInstance().Dataset,)
                };
            }
            if (pb.IsShowing)
            {
                pb.Dismiss();
            }

            // Dismiss Dialog
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            Debug.WriteLine("Time Log Detail : " + "We are in On create view");

            // Use this to return your custom view for this Fragment
            var v = inflater.Inflate(Resource.Layout.TimeLogEntry, container, false);

            _tn            = v.FindViewById <TextView>(Resource.Id.TimeLogEdit_TaskName);
            _pn            = v.FindViewById <TextView>(Resource.Id.TimeLogEdit_ProjectName);
            _interruptTime = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_InterruptTime);
            _comment       = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_Comment);
            _startTime     = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_StartTime);
            _deltaTime     = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_DeltaTime);


            _startTime.Click += (sender, args) =>
            {
                DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time)
                {
                    //TODO: DEBUG: Check whether this is causing any issues.
                    _startTime.Text = time.ToString(CultureInfo.InvariantCulture);
                    Toast.MakeText(Activity, "Start Date Updated", ToastLength.Short).Show();
                    TimePickerFragment frag2 = TimePickerFragment.NewInstance(delegate(int hour, int min)
                    {
                        Toast.MakeText(Activity, "Start Time Updated", ToastLength.Short).Show();
                        DateTime output = new DateTime(time.Year, time.Month, time.Day, hour, min, 0);
                        _startTime.Text = output.ToString("g");
                    });

                    if (_timeLog != null)
                    {
                        frag2.StartHour   = _timeLog.StartDate.Hour;
                        frag2.StartMinute = _timeLog.StartDate.Minute;
                    }
                    else
                    {
                        frag2.StartHour   = time.Hour;
                        frag2.StartMinute = time.Minute;
                    }

                    frag2.Show(FragmentManager, TimePickerFragment.TAG);
                });
                //frag.StartTime = DateTime.SpecifyKind(DateTime.Parse(""+output[2].value), DateTimeKind.Local);

                frag.StartTime = _timeLog != null ? _timeLog.StartDate : DateTime.Now;

                Debug.WriteLine(frag.StartTime);
                frag.Show(FragmentManager, DatePickerFragment.TAG);
            };


            if (_timeLog != null)
            {
                _oldLoggedTime    = _timeLog.LoggedTime;
                _oldInterruptTime = _timeLog.InterruptTime;
            }
            else
            {
                _oldLoggedTime    = 0;
                _oldInterruptTime = 0;
            }

            if (_taskName != null && _projectName != null)
            {
                _tn.Text = _taskName;
                _pn.Text = _projectName;
            }

            if (_timeLog == null)
            {
                return(v);
            }

            string c = Util.GetInstance().GetLocalTime(_timeLog.StartDate).ToString("g");

            _startTime.Text     = (c);
            _interruptTime.Text = "" + TimeSpan.FromMinutes(_timeLog.InterruptTime).ToString(@"hh\:mm");
            _comment.Text       = _timeLog.Comment ?? "-";
            _deltaTime.Text     = "" + TimeSpan.FromMinutes(_timeLog.LoggedTime).ToString(@"hh\:mm");
            return(v);
        }