Exemplo n.º 1
0
 public BreakCard()
 {
     InitializeComponent();
     this.WhenAnyValue(x => x.ViewModel)
     .Where(x => x != null)
     .Do(PopulateFromViewModel)
     .Subscribe();
     _timeAccountingContext = CompositionRoot.Resolve <TimeAccountingContext>();
 }
Exemplo n.º 2
0
 public MainViewModel
 (
     INavigationService navigationService,
     TimeAccountingContext timeAccountingContext,
     Func <SettingsViewModel> settingsFactory,
     Func <TimeAccount, double, bool, AccountViewModel> accountFactory,
     Func <HistoryViewModel> historyFactory
 )
 {
     _historyFactory        = historyFactory;
     _accountFactory        = accountFactory;
     _settingsFactory       = settingsFactory;
     _timeAccountingContext = timeAccountingContext;
     _navigationService     = navigationService;
     HistoryCommand         = ReactiveCommand.CreateFromTask(HistoryExecuteAsync);
     CurrentCommand         = ReactiveCommand.CreateFromTask(CurrentExecuteAsync);
     SettingsCommand        = ReactiveCommand.CreateFromTask(SettingsExecuteAsync);
     RateCommand            = ReactiveCommand.CreateFromTask(RateExecuteAsync);
 }
Exemplo n.º 3
0
        public AccountViewModel
        (
            TimeAccount currentAccounting,
            double workedTime,
            bool fromHistory,
            INavigationService navigationService,
            HistoryViewModel historyViewModel,
            MainPage mainPage,
            TimeAccountingContext timeAccountingContext
        )
        {
            ShouldInit             = true;
            FromHistory            = fromHistory;
            _timeAccountingContext = timeAccountingContext;
            _mainPage          = mainPage;
            _historyViewModel  = historyViewModel;
            _navigationService = navigationService;
            _workedTime        = workedTime;
            _currentAccounting = currentAccounting;
            _isTimerStarted    = !currentAccounting.IsClosed;
            IsStarted          = currentAccounting.IsStarted;
            StartWorkTime      = currentAccounting.StartWorkTime;
            if (!_currentAccounting.IsClosed)
            {
                Breaks = currentAccounting.Breaks;
            }
            else
            {
                Breaks = new ObservableCollection <Break>(
                    currentAccounting.Breaks.OrderBy(x => x.StartBreakTime)
                    .Select(@break => new Break
                {
                    EndBreakTime   = @break.EndBreakTime,
                    StartBreakTime = @break.StartBreakTime,
                    TimeAccount    = @break.TimeAccount
                }));
            }

            EndWorkTime = currentAccounting.EndWorkTime;
            WorkDate    = currentAccounting.WorkDate;

            if (!FromHistory)
            {
                InitializationCommand = ReactiveCommand.CreateFromTask(InitializeAsync);
            }

            StartWorkCommand   = ReactiveCommand.Create(() => StartWorkTime = DateTime.Now.TimeOfDay);
            EndWorkCommand     = ReactiveCommand.Create(() => EndWorkTime = DateTime.Now.TimeOfDay);
            AddBreakCommand    = ReactiveCommand.CreateFromTask(AddBreakExecuteAsync);
            SaveCommand        = ReactiveCommand.CreateFromTask(SaveExecuteAsync);
            AllCommand         = ReactiveCommand.CreateFromTask(AllExecuteAsync);
            CurrentCommand     = ReactiveCommand.CreateFromTask(CurrentExecuteAsync);
            DeleteBreakCommand = ReactiveCommand.CreateFromTask <Break, Unit>(async _ =>
            {
                await DeleteBreakExecuteAsync(_);
                return(Unit.Default);
            });

            this.WhenAnyValue(x => x.StartWorkTime)
            .Skip(1)
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Subscribe(async _ => await UpdateStartWorkExecuteAsync());

            this.WhenAnyValue(x => x.EndWorkTime)
            .Skip(1)
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Subscribe(async _ => await UpdateEndWorkExecuteAsync());

            this.WhenAnyValue(x => x.SelectedBreak)
            .Skip(1)
            .Where(x => x != null)
            .InvokeCommand(DeleteBreakCommand);
            Initialize = true;
        }
Exemplo n.º 4
0
 public SettingsViewModel
 (
     INavigationService navigationService,
     TimeAccountingContext timeAccountingContext,
     Func <WorkDaysViewModel> workDaysFactory
 )
 {
     _workDaysFactory       = workDaysFactory;
     _timeAccountingContext = timeAccountingContext;
     _navigationService     = navigationService;
     ClearCommand           = ReactiveCommand.CreateFromTask(ClearExecuteAsync);
     WorkDaysCommand        = ReactiveCommand.CreateFromTask(WorkDaysExecuteAsync);
     DevelopCommand         = ReactiveCommand.CreateFromTask(DevelopExecuteAsync);
     LightCommand           = ReactiveCommand.Create(() =>
     {
         if (!Settings.IsDark)
         {
             return;
         }
         Settings.IsDark = false;
         ThemeService.ChangeToLight();
     });
     DarkCommand = ReactiveCommand.Create(() =>
     {
         if (Settings.IsDark)
         {
             return;
         }
         Settings.IsDark = true;
         ThemeService.ChangeToDark();
     });
     WorkDaysCommand  = ReactiveCommand.CreateFromTask(WorkDaysExecuteAsync);
     InstagramCommand = ReactiveCommand.CreateFromTask(async() =>
     {
         InstagramBackgroundColor = Color.FromHex("#D4F4FF");
         await Task.Delay(150);
         await Browser.OpenAsync(new Uri(BaseValue.CreatorInstagram));
         InstagramBackgroundColor = Color.Transparent;
     });
     VkCommand = ReactiveCommand.CreateFromTask(async() =>
     {
         VkBackgroundColor = Color.FromHex("#D4F4FF");
         await Task.Delay(150);
         await Browser.OpenAsync(new Uri(BaseValue.CreatorVk));
         VkBackgroundColor = Color.Transparent;
     });
     GitCommand = ReactiveCommand.CreateFromTask(async() =>
     {
         GitBackgroundColor = Color.FromHex("#D4F4FF");
         await Task.Delay(150);
         await Browser.OpenAsync(new Uri(BaseValue.CreatorGithub));
         GitBackgroundColor = Color.Transparent;
     });
     SupportCommand = ReactiveCommand.Create(() =>
     {
         var emailMessenger = CrossMessaging.Current.EmailMessenger;
         if (emailMessenger.CanSendEmail)
         {
             emailMessenger.SendEmail(
                 BaseValue.SupportEmail,
                 TranslationCodeExtension.GetTranslation("MessageToSupport"),
                 string.Empty);
         }
     });
 }