From 7b96137d745ae94978b27b852598c312712352c5 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 5 Oct 2016 03:48:59 +0200 Subject: [PATCH] Fixes User's dashboard --- BookAStar/BookAStar/Helpers/MainSettings.cs | 9 +++++- .../BookAStar/Pages/DashboardPage.xaml.cs | 9 +----- .../ViewModels/DashboardViewModel.cs | 28 +++++++++++++++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/BookAStar/BookAStar/Helpers/MainSettings.cs b/BookAStar/BookAStar/Helpers/MainSettings.cs index 71e871d0..8da30074 100644 --- a/BookAStar/BookAStar/Helpers/MainSettings.cs +++ b/BookAStar/BookAStar/Helpers/MainSettings.cs @@ -157,12 +157,19 @@ namespace BookAStar if (olduserid != value.Id) { App.CurrentApp.PostDeviceInfo(); + UserChanged.Invoke(App.CurrentApp, new EventArgs()); } } - // TODO else Unregister this device + else if (olduserid != null) + { + UserChanged.Invoke(App.CurrentApp, new EventArgs()); + // TODO else Unregister this device + } } } + public static event EventHandler UserChanged; + public static void SaveUser(User user) { var existent = AccountList.FirstOrDefault(u => u.UserName == user.UserName); diff --git a/BookAStar/BookAStar/Pages/DashboardPage.xaml.cs b/BookAStar/BookAStar/Pages/DashboardPage.xaml.cs index 0d6bac9c..85290eb1 100644 --- a/BookAStar/BookAStar/Pages/DashboardPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/DashboardPage.xaml.cs @@ -16,18 +16,11 @@ namespace BookAStar.Pages { public partial class DashboardPage : ContentPage { - public RelayGesture UserNameGesture { get; set; } + public DashboardPage() { InitializeComponent(); - UserNameGesture = new RelayGesture((g, x) => - { - if (g.GestureType == GestureType.LongPress) - { - Resolver.Resolve().NavigateTo(true); - } - }); } public void OnViewPerformerStatus(object sender, EventArgs e) diff --git a/BookAStar/BookAStar/ViewModels/DashboardViewModel.cs b/BookAStar/BookAStar/ViewModels/DashboardViewModel.cs index 03d1abf4..72549605 100644 --- a/BookAStar/BookAStar/ViewModels/DashboardViewModel.cs +++ b/BookAStar/BookAStar/ViewModels/DashboardViewModel.cs @@ -1,9 +1,14 @@ using BookAStar.Helpers; using BookAStar.Model.Auth.Account; +using BookAStar.Pages; using System.Collections.ObjectModel; using System.Linq; using Xamarin.Forms; +using XLabs.Forms.Behaviors; +using XLabs.Forms.Controls; using XLabs.Forms.Mvvm; +using XLabs.Ioc; +using XLabs.Platform.Services; namespace BookAStar.ViewModels { @@ -98,6 +103,22 @@ namespace BookAStar.ViewModels Accounts = MainSettings.AccountList; User = MainSettings.CurrentUser; UpdateUserMeta(); + + UserNameGesture = new RelayGesture((g, x) => + { + if (g.GestureType == GestureType.LongPress) + { + Resolver.Resolve().NavigateTo(true); + } + }); + MainSettings.UserChanged += MainSettings_UserChanged; + + } + + private void MainSettings_UserChanged(object sender, System.EventArgs e) + { + User = MainSettings.CurrentUser; + UpdateUserMeta(); } private void UpdateUserMeta () @@ -117,9 +138,9 @@ namespace BookAStar.ViewModels { newUserIsPro = User.Roles?.Contains("Performer") ?? false; - newQueryCount = userIsPro ? DataManager.Current.BookQueries.Count : 0; + newQueryCount = newUserIsPro ? DataManager.Current.BookQueries.Count : 0; - newStatusString = userIsPro ? + newStatusString = newUserIsPro ? $"Profile professionel renseigné,\n{newQueryCount} demandes valides en cours" : "Profile professionel non renseigné"; newAvatar = UserHelpers.Avatar(user.Avatar); @@ -133,5 +154,8 @@ namespace BookAStar.ViewModels { UpdateUserMeta(); } + + public RelayGesture UserNameGesture { get; set; } + } } \ No newline at end of file