public BaseTabViewModel(ICache <SettingsModel> settings, IPageFactory pageFactory, ILogger <BaseTabViewModel> logger, MainThreadNavigator nav) { _settings = settings; _pageFactory = pageFactory; _logger = logger; _nav = nav; OnAppearingBehavior = new Command(() => { try { if (!_dialogShown && (!_settings.GetAll().Any() || _settings.Get("").DisplayWelcomeMessage)) { _dialogShown = true; _nav.Push(_pageFactory.GetPage(PageType.Instruction, true)); } } catch (Exception ex) { _logger.LogError($"Failed to check settings on load.", ex); } }); }
public InstructionViewModel(MainThreadNavigator nav, ICache <SettingsModel> settings, ILogger <InstructionViewModel> logger, bool showDismissButton) { _nav = nav; _settings = settings; _logger = logger; TitleColHeight = showDismissButton ? 50 : 0; SwitchColHeight = showDismissButton ? 50 : 0; DismissBtnColHeight = showDismissButton ? 50 : 0; DismissCommand = new Command(() => { try { if (NotShowAgain) { _settings.Put("", new SettingsModel() { DisplayWelcomeMessage = false }); } } catch (Exception ex) { _logger.LogError($"Failed to update settings cache.", ex); } _nav.Pop(); }); }
public PurchaseViewModel(IToastService toastService, IPurchasingService purchaseService, ICache <SubscriptionModel> subCache, ISubscriptionService subService, ICurrentUserService userCache, MainThreadNavigator nav, ValidationModel validationModel, string runtimePlatform, Action <BaseNavPageType> navigateFromMenu, AlertUtility alertUtility, Action <Uri> openUri) { _toastService = toastService; _purchaseService = purchaseService; _subCache = subCache; _subService = subService; _userCache = userCache; _validationModel = validationModel; _runtimePlatform = runtimePlatform; _openUri = openUri; _alertUtility = alertUtility; _nav = nav; _navigateFromMenu = navigateFromMenu; LegalLinkCommand = new Command(() => _openUri(new Uri(Configuration.PrivacyPolicyUrl))); PurchaseButtonCommand = new Command(() => PurchaseButtonClicked()); SetVisualState(validationModel); }
public SingleReportPurchaseViewModel(ValidationModel validation, Action <Uri> openUri, string runtimePlatform, AlertUtility alertUtility, MainThreadNavigator nav, IToastService toastService, IPurchasedReportService prService, IPurchasingService purchaseService, ICurrentUserService userCache, ICache <PurchasedReportModel> prCache, ILogger <SingleReportPurchaseViewModel> emailLogger) { _validation = validation; _openUri = openUri; _nav = nav; _toastService = toastService; _runtimePlatform = runtimePlatform; _userCache = userCache; _purchaseService = purchaseService; _prService = prService; _prCache = prCache; _emailLogger = emailLogger; _alertUtility = alertUtility; SetViewState(validation); }
public ManageSubscriptionViewModel(ValidationModel model, string runtimePlatform, Action <Uri> openUri, MainThreadNavigator nav, ILogger <ManageSubscriptionViewModel> logger, IPageFactory pageFactory) { _model = model; _runtimePlatform = runtimePlatform; _openUri = openUri; _nav = nav; _logger = logger; _pageFactory = pageFactory; try { SubscriptionTypeLabel = " " + _model.Subscription.SubscriptionType.ToString(); RemainingOrdersLabel = " " + _model.RemainingOrders.ToString(); PurchasedOrdersLabel = " " + _model.PurchasedReports?.Count.ToString(); EndDateLabel = " " + _model.Subscription.EndDateTime.ToString("dddd, dd MMMM yyyy"); GetMoreReportsLabel = $"Purchase additional reports at a reduced price of ${SubscriptionUtility.GetSingleReportInfo(_model).Price} per report."; GetMoreReportsCommand = new Command(() => _nav.Push(_pageFactory.GetPage(PageType.SingleReportPurchase, _model))); var compName = _runtimePlatform == Device.Android ? "Google" : "Apple"; var supportUri = _runtimePlatform == Device.Android ? "https://support.google.com/googleplay/answer/7018481" : "https://support.apple.com/en-us/HT202039#subscriptions"; DisclaimerLabel = $"NOTE: {compName} does not allow subscriptions to be cancelled through the app. This button will open a web browser with instructions on how to cancel from your device."; CancelSubCommand = new Command(() => _openUri(new Uri(supportUri))); } catch (Exception ex) { _logger.LogError($"Failed to load manage subscription page.", ex); } }
public OrderViewModel(IOrderValidationService validator, ICurrentUserService userCache, IOrderService orderService, IToastService toast, IPageFactory pageFactory, MainThreadNavigator nav, IMessagingSubscriber topicSubscriber, ILogger <OrderViewModel> logger, string deviceType, AlertUtility alertUtility, Action <BaseNavPageType> baseNavigationAction, ICache <Models.Order> orderCache) { _orderValidator = validator; _userService = userCache; _toast = toast; _nav = nav; _orderService = orderService; _pageFactory = pageFactory; _orderCache = orderCache; _alertUtility = alertUtility; _topicSubscriber = topicSubscriber; _baseNavigationAction = baseNavigationAction; _deviceType = deviceType; _logger = logger; PurchaseOptionsCommand = new Command(async() => { var val = await _orderValidator.ValidateOrderRequest(_userService.GetLoggedInAccount()); if (SubscriptionUtility.SubscriptionActive(val.Subscription)) { _nav.Push(_pageFactory.GetPage(PageType.SingleReportPurchase, val)); } else { _nav.Push(_pageFactory.GetPage(PageType.PurchaseOptions, val)); } }); OptionsInfoCommand = new Command(async() => await alertUtility.Display("Roof Option Selection", $"Selecting a roof option allows Fair Squares to determine what roofs you would like measured at the submitted address.{Environment.NewLine}" + $"{Environment.NewLine}Primary Only- Fair Squares will measure the primary structure, including attached garage.{Environment.NewLine}" + $"Detached Garage- Fair Squares will also measure the detached garage on the property.{Environment.NewLine}" + $"Shed/Barn- Fair Squares will also measure a shed or barn on the property.{Environment.NewLine}" + $"{Environment.NewLine}NOTE: Fair Squares only supports measuring one primary structure per report (with a detached garage or shed/barn if needed).", "Ok")); ErrorMessageRowHeight = 0; SelectedOptionIndex = -1; SelectedStateIndex = -1; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed SetVisualStateForValidation(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }
public PurchaseOptionsViewModel(ValidationModel validation, MainThreadNavigator nav, IPageFactory pageFactory) { _validation = validation; _nav = nav; _pageFactory = pageFactory; var freeTrial = new[] { ValidationState.NoSubscriptionAndTrialValid, ValidationState.FreeReportValid }.Contains(validation.State); SubscriptionHeaderText = freeTrial ? "FREE 30 DAY TRIAL AVAILABLE!" : "Become a Subscriber"; SingleReportPrice = $"An additional report gives you access to submit an additional order. Price is ${SubscriptionUtility.IndvReportNoSubPrice} per report."; var ending = freeTrial ? " after 30-day free trial ends." : "."; SubscriptionPrice = $"A subscription plan gives you access to 3 reports every month for $24.99 a month{ending}"; }
public void SetUp() { _userCache = new Mock <ICurrentUserService>(); _validator = new Mock <IOrderValidationService>(); _nav = new Mock <INavigation>(); _logger = new Mock <ILogger <AccountViewModel> >(); _pageFac = new Mock <IPageFactory>(); _mnNav = new MainThreadNavigator(x => x(), _nav.Object); _refresher = new Mock <ICacheRefresher>(); _loginStyle = ""; _subStyle = ""; _loginStyleAction = x => _loginStyle = x; _subStyleAction = x => _subStyle = x; }
public LandingViewModel(OAuth2Authenticator auth, IToastService toastService, ILogger <LandingViewModel> logger, MainThreadNavigator nav) { _auth = auth; _toastService = toastService; _nav = nav; _logger = logger; _auth.Completed += Auth_Completed; _auth.Error += Auth_Error; LoginLayoutVisible = true; GoogleLoginCommand = new Command(() => LoginWithGoogle()); }
public FeedbackViewModel(INotificationService notifier, ICurrentUserService userCache, AlertUtility alertUtility, IPageFactory pageFactory, ILogger <FeedbackViewModel> logger, MainThreadNavigator nav) { _notifier = notifier; _pageFactory = pageFactory; _userCache = userCache; _nav = nav; _logger = logger; _alertUtility = alertUtility; SubmitCommand = new Command(async() => await SubmitFeedback(_feedbackEntry)); }
public void SetUp() { _model = new ValidationModel() { RemainingOrders = 3, State = ValidationState.SubscriptionReportValid, Subscription = new MobileClient.Models.SubscriptionModel() { EndDateTime = _endDateTime, SubscriptionType = MobileClient.Models.SubscriptionType.Basic } }; _nav = new Mock <INavigation>(); _mnNav = new MainThreadNavigator(x => x(), _nav.Object); _logger = new Mock <ILogger <ManageSubscriptionViewModel> >(); _pageFactory = new Mock <IPageFactory>(); }
public void SetUp() { _alertService = new Mock <IToastService>(); _purchaseService = new Mock <IPurchasingService>(); _subCache = new Mock <ICache <SubscriptionModel> >(); _subService = new Mock <ISubscriptionService>(); _userCache = new Mock <ICurrentUserService>(); _nav = new Mock <INavigation>(); _mnNav = new MainThreadNavigator(x => x(), _nav.Object); _validationModel = new ValidationModel() { RemainingOrders = 0, State = ValidationState.FreeReportValid }; _runtimePlatform = Device.Android; _navigateFromMenu = new Action <BaseNavPageType>(x => CurrentTab = x); _alertUtil = new AlertUtility((s1, s2, s3, s4) => Task.FromResult(false), (s1, s2, s3) => Task.Delay(0)); _openUri = new Action <Uri>(x => OpenedUri = x); }
public void SetUp() { _notifier = new Mock <INotificationService>(); _userCache = new Mock <ICurrentUserService>(); _nav = new Mock <INavigation>(); _alert = new AlertUtility((s1, s2, s3, s4) => Task.FromResult(false), (s1, s2, s3) => Task.Delay(0)); _logger = new Mock <MobileClient.Utilities.ILogger <FeedbackViewModel> >(); _pageFactory = new Mock <IPageFactory>(); _notifier.Setup(x => x.Notify(It.Is <NotificationRequest>(y => y.From == "*****@*****.**" && y.To == "*****@*****.**" && y.MessageType == MessageType.Email))); _userCache.Setup(x => x.GetLoggedInAccount()).Returns(new AccountModel() { Email = "*****@*****.**", UserId = "1234" }); _nav.Setup(x => x.PopAsync()).ReturnsAsync(null as Page); _mnNav = new MainThreadNavigator(x => x(), _nav.Object); }
public AccountViewModel(ICurrentUserService userCache, IOrderValidationService orderValidator, MainThreadNavigator navigation, IPageFactory pageFactory, Action <string> changeLogInStyleClass, Action <string> changeSubStyleClass, ILogger <AccountViewModel> logger, ICacheRefresher cacheRefresher) { _navigation = navigation; _pageFactory = pageFactory; _userCache = userCache; _logger = logger; _cacheRefresher = cacheRefresher; _userCache.OnLoggedIn += async(s, e) => { SetAccountState(e.Account); await SetSubState(e.Account); }; _userCache.OnLoggedOut += async(s, e) => { SetAccountState(null); await SetSubState(null); }; _orderValidator = orderValidator; _changeLoginStyleClass = changeLogInStyleClass; _changeSubStyleClass = changeSubStyleClass; var user = userCache.GetLoggedInAccount(); _logger = logger; OnAppearingBehavior = new Command(async() => { var u = _userCache.GetLoggedInAccount(); SetAccountState(u); await SetSubState(u); }); SetInitialState(user); }
public OrderDetailViewModel(Models.Order order, ICache <PropertyModel> propertyCache, ICache <ImageModel> imgCache, IPropertyService propService, IImageService imgService, IToastService toast, MainThreadNavigator nav, IPageFactory pageFactory, Func <string, string, string, Task> alertAction, ICurrentUserService userService, ILogger <OrderDetailViewModel> logger) { _order = order; _propertyCache = propertyCache; _imageCache = imgCache; _propertyService = propService; _pageFactory = pageFactory; _imageService = imgService; _userService = userService; _toastService = toast; _nav = nav; _alertAction = alertAction; _logger = logger; OnAppearingBehavior = new Command(async() => await LoadPropertyAndImage()); // Display message if order isn't fulfilled yet. if (!order.Fulfilled) { StatusMessageVisible = true; MainLayoutVisible = false; // Have to do this because some dummy decided to store dates in EST DateTime displayTime = DateTime.Now; if (order.DateReceived != null) { var timeInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Detroit"); var utc = TimeZoneInfo.ConvertTimeToUtc(order.DateReceived.Value.DateTime); displayTime = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.Local); } SubmittedDateText = $"Order #{order.OrderId} was submitted on {displayTime.ToString("dddd, MMMM dd yyyy")}" + $" at {displayTime.ToString("h:mm tt")}"; if (order.Status == null) { order.Status = new StatusModel() { Status = Status.Pending }; } switch (order.Status.Status) { case (Status.ActionRequired): StatusMessageText = $"Please respond to the message sent to {_userService.GetLoggedInAccount()?.Email ?? "your logged in email"} to continue with this order."; StatusText = "Action Required"; TimingDisclaimerVisible = false; break; default: StatusMessageText = "Your order has been received and is being processed."; StatusText = "Pending"; TimingDisclaimerVisible = true; break; } return; } else { StatusMessageVisible = false; } _property = _propertyCache.Get(order.OrderId); _image = _property != null?_imageCache.Get(_property.OrderId) : null; SelectedRoofChangedCommand = new Command(() => SetUIMeasurements(_selectedRoofIndex)); if ((_property == null || _image == null) && _order.Fulfilled) { MainLayoutVisible = false; StatusMessageVisible = false; LoadingAnimVisible = true; LoadingAnimRunning = true; } else { MainLayoutVisible = true; if (_property.Roofs.Count > 1) { RoofSelectionVisible = true; RoofsSource = _property.Roofs.Select(x => x.Name).Distinct().ToList(); RoofsSource = new[] { "All" }.Concat(RoofsSource).ToList(); } else { RoofSelectionVisible = false; } SetUIMeasurements(0); } }
public MyOrdersViewModel(IOrderService orderSvc, ICache <Models.Order> orderCache, ICache <PropertyModel> propertyCache, ICache <ImageModel> imageCache, ILogger <MyOrdersViewModel> logger, ICacheRefresher cacheRefresher, IOrderValidationService validator, IPageFactory pageFactory, ICurrentUserService userService, LaunchedFromPushModel pushModel, MainThreadNavigator nav, IMessagingCenter messagingCenter, Action <Action> uiInvoke, Action <BaseNavPageType> baseNavAction) { _orderService = orderSvc; _orderCache = orderCache; _propertyCache = propertyCache; _imageCache = imageCache; _logger = logger; _uiInvoke = uiInvoke; _cacheRefresher = cacheRefresher; _validationService = validator; _pageFactory = pageFactory; _userService = userService; _messagingCenter = messagingCenter; _nav = nav; _baseNavAction = baseNavAction; ExampleReportCommand = new Command(() => { try { var order = JsonConvert.DeserializeObject <Models.Order>(Examples.ExampleOrder); _imageCache.Put(order.OrderId, new ImageModel() { OrderId = order.OrderId, Image = Convert.FromBase64String(Examples.ExampleImage) }); _propertyCache.Put(order.OrderId, JsonConvert.DeserializeObject <PropertyModel>(Examples.ExampleProperty)); _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, order)); } catch (Exception ex) { _logger.LogError($"An error occurred while trying to open example order.", ex); } }); Action refreshAction = async() => { try { OrderListRefreshing = true; var fresh = await _orderService.GetMemberOrders(_userService.GetLoggedInAccount()?.UserId); _orderCache.Put(fresh.ToDictionary(x => x.OrderId, x => x)); SetListViewSource(fresh.ToList()); OrderListRefreshing = false; } catch (Exception ex) { _logger.LogError($"Failed to refresh order list.", ex); } }; OrderListRefreshCommand = new Command(refreshAction); _messagingCenter.Subscribe <App>(this, "CacheInvalidated", async x => { await this.SetViewState(); }); OnAppearingBehavior = new Command(async() => { if (!_pmEventSubscribed) { _pmEventSubscribed = true; pushModel.PropertyChanged += async(s, e) => { if (!string.IsNullOrWhiteSpace(pushModel.OrderId)) { var order = await _orderService.GetOrder(pushModel.OrderId); _orderCache.Put(order.OrderId, order); _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, order)); } }; } await SetViewState(); }); }