private void PopulateFromViewModel(HistoryAccount vm) { DayLbl.Text = Settings.Language.IsNullOrEmptyOrWhiteSpace() ? $"{vm.TimeAccount.WorkDate:M}, {DateService.DayShortName(vm.TimeAccount.WorkDate.DayOfWeek)}" : vm.TimeAccount.WorkDate.ToString("M", CultureInfo.GetCultureInfo(Settings.Language)) + $", {DateService.DayShortName(vm.TimeAccount.WorkDate.DayOfWeek)}"; StartWorkSpn.Text = vm.TimeAccount.StartWorkTime.ToString(@"hh\:mm"); EndWorkSpn.Text = vm.TimeAccount.EndWorkTime.ToString(@"hh\:mm"); if (vm.TimeAccount.Breaks == null || vm.TimeAccount.Breaks.Count == 0) { DinnerStck.IsVisible = false; } else { var orderedBreaks = vm.TimeAccount.Breaks .OrderBy(x => x.StartBreakTime) .ToArray(); for (var i = 0; i < orderedBreaks.Length; i++) { if (i == 0) { DinnerLbl.Text = TimeSpan.FromMinutes(orderedBreaks[i].StartBreakTime).ToString(@"hh\:mm") + " - " + TimeSpan.FromMinutes(orderedBreaks[i].EndBreakTime).ToString(@"hh\:mm"); } else { DinnerLbl.Text += ", " + TimeSpan.FromMinutes(orderedBreaks[i].StartBreakTime).ToString(@"hh\:mm") + " - " + TimeSpan.FromMinutes(orderedBreaks[i].EndBreakTime).ToString(@"hh\:mm"); } } BreakLbl.Text = orderedBreaks.Length > 1 ? TranslationCodeExtension.GetTranslation("BreaksText") : TranslationCodeExtension.GetTranslation("BreakText"); } OverWorkTitle.Text = vm.DayOverWork >= 0 ? TranslationCodeExtension.GetTranslation("OverworkText") + " " : TranslationCodeExtension.GetTranslation("WeaknessesText") + " "; OverWorkLbl.TextColor = vm.DayOverWork >= 0 ? Color.ForestGreen : (Color)Application.Current.Resources["AccentColor"]; OverWorkLbl.Text = TimeSpan.FromMinutes(vm.DayOverWork).ToString(@"hh\:mm"); }
protected override void OnAppearing() { base.OnAppearing(); this.WhenActivated(disposables => { this.BindCommand(ViewModel, vm => vm.StartWorkCommand, v => v.StartWorkBtn); this.BindCommand(ViewModel, vm => vm.EndWorkCommand, v => v.EndWorkBtn); this.BindCommand(ViewModel, vm => vm.AddBreakCommand, v => v.AddDinnerBtn); this.BindCommand(ViewModel, vm => vm.SaveCommand, v => v.SaveBtn); this.BindCommand(ViewModel, vm => vm.AllCommand, v => v.AllGstr); this.BindCommand(ViewModel, vm => vm.CurrentCommand, v => v.CurrentGstr); this.Bind(ViewModel, vm => vm.StartWorkTime, v => v.StartWorkTmPck.Time); this.Bind(ViewModel, vm => vm.EndWorkTime, v => v.EndWorkTmPck.Time); this.OneWayBind(ViewModel, vm => vm.WorkDate, v => v.DateSpn.Text, date => Settings.Language.IsNullOrEmptyOrWhiteSpace() ? $"{date:d}" : date.ToString("d", CultureInfo.GetCultureInfo(Settings.Language))) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.WorkDate, v => v.DaySpn.Text, date => DateService.DayShortName(date.DayOfWeek)) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.CurrentOverWork, v => v.CurrentOverWorkLbl.Text, t => t > default(TimeSpan) ? "-" + t.ToString(@"dd\.hh\:mm\:ss") : t.ToString(@"dd\.hh\:mm\:ss")) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.TotalOverWork, v => v.TotalOverWorkLbl.Text, t => t > default(TimeSpan) ? "-" + t.ToString(@"dd\.hh\:mm\:ss") : t.ToString(@"dd\.hh\:mm\:ss")) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.IsStarted, v => v.SaveBtn.IsVisible) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.IsStarted, v => v.AddDinnerBtn.IsEnabled) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.IsStarted, v => v.AddDinnerBtn.Opacity, v => v ? 1 : 0) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.IsEnable, v => v.LoadingIndic.IsRunning, OppositeConverter.BooleanConverterFunc) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.IsEnable, v => v.LoadingIndic.IsVisible, OppositeConverter.BooleanConverterFunc) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.IsEnable, v => v.LoadingStck.IsVisible, OppositeConverter.BooleanConverterFunc) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.IsEnable, v => v.MainRlt.IsEnabled) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.Breaks, v => v.MainLst.ItemsSource) .DisposeWith(SubscriptionDisposables); this.Bind(ViewModel, vm => vm.SelectedBreak, v => v.MainLst.SelectedItem) .DisposeWith(SubscriptionDisposables); this.WhenAnyValue(x => x.ViewModel.SelectedBreak) .Where(x => x != null) .Subscribe(_ => MainLst.SelectedItem = null) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.FromHistory, v => v.SaveBtn.Text, v => v ? TranslationCodeExtension.GetTranslation("SaveDayButton") : TranslationCodeExtension.GetTranslation("EndDayButton")) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.FromHistory, v => v.DateTitleSpn.Text, v => !v ? TranslationCodeExtension.GetTranslation("CurrentDayText") + " " : TranslationCodeExtension.GetTranslation("SelectedDayText") + " ") .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.FromHistory, v => v.EndStck.IsVisible) .DisposeWith(SubscriptionDisposables); this.OneWayBind(ViewModel, vm => vm.FromHistory, v => v.TimerGrid.IsVisible, OppositeConverter.BooleanConverterFunc) .DisposeWith(SubscriptionDisposables); }); ViewModel.Subscribe(); }