sharee.bike-App/Meinkonrad/TINK/ViewModel/RootShell/AppShellViewModel.cs

73 lines
2.4 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System.ComponentModel;
using TINK.MultilingualResources;
using TINK.Services;
2021-11-07 19:42:59 +01:00
using TINK.Services.CopriApi.ServerUris;
using TINK.View.Themes;
2022-08-30 15:42:25 +02:00
using TINK.ViewModel.Info;
2021-11-07 19:42:59 +01:00
namespace TINK.ViewModel.RootShell
{
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(IsFindBikePageVisible)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsAccountPageVisible)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsLoginPageVisible)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsSettingsPageVisible)));
};
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
2022-09-06 16:08:19 +02:00
MasterDetailMenuTitlte = GetMasterDetailMenuTitle(themes.Active);
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MasterDetailMenuTitlte)));
};
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
MasterDetailMenuTitlte = GetMasterDetailMenuTitle(App.ModelRoot.Themes.Active);
}
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))
return "sharee.bike";
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>
/// Holds the title of the fylout page.
/// </summary>
public string MasterDetailMenuTitlte { 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 IsFindBikePageVisible => 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
2022-09-06 16:08:19 +02:00
public bool IsSettingsPageVisible => App.ModelRoot.Uris.ActiveUri.Host.GetIsCopri()
|| App.ModelRoot.ActiveUser.IsLoggedIn;
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
public string TabbedPageIngoTitle => AppResources.MarkingAbout;
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
}
2021-11-07 19:42:59 +01:00
}