using System.ComponentModel; using TINK.MultilingualResources; using TINK.Services; using TINK.Services.CopriApi.ServerUris; using TINK.View.Themes; using TINK.ViewModel.LegalInformation; namespace TINK.ViewModel.RootShell { public class AppShellViewModel : INotifyPropertyChanged { public AppShellViewModel() { App.ModelRoot.ActiveUser.StateChanged += (sender, eventargs) => { // Login state changed. Update related menu entries. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsMyBikesPageVisible))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsSelectBikePageVisible))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsAccountPageVisible))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsLoginPageVisible))); }; // Update flyout view model whenever theme is switched. App.ModelRoot.Themes.PropertyChanged += (sender, eventargs) => { if (!(sender is ServicesContainerMutableT themes)) return; MasterDetailMenuTitlte = GetMasterDetailMenuTitle(themes.Active); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MasterDetailMenuTitlte))); }; MasterDetailMenuTitlte = GetMasterDetailMenuTitle(App.ModelRoot.Themes.Active); } /// /// Gets the flyout title from theme name /// /// Name of theme. /// Flyout title. private string GetMasterDetailMenuTitle(object theme) { if (!(theme is ITheme active)) return "sharee.bike"; return $"{(!string.IsNullOrEmpty(active.OperatorInfo) ? ($"{active.OperatorInfo}") : "sharee.bike")}"; } /// /// Holds the title of the fylout page. /// public string MasterDetailMenuTitlte { get; private set; } public event PropertyChangedEventHandler PropertyChanged; public bool IsMyBikesPageVisible => App.ModelRoot.ActiveUser.IsLoggedIn; public bool IsSelectBikePageVisible => App.ModelRoot.ActiveUser.IsLoggedIn; public bool IsAccountPageVisible => App.ModelRoot.ActiveUser.IsLoggedIn; public bool IsLoginPageVisible => !App.ModelRoot.ActiveUser.IsLoggedIn; } }