private void Rebind() { if (!isStarted) { return; } rebindCounter++; if (currentTimeEntry == null) { durationButton.SetTitle(DefaultDurationText, UIControlState.Normal); actionButton.Apply(Style.NavTimer.StartButton); } else { var duration = currentTimeEntry.GetDuration(); durationButton.SetTitle(duration.ToString(@"hh\:mm\:ss"), UIControlState.Normal); actionButton.Apply(Style.NavTimer.StopButton); actionButton.Hidden = currentTimeEntry.State != TimeEntryState.Running; var counter = rebindCounter; DispatchQueue.MainQueue.DispatchAfter( TimeSpan.FromMilliseconds(1000 - duration.Milliseconds), delegate { if (counter == rebindCounter) { Rebind(); } }); } }
public override Dialog OnCreateDialog(Bundle state) { if (model != null) { oldDuration = model.GetDuration(); } else { oldDuration = Duration.Zero; } var view = LayoutInflater.From(Activity) .Inflate(Resource.Layout.ChangeTimeEntryDurationDialogFragment, null); DurationTextView = view.FindViewById <TextView> (Resource.Id.DurationTextView).SetFont(Font.Roboto); DeleteImageButton = view.FindViewById <ImageButton> (Resource.Id.DeleteImageButton); Add5Button = view.FindViewById <Button> (Resource.Id.Add5Button).SetFont(Font.RobotoLight); Add30Button = view.FindViewById <Button> (Resource.Id.Add30Button).SetFont(Font.RobotoLight); numButtons [0] = view.FindViewById <Button> (Resource.Id.Num0Button).SetFont(Font.RobotoLight); numButtons [1] = view.FindViewById <Button> (Resource.Id.Num1Button).SetFont(Font.RobotoLight); numButtons [2] = view.FindViewById <Button> (Resource.Id.Num2Button).SetFont(Font.RobotoLight); numButtons [3] = view.FindViewById <Button> (Resource.Id.Num3Button).SetFont(Font.RobotoLight); numButtons [4] = view.FindViewById <Button> (Resource.Id.Num4Button).SetFont(Font.RobotoLight); numButtons [5] = view.FindViewById <Button> (Resource.Id.Num5Button).SetFont(Font.RobotoLight); numButtons [6] = view.FindViewById <Button> (Resource.Id.Num6Button).SetFont(Font.RobotoLight); numButtons [7] = view.FindViewById <Button> (Resource.Id.Num7Button).SetFont(Font.RobotoLight); numButtons [8] = view.FindViewById <Button> (Resource.Id.Num8Button).SetFont(Font.RobotoLight); numButtons [9] = view.FindViewById <Button> (Resource.Id.Num9Button).SetFont(Font.RobotoLight); DeleteImageButton.Click += OnDeleteImageButtonClick; DeleteImageButton.LongClick += OnDeleteImageButtonLongClick; foreach (var numButton in numButtons) { numButton.Click += OnNumButtonClick; } Add5Button.Click += OnAdd5ButtonClick; Add30Button.Click += OnAdd30ButtonClick; return(new AlertDialog.Builder(Activity) .SetTitle(Resource.String.ChangeTimeEntryDurationDialogTitle) .SetView(view) .SetNegativeButton(Resource.String.ChangeTimeEntryDurationDialogCancel, OnCancelClicked) .SetPositiveButton(Resource.String.ChangeTimeEntryDurationDialogOk, OnOkClicked) .Create()); }
public TimeSpan GetTimeEntryListDuration(List <TimeEntryData> timeEntries) { TimeSpan duration = TimeSpan.Zero; foreach (var item in timeEntries) { duration += TimeEntryModel.GetDuration(item, Time.UtcNow); } return(duration); }
private void DurationTimerCallback(object sender, ElapsedEventArgs e) { var duration = TimeEntryModel.GetDuration(data, Time.UtcNow); durationTimer.Interval = 1000 - duration.Milliseconds; // Update on UI Thread ServiceContainer.Resolve <IPlatformUtils> ().DispatchOnUIThread(() => { Duration = string.Format("{0:D2}:{1:mm}:{1:ss}", (int)duration.TotalHours, duration); }); }
private async void LoadData () { model = new TimeEntryModel (TimeEntryId); await model.LoadAsync (); if (model.Workspace == null || model.Workspace.Id == Guid.Empty) { Dismiss (); } else { oldDuration = model.GetDuration (); enabled = true; } }
private void DurationTimerCallback(object sender, ElapsedEventArgs e) { var duration = TimeEntryModel.GetDuration(activeTimeEntryManager.ActiveTimeEntry, Time.UtcNow); //model.GetDuration (); durationTimer.Interval = 1000 - duration.Milliseconds; // Update on UI Thread ServiceContainer.Resolve <IPlatformUtils> ().DispatchOnUIThread(() => { Duration = TimeSpan.FromSeconds(duration.TotalSeconds).ToString().Substring(0, 8); }); }
private async void LoadData() { model = new TimeEntryModel(TimeEntryId); await model.LoadAsync(); if (model.Workspace == null || model.Workspace.Id == Guid.Empty) { Dismiss(); } else { oldDuration = model.GetDuration(); enabled = true; } }
private void Rebind() { if (!canRebind || currentEntry == null) { return; } var res = activity.Resources; if (currentEntry.State == TimeEntryState.New && currentEntry.StopTime.HasValue) { // Save button ActionButton.Text = res.GetString(Resource.String.TimerSaveButtonText); ActionButton.SetBackgroundColor(res.GetColor(Resource.Color.gray)); } else if (currentEntry.State == TimeEntryState.Running) { // Stop button ActionButton.Text = res.GetString(Resource.String.TimerStopButtonText); ActionButton.SetBackgroundColor(res.GetColor(Resource.Color.bright_red)); } else { // Start button ActionButton.Text = res.GetString(Resource.String.TimerStartButtonText); ActionButton.SetBackgroundColor(res.GetColor(Resource.Color.bright_green)); } ActionButton.Visibility = HideAction ? ViewStates.Gone : ViewStates.Visible; if (currentEntry.State == TimeEntryState.Running && !HideDuration) { var duration = currentEntry.GetDuration(); DurationTextView.Text = TimeSpan.FromSeconds((long)duration.TotalSeconds).ToString(); DurationTextView.Visibility = ViewStates.Visible; // Schedule next rebind: handler.RemoveCallbacks(Rebind); handler.PostDelayed(Rebind, 1000 - duration.Milliseconds); } else { DurationTextView.Visibility = ViewStates.Gone; } }
private async void OnOkClicked(object sender, DialogClickEventArgs e) { if (enabled && model != null) { var duration = model.GetDuration(); if (model.State == TimeEntryState.New) { duration = new TimeSpan(newDuration.Hours, newDuration.Minutes, 0); } else { // Keep the current seconds and milliseconds duration = new TimeSpan(0, newDuration.Hours, newDuration.Minutes, duration.Seconds, duration.Milliseconds); } model.SetDuration(duration); await model.SaveAsync(); } }
private void UpdateView() { // Ensure that this content runs in UI thread ServiceContainer.Resolve <IPlatformUtils> ().DispatchOnUIThread(() => { StartDate = data.StartTime == DateTime.MinValue ? DateTime.UtcNow.AddMinutes(-1).ToLocalTime() : data.StartTime.ToLocalTime(); StopDate = data.StopTime.HasValue ? data.StopTime.Value.ToLocalTime() : DateTime.UtcNow.ToLocalTime(); var duration = TimeEntryModel.GetDuration(data, Time.UtcNow); Duration = TimeSpan.FromSeconds(duration.TotalSeconds).ToString().Substring(0, 8); // TODO: check substring function for long times Description = data.Description; WorkspaceId = data.WorkspaceId; if (data.State == TimeEntryState.Running && !IsRunning) { IsRunning = true; durationTimer.Start(); } else if (data.State != TimeEntryState.Running) { IsRunning = false; durationTimer.Stop(); } }); }
private void UpdateView() { // Ensure that this content runs in UI thread ServiceContainer.Resolve <IPlatformUtils> ().DispatchOnUIThread(() => { StartDate = data.StartTime == DateTime.MinValue ? DateTime.UtcNow.AddMinutes(-1).ToLocalTime() : data.StartTime.ToLocalTime(); StopDate = data.StopTime.HasValue ? data.StopTime.Value.ToLocalTime() : DateTime.MaxValue; var duration = TimeEntryModel.GetDuration(data, Time.UtcNow); Duration = string.Format("{0:D2}:{1:mm}:{1:ss}", (int)duration.TotalHours, duration); Description = data.Description; WorkspaceId = data.WorkspaceId; IsBillable = data.IsBillable; if (data.State == TimeEntryState.Running && !IsRunning) { IsRunning = true; durationTimer.Start(); } else if (data.State != TimeEntryState.Running) { IsRunning = false; durationTimer.Stop(); } }); }
public TimeSpan GetDuration() { return(TimeEntryModel.GetDuration(Data, Time.UtcNow)); }
public TimeSpan GetDuration() { return(DataCollection.Aggregate(TimeSpan.Zero, (acc, x) => acc + TimeEntryModel.GetDuration(x, Time.UtcNow))); }