diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/AppShell.xaml.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/AppShell.xaml.cs index a880498..22a42f3 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/AppShell.xaml.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/AppShell.xaml.cs @@ -2,31 +2,50 @@ using Ebd.Mobile.Views; using Ebd.Mobile.Views.Aluno; using Ebd.Mobile.Views.Chamada; +using Ebd.MobileApp.Services.Navigation; using Ebd.MobileApp.Views.Perfil; -namespace Ebd.Mobile +namespace Ebd.MobileApp; + +public partial class AppShell : Shell { - public partial class AppShell : Shell + private readonly INavigationService _navigationService; + + public AppShell(INavigationService navigationService) { - public AppShell() - { - InitializeComponent(); - Routing.RegisterRoute(nameof(ItemDetailPage), typeof(ItemDetailPage)); - Routing.RegisterRoute(nameof(NewItemPage), typeof(NewItemPage)); - Routing.RegisterRoute(nameof(HomePage), typeof(HomePage)); - Routing.RegisterRoute(nameof(EfetuarChamadaPage), typeof(EfetuarChamadaPage)); + _navigationService = navigationService; + InitializeRouting(); - Routing.RegisterRoute(PageConstant.Aluno.Novo, typeof(NovoAlunoPage)); - Routing.RegisterRoute(PageConstant.Aluno.Lista, typeof(ListaAlunoPage)); - Routing.RegisterRoute(PageConstant.Aluno.ResponsavelAluno.Adicionar, typeof(AdicionarResponsavelPage)); + InitializeComponent(); + } - Routing.RegisterRoute(PageConstant.Perfil.Detalhes, typeof(PerfilPage)); - } + private static void InitializeRouting() + { + Routing.RegisterRoute(nameof(ItemDetailPage), typeof(ItemDetailPage)); + Routing.RegisterRoute(nameof(NewItemPage), typeof(NewItemPage)); + Routing.RegisterRoute(nameof(HomePage), typeof(HomePage)); + Routing.RegisterRoute(nameof(EfetuarChamadaPage), typeof(EfetuarChamadaPage)); + + Routing.RegisterRoute(PageConstant.Aluno.Novo, typeof(NovoAlunoPage)); + Routing.RegisterRoute(PageConstant.Aluno.Lista, typeof(ListaAlunoPage)); + Routing.RegisterRoute(PageConstant.Aluno.ResponsavelAluno.Adicionar, typeof(AdicionarResponsavelPage)); - private async void OnMenuItemClicked(object sender, EventArgs e) + Routing.RegisterRoute(PageConstant.Perfil.Detalhes, typeof(PerfilPage)); + } + + protected override async void OnHandlerChanged() + { + base.OnHandlerChanged(); + + if (Handler is not null) { - Shell.Current.FlyoutIsPresented = false; - await Shell.Current.GoToAsync("//LoginPage"); + await _navigationService.InitializeAsync(); } } + + private async void OnMenuItemClicked(object sender, EventArgs e) + { + Shell.Current.FlyoutIsPresented = false; + await Shell.Current.GoToAsync("//LoginPage"); + } } diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/DependencyInjection.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/DependencyInjection.cs index dc4f069..dd8ee71 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/DependencyInjection.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/DependencyInjection.cs @@ -16,6 +16,7 @@ using Ebd.MobileApp.Services.Implementations.Analytics; using Ebd.MobileApp.Services.Implementations.BottomSheets; using Ebd.MobileApp.Services.Interfaces.BottomSheets; +using Ebd.MobileApp.Services.Navigation; using Ebd.MobileApp.ViewModels.Home; using Ebd.MobileApp.ViewModels.Perfil; using Ebd.MobileApp.ViewModels.Turma; @@ -65,6 +66,7 @@ public static IServiceCollection ConfigureServices(this IServiceCollection servi services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(Connectivity.Current); services.AddSingleton(); diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Navigation/INavigationService.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Navigation/INavigationService.cs new file mode 100644 index 0000000..925000b --- /dev/null +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Navigation/INavigationService.cs @@ -0,0 +1,12 @@ +using Ebd.MobileApp.ViewModels; + +namespace Ebd.MobileApp.Services.Navigation; + +public interface INavigationService +{ + Task Navigate(object? parameter = null, bool animated = true) + where TViewModel : BasePageViewModel; + + void Initialize(object? parameters = null); + Task InitializeAsync(); +} \ No newline at end of file diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Navigation/NavigationService.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Navigation/NavigationService.cs index aa508b4..8622157 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Navigation/NavigationService.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Navigation/NavigationService.cs @@ -12,7 +12,7 @@ namespace Ebd.MobileApp.Services.Navigation; -internal sealed class NavigationService +internal sealed class NavigationService : INavigationService { static readonly Lazy _Lazy = new(() => new()); @@ -119,4 +119,9 @@ private Page CreateAndBindPage(Type viewModelType) return page; } + + public async Task InitializeAsync() + { + await Task.CompletedTask; + } }