Version 3.0.381

This commit is contained in:
Anja 2024-04-09 12:53:23 +02:00
parent f963c0a219
commit 3a363acf3a
1525 changed files with 60589 additions and 125098 deletions

View file

@ -0,0 +1,62 @@
using System.ComponentModel;
using ShareeBike.MultilingualResources;
using ShareeBike.Services;
using ShareeBike.Services.CopriApi.ServerUris;
using ShareeBike.View.Themes;
using ShareeBike.ViewModel.LegalInformation;
namespace ShareeBike.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(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<object> themes))
return;
MasterDetailMenuTitle = GetMasterDetailMenuTitle(themes.Active);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MasterDetailMenuTitle)));
};
MasterDetailMenuTitle = GetMasterDetailMenuTitle(App.ModelRoot.Themes.Active);
}
/// <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 ShareeBike.Themes.ShareeBike.OPERATORINFO;
return $"{(!string.IsNullOrEmpty(active.OperatorInfo) ? ($"{active.OperatorInfo}") : "sharee.bike")}";
}
/// <summary>
/// Holds the title of the flyout page.
/// </summary>
public string MasterDetailMenuTitle { get; private set; }
public event PropertyChangedEventHandler PropertyChanged;
public bool IsMyBikesPageVisible => App.ModelRoot.ActiveUser.IsLoggedIn;
public bool IsAccountPageVisible => App.ModelRoot.ActiveUser.IsLoggedIn;
public bool IsLoginPageVisible => !App.ModelRoot.ActiveUser.IsLoggedIn;
}
}

View file

@ -0,0 +1,42 @@
using System.IO;
using System.Reflection;
using System.Text;
using Serilog;
namespace ShareeBike.ViewModel
{
public static class ViewModelResourceHelper
{
/// <summary> Get resource prefix depending on platform.</summary>
public static string ResourcePrefix
{
get
{
#if __IOS__
return "ShareeBike.iOS.";
#endif
#if __ANDROID__
return "ShareeBike.Droid.";
#endif
#if WINDOWS_UWP
return "ShareeBike.WinPhone.";
#endif
}
}
/// <summary> Gets an embedded html resource.</summary>
/// <param name="resrouceName">Name of resource to get.</param>
/// <returns></returns>
public static string GetSource(string resrouceName)
{
var resourceName = ResourcePrefix + resrouceName;
Log.Verbose($"Using this resource prefix {ResourcePrefix}.");
// note that the prefix includes the trailing period '.' that is required
var assembly = typeof(ViewModelResourceHelper).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream(resourceName);
return stream != null
? (new StreamReader(stream, Encoding.UTF8)).ReadToEnd()
: string.Format("<!DOCTYPE html><html lang=\"de\"><body>An error occurred loading html- resource {0}.</body>", resourceName);
}
}
}