示例#1
0
 public TaskAdapter(Activity context, DateTime date, IElmaTaskProvider taskProvider)
 {
     _context      = context;
     _taskProvider = taskProvider;
     _date         = date;
     _tasks        = _taskProvider.GetTasksForDate(_date).ToList();
 }
示例#2
0
 private async Task <IEnumerable <IElmaTask> > GetTaskListForDateAsync()
 {
     return(await Task.Run(() => _taskProvider.GetTasksForDate(_currentDate)));
 }
示例#3
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            _tasks = _taskProvider.GetTasksForDate(_date).ToList();
            var task         = _tasks[position];
            var loggingState = task.LoggingState;
            var image        = loggingState == TaskLoggingState.Logging
                            ? Android.Resource.Drawable.IcMediaPause
                            : Android.Resource.Drawable.IcMediaPlay;

            var init = false;

            if (null == convertView)
            {
                convertView = _context.LayoutInflater.Inflate(Resource.Layout.TaskRowView, null);
                init        = true;
            }

            FindViews(convertView);

            _taskSubjectTextView.Text = task.Subject;
            _tillDateTextView.Text    = $"Till {task.EndDateTime}";

            double?hours = null;

            if (task.PlannedWorkTime != null)
            {
                hours = task.FactWorkTime == null
                            ? task.PlannedWorkTime.Value.TotalHours
                            : (task.PlannedWorkTime.Value - task.FactWorkTime.Value).TotalHours;
            }
            if (null != hours)
            {
                _remainingTimeTextView.Visibility = ViewStates.Visible;
                _remainingTimeTextView.Text       = $"{(int) hours} hours remaining";
            }
            else
            {
                _remainingTimeTextView.Visibility = ViewStates.Invisible;
            }

            // TODO: replace seconds with hours and minutes
            if (null != task.UnaccountedWorkTime)
            {
                _unaccountedLayout.Visibility     = ViewStates.Visible;
                _unaccountedWorkTimeTextView.Text = ((int)task.UnaccountedWorkTime?.TotalSeconds).ToString();
            }
            else
            {
                _unaccountedLayout.Visibility = ViewStates.Invisible;
            }
            _taskLoggingStateButton.SetBackgroundResource(image);

            if (init)
            {
                _taskLoggingStateButton.Click += delegate {
                    if (task.LoggingState == TaskLoggingState.NotLogging || task.LoggingState == TaskLoggingState.Paused)
                    {
                        _taskProvider.StartTaskExecution(task);
                        _taskLoggingStateButton.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause);
                    }
                    else
                    {
                        _taskProvider.PauseTaskExecution(task);
                        _taskLoggingStateButton.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay);
                    }
                };

                _sendWorklogButton.Click += delegate {
                    var transaction = _context.FragmentManager.BeginTransaction();
                    var dialog      = new SendWorklogDialogFragment(task, _taskProvider);
                    dialog.Show(transaction, "");
                };
            }

            return(convertView);
        }