Example #1
0
        public MainViewModel(IApplicationRepository applicationRepository, IFunctionalityToggler functionalityToggler, ILogRepository logRepository,
            ILocationRepository locationRepository, IDeviceRepository deviceRepository, ICredentialsRepository credentialsRepository,
            IFirstTimeUserExperienceTracker firstTimeUserExperienceTracker, IActionRepository actionRepository)
        {
            if (applicationRepository == null) throw new ArgumentNullException(nameof(applicationRepository));
            if (functionalityToggler == null) throw new ArgumentNullException(nameof(functionalityToggler));
            if (logRepository == null) throw new ArgumentNullException(nameof(logRepository));
            if (locationRepository == null) throw new ArgumentNullException(nameof(locationRepository));
            if (deviceRepository == null) throw new ArgumentNullException(nameof(deviceRepository));
            if (actionRepository == null) throw new ArgumentNullException(nameof(actionRepository));
            if (credentialsRepository == null) throw new ArgumentNullException(nameof(credentialsRepository));
            if (firstTimeUserExperienceTracker == null) throw new ArgumentNullException(nameof(firstTimeUserExperienceTracker));

            _applicationRepository = applicationRepository;
            _functionalityToggler = functionalityToggler;
            _logRepository = logRepository;
            _locationRepository = locationRepository;
            _deviceRepository = deviceRepository;
            _actionRepository = actionRepository;
            _credentialsRepository = credentialsRepository;
            _firstTimeUserExperienceTracker = firstTimeUserExperienceTracker;

            if (IsInDesignMode)
            {
                IsFirstTimeUserExperience = false;

                Activities = new ObservableCollection<ActivityViewModel>
                {
                    new ActivityViewModel(DateTimeOffset.UtcNow, "Home")
                    {
                        Actions = new List<string> { "switch on Desk lamp", $"Failed to control IFTTT{Environment.NewLine}This is what happened: (NotFound Not Found..." }
                    },
                    new ActivityViewModel(DateTimeOffset.UtcNow.AddDays(-1), "Away")
                    {
                        Actions = new List<string> { "switch off TV", "set to 16°C heating" }
                    },
                    new ActivityViewModel(DateTimeOffset.UtcNow.AddDays(-10), "Home")
                    {
                        Actions = new List<string> { "switch on TV", "set to 16°C heating" }
                    }
                };

                IsFirstTimeUserExperienceHomeStep = true;
            }
            else
            {
                Activities = new ObservableCollection<ActivityViewModel>();
            }

            UpdateFirstTimeUserExperienceCommand = new TransactionalCommandTask(UpdateFirstTimeUserExperience);
            NavigateToSettingsCommand = new RelayCommand(NavigateToSettings);
        }
        public SettingsViewModel(IFunctionalityToggler functionalityToggler,
            IApplicationRepository applicationRepository, ILocationRepository locationRepository, IDeviceRepository deviceRepository)
        {
            if (functionalityToggler == null) throw new ArgumentNullException(nameof(functionalityToggler));
            if (applicationRepository == null) throw new ArgumentNullException(nameof(applicationRepository));
            if (locationRepository == null) throw new ArgumentNullException(nameof(locationRepository));
            if (deviceRepository == null) throw new ArgumentNullException(nameof(deviceRepository));

            _functionalityToggler = functionalityToggler;
            _applicationRepository = applicationRepository;
            _locationRepository = locationRepository;
            _deviceRepository = deviceRepository;

            EnableCommand = new TransactionalCommandTask(Enable, () => CanExecute);
            EnableCommand.CanExecuteChanged += (s, e) => CanExecute = !EnableCommand.IsExecuting;

            CanExecute = true;
            
            if (IsInDesignMode)
                IsEnabled = true;

            MessengerInstance.Register<HomeLocationChanged>(this, async t => await DispatcherHelper.RunAsync(() => IsHomeLocationSet = true));
        }
        public SettingsViewModel(IFunctionalityToggler functionalityToggler,
                                 IApplicationRepository applicationRepository, ILocationRepository locationRepository, IDeviceRepository deviceRepository)
        {
            if (functionalityToggler == null)
            {
                throw new ArgumentNullException(nameof(functionalityToggler));
            }
            if (applicationRepository == null)
            {
                throw new ArgumentNullException(nameof(applicationRepository));
            }
            if (locationRepository == null)
            {
                throw new ArgumentNullException(nameof(locationRepository));
            }
            if (deviceRepository == null)
            {
                throw new ArgumentNullException(nameof(deviceRepository));
            }

            _functionalityToggler  = functionalityToggler;
            _applicationRepository = applicationRepository;
            _locationRepository    = locationRepository;
            _deviceRepository      = deviceRepository;

            EnableCommand = new TransactionalCommandTask(Enable, () => CanExecute);
            EnableCommand.CanExecuteChanged += (s, e) => CanExecute = !EnableCommand.IsExecuting;

            CanExecute = true;

            if (IsInDesignMode)
            {
                IsEnabled = true;
            }

            MessengerInstance.Register <HomeLocationChanged>(this, async t => await DispatcherHelper.RunAsync(() => IsHomeLocationSet = true));
        }
Example #4
0
        public MainViewModel(IApplicationRepository applicationRepository, IFunctionalityToggler functionalityToggler, ILogRepository logRepository,
                             ILocationRepository locationRepository, IDeviceRepository deviceRepository, ICredentialsRepository credentialsRepository,
                             IFirstTimeUserExperienceTracker firstTimeUserExperienceTracker, IActionRepository actionRepository)
        {
            if (applicationRepository == null)
            {
                throw new ArgumentNullException(nameof(applicationRepository));
            }
            if (functionalityToggler == null)
            {
                throw new ArgumentNullException(nameof(functionalityToggler));
            }
            if (logRepository == null)
            {
                throw new ArgumentNullException(nameof(logRepository));
            }
            if (locationRepository == null)
            {
                throw new ArgumentNullException(nameof(locationRepository));
            }
            if (deviceRepository == null)
            {
                throw new ArgumentNullException(nameof(deviceRepository));
            }
            if (actionRepository == null)
            {
                throw new ArgumentNullException(nameof(actionRepository));
            }
            if (credentialsRepository == null)
            {
                throw new ArgumentNullException(nameof(credentialsRepository));
            }
            if (firstTimeUserExperienceTracker == null)
            {
                throw new ArgumentNullException(nameof(firstTimeUserExperienceTracker));
            }

            _applicationRepository          = applicationRepository;
            _functionalityToggler           = functionalityToggler;
            _logRepository                  = logRepository;
            _locationRepository             = locationRepository;
            _deviceRepository               = deviceRepository;
            _actionRepository               = actionRepository;
            _credentialsRepository          = credentialsRepository;
            _firstTimeUserExperienceTracker = firstTimeUserExperienceTracker;

            if (IsInDesignMode)
            {
                IsFirstTimeUserExperience = false;

                Activities = new ObservableCollection <ActivityViewModel>
                {
                    new ActivityViewModel(DateTimeOffset.UtcNow, "Home")
                    {
                        Actions = new List <string> {
                            "switch on Desk lamp", $"Failed to control IFTTT{Environment.NewLine}This is what happened: (NotFound Not Found..."
                        }
                    },
                    new ActivityViewModel(DateTimeOffset.UtcNow.AddDays(-1), "Away")
                    {
                        Actions = new List <string> {
                            "switch off TV", "set to 16°C heating"
                        }
                    },
                    new ActivityViewModel(DateTimeOffset.UtcNow.AddDays(-10), "Home")
                    {
                        Actions = new List <string> {
                            "switch on TV", "set to 16°C heating"
                        }
                    }
                };

                IsFirstTimeUserExperienceHomeStep = true;
            }
            else
            {
                Activities = new ObservableCollection <ActivityViewModel>();
            }

            UpdateFirstTimeUserExperienceCommand = new TransactionalCommandTask(UpdateFirstTimeUserExperience);
            NavigateToSettingsCommand            = new RelayCommand(NavigateToSettings);
        }