private void RebindDuration() { if (timer != null) { timer.Stop(); timer.Elapsed -= OnDurationElapsed; timer = null; } if (isRunning) { timer = new Timer(1000 - duration.Milliseconds); timer.Elapsed += OnDurationElapsed; timer.Start(); } DurationTextView.Text = TimeEntryModel.GetFormattedDuration(duration); }
private void RebindDuration() { if (DataSource == null || Handle == IntPtr.Zero) { return; } var duration = DataSource.TotalDuration; DurationTextView.Text = TimeEntryModel.GetFormattedDuration(duration); if (DataSource.State == TimeEntryState.Running) { handler.RemoveCallbacks(RebindDuration); handler.PostDelayed(RebindDuration, 1000 - duration.Milliseconds); } else { handler.RemoveCallbacks(RebindDuration); } ShowStopButton(); }
protected override void Rebind() { ResetTrackedObservables(); if (DataSource == null) { return; } rebindCounter++; var model = DataSource; var projectName = "LogCellNoProject".Tr(); var projectColor = Color.Gray; var clientName = String.Empty; if (model.Project != null) { projectName = model.Project.Name; projectColor = UIColor.Clear.FromHex(model.Project.GetHexColor()); if (model.Project.Client != null) { clientName = model.Project.Client.Name; } } projectLabel.TextColor = projectColor; if (projectLabel.Text != projectName) { projectLabel.Text = projectName; SetNeedsLayout(); } if (clientLabel.Text != clientName) { clientLabel.Text = clientName; SetNeedsLayout(); } var taskName = model.Task != null ? model.Task.Name : String.Empty; var taskHidden = String.IsNullOrWhiteSpace(taskName); var description = model.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(); } RebindTags(); var duration = model.GetDuration(); durationLabel.Text = TimeEntryModel.GetFormattedDuration(model.Data); runningImageView.Hidden = model.State != TimeEntryState.Running; if (model.State == TimeEntryState.Running) { // Schedule rebind var counter = rebindCounter; DispatchQueue.MainQueue.DispatchAfter( TimeSpan.FromMilliseconds(1000 - duration.Milliseconds), delegate { if (counter == rebindCounter) { Rebind(); } }); } LayoutIfNeeded(); }