Exemplo n.º 1
0
 private async Task RemoveItemPermanentlyAsync(ITimeEntryHolder holder)
 {
     if (holder != null)
     {
         await holder.DeleteAsync();
     }
 }
Exemplo n.º 2
0
        public async Task RemoveItemWithUndoAsync(ITimeEntryHolder timeEntryHolder)
        {
            if (timeEntryHolder == null)
            {
                return;
            }

            // Remove previous if exists
            if (lastRemovedItem != null)
            {
                await RemoveItemPermanentlyAsync(lastRemovedItem);
            }

            if (timeEntryHolder.Data.State == TimeEntryState.Running)
            {
                await TimeEntryModel.StopAsync(timeEntryHolder.Data);
            }
            lastRemovedItem = timeEntryHolder;

            // Remove item only from list
            subject.OnNext(new TimeEntryMessage(timeEntryHolder.Data, DataAction.Delete));

            // Create Undo timer
            if (undoTimer != null)
            {
                undoTimer.Elapsed -= OnUndoTimeFinished;
                undoTimer.Close();
            }
            // Using the correct timer.
            undoTimer           = new System.Timers.Timer((UndoSecondsInterval + 1) * 1000);
            undoTimer.AutoReset = false;
            undoTimer.Elapsed  += OnUndoTimeFinished;
            undoTimer.Start();
        }
Exemplo n.º 3
0
 public void RestoreItemFromUndo()
 {
     if (lastRemovedItem != null)
     {
         subject.OnNext(new TimeEntryMessage(lastRemovedItem.Data, DataAction.Put));
         lastRemovedItem = null;
     }
 }
Exemplo n.º 4
0
        public TimeEntryGroup (TimeEntryData data, ITimeEntryHolder previous = null)
        {
            var previous2 = previous as TimeEntryGroup;
            if (previous2 != null) {
                Group = previous2.Group.ReplaceOrAppend (data, x => x.Id == data.Id)
                        .OrderByDescending (x => x.StartTime).ToList ();

                // Recycle entry info if possible
                Info = previous2.Data.Id == Data.Id ? previous2.Info : null;
            } else {
                Group = new List<TimeEntryData> { data };
            }
        }
Exemplo n.º 5
0
            private void RebindTags(ITimeEntryHolder dataSource)
            {
                var hasTags    = dataSource.Info.NumberOfTags > 0;
                var isBillable = dataSource.Info.IsBillable;

                if (hasTags && isBillable)
                {
                    billableTagsImageView.Apply(Style.Log.BillableAndTaggedEntry);
                }
                else if (hasTags)
                {
                    billableTagsImageView.Apply(Style.Log.TaggedEntry);
                }
                else if (isBillable)
                {
                    billableTagsImageView.Apply(Style.Log.BillableEntry);
                }
                else
                {
                    billableTagsImageView.Apply(Style.Log.PlainEntry);
                }
            }
Exemplo n.º 6
0
        private async void OnUndoTimeFinished(object sender, System.Timers.ElapsedEventArgs e)
        {
            await RemoveItemPermanentlyAsync(lastRemovedItem);

            lastRemovedItem = null;
        }
Exemplo n.º 7
0
            public void Bind(ITimeEntryHolder dataSource, Action <TimeEntryCell> OnContinueAction)
            {
                this.OnContinueAction = OnContinueAction;

                var projectName  = "LogCellNoProject".Tr();
                var projectColor = Color.Gray;
                var clientName   = string.Empty;
                var info         = dataSource.Info;

                if (!string.IsNullOrWhiteSpace(info.ProjectData.Name))
                {
                    projectName  = info.ProjectData.Name;
                    projectColor = UIColor.Clear.FromHex(ProjectModel.HexColors [info.ProjectData.Color % ProjectModel.HexColors.Length]);

                    if (!string.IsNullOrWhiteSpace(info.ClientData.Name))
                    {
                        clientName = info.ClientData.Name;
                    }
                }

                projectLabel.TextColor = projectColor;
                if (projectLabel.Text != projectName)
                {
                    projectLabel.Text = projectName;
                    SetNeedsLayout();
                }
                if (clientLabel.Text != clientName)
                {
                    clientLabel.Text = clientName;
                    SetNeedsLayout();
                }

                var taskName    = info.TaskData.Name;
                var taskHidden  = string.IsNullOrWhiteSpace(taskName);
                var description = info.Description;
                var descHidden  = string.IsNullOrWhiteSpace(description);

                if (taskHidden && descHidden)
                {
                    description = "LogCellNoDescription".Tr();
                    descHidden  = false;
                }
                var taskDeskSepHidden = taskHidden || descHidden;

                if (taskLabel.Hidden != taskHidden || taskLabel.Text != taskName)
                {
                    taskLabel.Hidden = taskHidden;
                    taskLabel.Text   = taskName;
                    SetNeedsLayout();
                }
                if (descriptionLabel.Hidden != descHidden || descriptionLabel.Text != description)
                {
                    descriptionLabel.Hidden = descHidden;
                    descriptionLabel.Text   = description;
                    SetNeedsLayout();
                }
                if (taskSeparatorImageView.Hidden != taskDeskSepHidden)
                {
                    taskSeparatorImageView.Hidden = taskDeskSepHidden;
                    SetNeedsLayout();
                }

                // Set duration
                duration  = dataSource.GetDuration();
                isRunning = dataSource.Data.State == TimeEntryState.Running;

                RebindTags(dataSource);
                RebindDuration();
                LayoutIfNeeded();
            }
Exemplo n.º 8
0
            public void Bind(ITimeEntryHolder datasource)
            {
                DataSource = datasource;

                if (DataSource == null || Handle == IntPtr.Zero)
                {
                    return;
                }

                var color = Color.Transparent;
                var ctx   = ServiceContainer.Resolve <Context> ();

                var info = DataSource.Info;

                if (!String.IsNullOrWhiteSpace(info.ProjectData.Name))
                {
                    color = Color.ParseColor(ProjectModel.HexColors [info.Color % ProjectModel.HexColors.Length]);
                    ProjectTextView.SetTextColor(color);
                    ProjectTextView.Text = info.ProjectData.Name;
                }
                else
                {
                    ProjectTextView.Text = ctx.GetString(Resource.String.RecentTimeEntryNoProject);
                    ProjectTextView.SetTextColor(ctx.Resources.GetColor(Resource.Color.dark_gray_text));
                }

                if (String.IsNullOrWhiteSpace(info.ClientData.Name))
                {
                    ClientTextView.Text       = String.Empty;
                    ClientTextView.Visibility = ViewStates.Gone;
                }
                else
                {
                    ClientTextView.Text       = String.Format("{0} • ", info.ClientData.Name);
                    ClientTextView.Visibility = ViewStates.Visible;
                }

                if (String.IsNullOrWhiteSpace(info.TaskData.Name))
                {
                    TaskTextView.Text       = String.Empty;
                    TaskTextView.Visibility = ViewStates.Gone;
                }
                else
                {
                    TaskTextView.Text       = String.Format("{0} • ", info.TaskData.Name);
                    TaskTextView.Visibility = ViewStates.Visible;
                }

                if (String.IsNullOrWhiteSpace(info.Description))
                {
                    DescriptionTextView.Text = ctx.GetString(Resource.String.RecentTimeEntryNoDescription);
                }
                else
                {
                    DescriptionTextView.Text = info.Description;
                }

                BillableView.Visibility = info.IsBillable ? ViewStates.Visible : ViewStates.Gone;


                var shape = ColorView.Background as GradientDrawable;

                if (shape != null)
                {
                    shape.SetColor(color);
                }

                RebindTags();
                RebindDuration();
            }
Exemplo n.º 9
0
            public void Bind(ITimeEntryHolder datasource)
            {
                if (datasource == null || Handle == IntPtr.Zero)
                {
                    return;
                }

                var color = Color.Transparent;
                var ctx   = ServiceContainer.Resolve <Context> ();

                var authManager = ServiceContainer.Resolve <AuthManager> ();

                if (authManager.OfflineMode || (datasource.Data.RemoteId.HasValue && !datasource.Data.IsDirty))
                {
                    NotSyncedView.Visibility = ViewStates.Gone;
                }
                else
                {
                    NotSyncedView.Visibility = ViewStates.Visible;
                }
                var notSyncedShape = NotSyncedView.Background as GradientDrawable;

                if (datasource.Data.IsDirty && datasource.Data.RemoteId.HasValue)
                {
                    notSyncedShape.SetColor(ctx.Resources.GetColor(Resource.Color.light_gray));
                }
                else
                {
                    notSyncedShape.SetColor(ctx.Resources.GetColor(Resource.Color.material_red));
                }

                var info = datasource.Info;

                if (!string.IsNullOrWhiteSpace(info.ProjectData.Name))
                {
                    color = Color.ParseColor(ProjectModel.HexColors [info.Color % ProjectModel.HexColors.Length]);
                    ProjectTextView.SetTextColor(color);
                    ProjectTextView.Text = info.ProjectData.Name;
                }
                else
                {
                    ProjectTextView.Text = ctx.GetString(Resource.String.RecentTimeEntryNoProject);
                    ProjectTextView.SetTextColor(ctx.Resources.GetColor(Resource.Color.dark_gray_text));
                }

                if (string.IsNullOrWhiteSpace(info.ClientData.Name))
                {
                    ClientTextView.Text       = string.Empty;
                    ClientTextView.Visibility = ViewStates.Gone;
                }
                else
                {
                    ClientTextView.Text       = string.Format("{0} • ", info.ClientData.Name);
                    ClientTextView.Visibility = ViewStates.Visible;
                }

                if (string.IsNullOrWhiteSpace(info.TaskData.Name))
                {
                    TaskTextView.Text       = string.Empty;
                    TaskTextView.Visibility = ViewStates.Gone;
                }
                else
                {
                    TaskTextView.Text       = string.Format("{0} • ", info.TaskData.Name);
                    TaskTextView.Visibility = ViewStates.Visible;
                }

                if (string.IsNullOrWhiteSpace(info.Description))
                {
                    DescriptionTextView.Text = ctx.GetString(Resource.String.RecentTimeEntryNoDescription);
                }
                else
                {
                    DescriptionTextView.Text = info.Description;
                }

                BillableView.Visibility = info.IsBillable ? ViewStates.Visible : ViewStates.Gone;

                var shape = ColorView.Background as GradientDrawable;

                if (shape != null)
                {
                    shape.SetColor(color);
                }

                // Show start/stop btn
                if (datasource.Data.State == TimeEntryState.Running)
                {
                    ContinueImageButton.SetImageResource(Resource.Drawable.IcStop);
                }
                else
                {
                    ContinueImageButton.SetImageResource(Resource.Drawable.IcPlayArrowGrey);
                }

                // Set tag number
                var numberOfTags = datasource.Info.NumberOfTags;

                TagsView.BubbleCount = numberOfTags;
                TagsView.Visibility  = numberOfTags > 0 ? ViewStates.Visible : ViewStates.Gone;

                // Set duration
                duration  = datasource.GetDuration();
                isRunning = datasource.Data.State == TimeEntryState.Running;
                RebindDuration();
            }