sharee.bike-App/LastenradBayern/ShareeBike/ViewModel/RootShell/AppShellViewModel.cs

63 lines
2 KiB
C#
Raw Normal View History

2022-10-12 21:02:34 +02:00
using System.ComponentModel;
2024-04-09 12:53:23 +02:00
using ShareeBike.MultilingualResources;
using ShareeBike.Services;
using ShareeBike.Services.CopriApi.ServerUris;
using ShareeBike.View.Themes;
using ShareeBike.ViewModel.LegalInformation;
2021-11-07 19:42:59 +01:00
2024-04-09 12:53:23 +02:00
namespace ShareeBike.ViewModel.RootShell
2021-11-07 19:42:59 +01:00
{
2022-09-06 16:08:19 +02:00
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(IsAccountPageVisible)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsLoginPageVisible)));
};
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
// Update flyout view model whenever theme is switched.
App.ModelRoot.Themes.PropertyChanged += (sender, eventargs) =>
{
if (!(sender is ServicesContainerMutableT<object> themes))
return;
2021-11-07 19:42:59 +01:00
2024-04-09 12:53:23 +02:00
MasterDetailMenuTitle = GetMasterDetailMenuTitle(themes.Active);
2021-11-07 19:42:59 +01:00
2024-04-09 12:53:23 +02:00
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MasterDetailMenuTitle)));
2022-09-06 16:08:19 +02:00
};
2021-11-07 19:42:59 +01:00
2024-04-09 12:53:23 +02:00
MasterDetailMenuTitle = GetMasterDetailMenuTitle(App.ModelRoot.Themes.Active);
2022-09-06 16:08:19 +02:00
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Gets the flyout title from theme name
/// </summary>
/// <param name="theme">Name of theme.</param>
/// <returns>Flyout title.</returns>
private string GetMasterDetailMenuTitle(object theme)
{
if (!(theme is ITheme active))
2024-04-09 12:53:23 +02:00
return ShareeBike.Themes.ShareeBike.OPERATORINFO;
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
return $"{(!string.IsNullOrEmpty(active.OperatorInfo) ? ($"{active.OperatorInfo}") : "sharee.bike")}";
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary>
2024-04-09 12:53:23 +02:00
/// Holds the title of the flyout page.
2022-09-06 16:08:19 +02:00
/// </summary>
2024-04-09 12:53:23 +02:00
public string MasterDetailMenuTitle { get; private set; }
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
public event PropertyChangedEventHandler PropertyChanged;
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
public bool IsMyBikesPageVisible => App.ModelRoot.ActiveUser.IsLoggedIn;
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
public bool IsAccountPageVisible => App.ModelRoot.ActiveUser.IsLoggedIn;
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
public bool IsLoginPageVisible => !App.ModelRoot.ActiveUser.IsLoggedIn;
}
2021-11-07 19:42:59 +01:00
}