From 07d8eee4b93aca1aaebab467b0b6936b2cb600d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oziel=20Guimar=C3=A3es=20de=20Paula=20Silva?= Date: Tue, 2 Jul 2024 16:44:55 -0300 Subject: [PATCH] tentando resolver erro list constructor index --- .../EscolherTurmaBottomSheetService.cs | 7 ++-- .../IEscolherTurmaBottomSheetService.cs | 2 +- .../ViewModels/BaseBottomSheetViewModel.cs | 2 +- .../ViewModels/Home/HomeViewModel.cs | 36 ++++++++++--------- .../ViewModels/Home/HomeViewModel.home.cs | 3 +- .../ViewModels/Perfil/PerfilPageViewModel.cs | 2 +- .../EscolherTurmaBottomSheetViewModel.cs | 8 +++-- .../Views/Turma/EscolherTurmaBottomSheet.xaml | 6 +++- .../Turma/EscolherTurmaBottomSheet.xaml.cs | 6 +++- 9 files changed, 44 insertions(+), 28 deletions(-) diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Implementations/BottomSheets/EscolherTurmaBottomSheetService.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Implementations/BottomSheets/EscolherTurmaBottomSheetService.cs index 0d1352f..e24afd3 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Implementations/BottomSheets/EscolherTurmaBottomSheetService.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Implementations/BottomSheets/EscolherTurmaBottomSheetService.cs @@ -7,14 +7,15 @@ public class EscolherTurmaBottomSheetService : IEscolherTurmaBottomSheetService { private EscolherTurmaBottomSheet? EscolherTurmaBottomSheet; - public async Task AbrirBottomSheetAsync() + public async Task AbrirBottomSheetAsync(bool usuarioPodeFechar) { - EscolherTurmaBottomSheet = new EscolherTurmaBottomSheet + EscolherTurmaBottomSheet ??= new EscolherTurmaBottomSheet { HasHandle = true, - IsCancelable = false + IsCancelable = usuarioPodeFechar }; + await EscolherTurmaBottomSheet.LoadDataAsync(); await EscolherTurmaBottomSheet.ShowAsync(); } diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Interfaces/BottomSheets/IEscolherTurmaBottomSheetService.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Interfaces/BottomSheets/IEscolherTurmaBottomSheetService.cs index 27fc5b8..122652d 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Interfaces/BottomSheets/IEscolherTurmaBottomSheetService.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Services/Interfaces/BottomSheets/IEscolherTurmaBottomSheetService.cs @@ -2,6 +2,6 @@ public interface IEscolherTurmaBottomSheetService : IDisposable { - Task AbrirBottomSheetAsync(); + Task AbrirBottomSheetAsync(bool usuarioPodeFechar); Task FecharBottomSheetAsync(); } diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/BaseBottomSheetViewModel.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/BaseBottomSheetViewModel.cs index d8c833c..ff91f09 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/BaseBottomSheetViewModel.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/BaseBottomSheetViewModel.cs @@ -17,7 +17,7 @@ protected void DefinirNomeDoBottomSheet(string name) BottomSheetName = name; } - public virtual Task OnAppearingAsync(object? parameter = null) + public virtual Task LoadDataAsync(object? parameter = null) { var nameWasDefined = string.IsNullOrWhiteSpace(BottomSheetName).Not(); if (nameWasDefined) diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.cs index 7a77f3d..7f99567 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.cs @@ -15,9 +15,10 @@ internal sealed partial class HomeViewModel : BasePageViewModel { private readonly ISyncService syncService; private readonly IEscolherTurmaBottomSheetService escolherTurmaBottomSheetService; + private readonly ITurmaService turmaService; private readonly IConfiguracoesDoUsuarioService configuracoesDoUsuarioService; - public HomeViewModel(ISyncService syncService, IDiagnosticService diagnosticService, IDialogService dialogService, ILoggerService loggerService, IEscolherTurmaBottomSheetService escolherTurmaBottomSheetService, IConfiguracoesDoUsuarioService configuracoesDoUsuarioService, IAnalyticsService analyticsService) : base(diagnosticService, dialogService, loggerService, analyticsService) + public HomeViewModel(ISyncService syncService, IDiagnosticService diagnosticService, IDialogService dialogService, ILoggerService loggerService, IEscolherTurmaBottomSheetService escolherTurmaBottomSheetService, IConfiguracoesDoUsuarioService configuracoesDoUsuarioService, IAnalyticsService analyticsService, ITurmaService turmaService) : base(diagnosticService, dialogService, loggerService, analyticsService) { this.syncService = syncService; this.escolherTurmaBottomSheetService = escolherTurmaBottomSheetService; @@ -37,7 +38,7 @@ public HomeViewModel(ISyncService syncService, IDiagnosticService diagnosticServ ClicouNaAbaPerfilCommand = new AsyncCommand( execute: ExecutarClicouNaAbaPerfilCommand, onException: CommandOnException); - + this.turmaService = turmaService; } public AsyncCommand GoToAlunoPageCommand { get; private set; } @@ -47,7 +48,6 @@ public HomeViewModel(ISyncService syncService, IDiagnosticService diagnosticServ [ObservableProperty] HomeTab _currentTab; - [RelayCommand] void GoToTab(HomeTab destinationTab) { @@ -95,31 +95,35 @@ private async Task ExecutarClicouNaAbaPerfilCommand() IsBusy = true; await Navigate(); - //await Shell.Current.GoToAsync(PageConstant.Perfil.Detalhes); IsBusy = false; } public async override Task OnAppearingAsync(object? parameter = null) { + if (IsBusy) + return; + + IsBusy = true; + await base.OnAppearingAsync(parameter); - await MainThread.InvokeOnMainThreadAsync(async () => + if (configuracoesDoUsuarioService.SelecionouUmaTurma.Not()) { - try + await MainThread.InvokeOnMainThreadAsync(async () => { - if (configuracoesDoUsuarioService.SelecionouUmaTurma.Not()) + try { - await escolherTurmaBottomSheetService.AbrirBottomSheetAsync(); - return; + await escolherTurmaBottomSheetService.AbrirBottomSheetAsync(false); + } + catch (Exception exception) + { + Logger.LogError($"{nameof(HomeViewModel)}::{nameof(OnAppearingAsync)}", exception); } - await InitializeHomeTab(); - } - catch (Exception exception) - { - Logger.LogError($"{nameof(HomeViewModel)}::{nameof(OnAppearingAsync)}", exception); - } - }); + }); + } + + IsBusy = false; } } } diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.home.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.home.cs index b086fed..01b8bd2 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.home.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Home/HomeViewModel.home.cs @@ -4,8 +4,9 @@ namespace Ebd.MobileApp.ViewModels.Home; internal sealed partial class HomeViewModel : BasePageViewModel { - public HomeViewModel(IDiagnosticService diagnosticService, IDialogService dialogService, ILoggerService logger, IAnalyticsService analyticsService) : base(diagnosticService, dialogService, logger, analyticsService) + public HomeViewModel(IDiagnosticService diagnosticService, IDialogService dialogService, ILoggerService logger, IAnalyticsService analyticsService, ITurmaService turmaService) : base(diagnosticService, dialogService, logger, analyticsService) { + this.turmaService = turmaService; } private async Task InitializeHomeTab(object? parameter = null) diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Perfil/PerfilPageViewModel.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Perfil/PerfilPageViewModel.cs index 4c93596..38496cd 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Perfil/PerfilPageViewModel.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Perfil/PerfilPageViewModel.cs @@ -53,7 +53,7 @@ private async Task ExecutarExecutarClicouNaAbaPerfilCommand() if (IsBusy) return; IsBusy = true; - await escolherTurmaBottomSheetService.AbrirBottomSheetAsync(); + await escolherTurmaBottomSheetService.AbrirBottomSheetAsync(true); IsBusy = false; } diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Turma/EscolherTurmaBottomSheetViewModel.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Turma/EscolherTurmaBottomSheetViewModel.cs index d81db91..ae91fdf 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Turma/EscolherTurmaBottomSheetViewModel.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/ViewModels/Turma/EscolherTurmaBottomSheetViewModel.cs @@ -32,7 +32,7 @@ public ObservableCollection Turmas public ICommand TurmaSelecionadaCommand { get; set; } - public override async Task OnAppearingAsync(object? parameter = null) + public override async Task LoadDataAsync(object? parameter = null) { DialogService.ShowLoading("Carregando as turmas..."); var respostaTurmas = await turmaService.ObterTodasAsync(); @@ -67,7 +67,9 @@ private async Task ExecutarTurmaSelecionadaCommand(TurmaResponse turma) Logger.LogInformation($"Turma selecionada: {turma.Nome}"); configuracoesDoUsuarioService.TurmaSelecionada = turma; - - await MainThread.InvokeOnMainThreadAsync(escolherTurmaBottomSheetService.FecharBottomSheetAsync); + await MainThread.InvokeOnMainThreadAsync(async () => + { + await escolherTurmaBottomSheetService.FecharBottomSheetAsync(); + }); } } diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml index 18462e7..a243817 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml @@ -3,11 +3,15 @@ x:Class="Ebd.MobileApp.Views.Turma.EscolherTurmaBottomSheet" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:response="clr-namespace:Ebd.Mobile.Services.Responses.Turma" xmlns:the49="https://schemas.the49.com/dotnet/2023/maui" x:Name="ThisBottomSheet" Padding="32,32" BackgroundColor="{StaticResource White}"> + + + @@ -20,8 +24,8 @@ VerticalOptions="CenterAndExpand" /> diff --git a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml.cs b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml.cs index f5784b0..8142067 100644 --- a/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml.cs +++ b/EscolaBiblicaDominical/Ebd.Mobile/Ebd.MobileApp/Views/Turma/EscolherTurmaBottomSheet.xaml.cs @@ -12,6 +12,10 @@ public EscolherTurmaBottomSheet() { InitializeComponent(); BindingContext = viewModel = DependencyInjection.GetService(); - MainThread.BeginInvokeOnMainThread(async () => await viewModel.OnAppearingAsync()); + } + + public async Task LoadDataAsync() + { + await viewModel.LoadDataAsync(); } } \ No newline at end of file