public LoginPageViewModel( ILoggingService logging, INavigationService navigation, IPlatformSpecific device, IWallabagClient client, IApiClientCreationService apiService, SQLiteConnection database) { _loggingService = logging; _navigationService = navigation; _device = device; _client = client; _apiClientService = apiService; _database = database; _loggingService.WriteLine("Creating new instance of LoginPageViewModel."); Providers = new List <WallabagProvider>() { new WallabagProvider(new Uri("https://framabag.org"), "framabag", _device.GetLocalizedResource("FramabagProviderDescription")), new WallabagProvider(new Uri("https://app.wallabag.it"), "wallabag.it", _device.GetLocalizedResource("WallabagItProviderDescription")), WallabagProvider.GetOther(_device) }; PreviousCommand = new RelayCommand(() => Previous(), () => PreviousCanBeExecuted()); NextCommand = new RelayCommand(async() => await NextAsync(), () => NextCanBeExecuted()); RegisterCommand = new RelayCommand(() => _device.LaunchUri((SelectedProvider as WallabagProvider).Url.Append("/register")), () => RegistrationCanBeExecuted()); WhatIsWallabagCommand = new RelayCommand(() => _device.LaunchUri(new Uri("vimeo://v/167435064"), new Uri("https://vimeo.com/167435064"))); ScanQRCodeCommand = new RelayCommand(() => _navigationService.Navigate(Navigation.Pages.QRScanPage)); this.PropertyChanged += This_PropertyChanged; }
public override async Task ActivateAsync(object parameter, IDictionary <string, object> state, NavigationMode mode) { CameraIsSupported = await _device.GetHasCameraAsync(); _loggingService.WriteLine($"Camera is supported: {CameraIsSupported}"); if (state.Count > 0) { _loggingService.WriteLine("PageState.Count was greater than zero. Restoring."); _loggingService.WriteObject(state); Username = state[nameof(Username)] as string; Password = state[nameof(Password)] as string; Url = state[nameof(Url)] as string; ClientId = state[nameof(ClientId)] as string; ClientSecret = state[nameof(ClientSecret)] as string; CurrentStep = (int)state[nameof(CurrentStep)]; UseCustomSettings = (bool?)state[nameof(UseCustomSettings)]; _restoredFromPageState = true; } _loggingService.WriteLine("Checking for navigation parameter."); ProtocolSetupNavigationParameter protocolSetupParameter = null; if (parameter is ProtocolSetupNavigationParameter) { protocolSetupParameter = parameter as ProtocolSetupNavigationParameter; _loggingService.WriteLine($"Parameter existing. Setting it as {nameof(protocolSetupParameter)}."); } if (SessionState.ContainsKey(QRScanPageViewModel.m_QRRESULTKEY)) { _loggingService.WriteLine($"{nameof(SessionState)} contained {QRScanPageViewModel.m_QRRESULTKEY}. Set it as {nameof(protocolSetupParameter)}."); protocolSetupParameter = SessionState[QRScanPageViewModel.m_QRRESULTKEY] as ProtocolSetupNavigationParameter; } if (protocolSetupParameter != null) { _loggingService.WriteLine($"Making use of the {nameof(ProtocolSetupNavigationParameter)}."); Username = protocolSetupParameter.Username; Url = protocolSetupParameter.Server; SelectedProvider = WallabagProvider.GetOther(_device); CurrentStep = 1; } }
public void TheUrlFieldIsVisibleIfTheSelectedProviderUrlIsNotNull() { var logging = A.Fake <ILoggingService>(); var navigation = A.Fake <INavigationService>(); var device = A.Fake <IPlatformSpecific>(); var client = A.Fake <IWallabagClient>(); var apiService = A.Fake <IApiClientCreationService>(); var database = TestsHelper.CreateFakeDatabase(); var viewModel = new LoginPageViewModel(logging, navigation, device, client, apiService, database) { SelectedProvider = WallabagProvider.GetOther(device) }; viewModel.RaisePropertyChanged(nameof(viewModel.SelectedProvider)); Assert.Null(viewModel.SelectedProvider.Url); Assert.True(viewModel.UrlFieldIsVisible); }
public async Task NavigationWithParameterSetsProperties() { var logging = A.Fake <ILoggingService>(); var navigation = A.Fake <INavigationService>(); var device = A.Fake <IPlatformSpecific>(); var client = A.Fake <IWallabagClient>(); var apiService = A.Fake <IApiClientCreationService>(); var database = TestsHelper.CreateFakeDatabase(); var viewModel = new LoginPageViewModel(logging, navigation, device, client, apiService, database); var param = new ProtocolSetupNavigationParameter("user", "http://test.de"); await viewModel.ActivateAsync(param, new Dictionary <string, object>(), Data.Common.NavigationMode.New); Assert.True(WallabagProvider.GetOther(device).Equals(viewModel.SelectedProvider)); Assert.Equal("user", viewModel.Username); Assert.Equal("http://test.de", viewModel.Url); }