Skip to content

Commit

Permalink
tentando resolver erro list constructor index
Browse files Browse the repository at this point in the history
  • Loading branch information
ozielguimaraes committed Jul 2, 2024
1 parent 346aee3 commit 07d8eee
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface IEscolherTurmaBottomSheetService : IDisposable
{
Task AbrirBottomSheetAsync();
Task AbrirBottomSheetAsync(bool usuarioPodeFechar);
Task FecharBottomSheetAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
Expand All @@ -47,7 +48,6 @@ public HomeViewModel(ISyncService syncService, IDiagnosticService diagnosticServ
[ObservableProperty]
HomeTab _currentTab;


[RelayCommand]
void GoToTab(HomeTab destinationTab)
{
Expand Down Expand Up @@ -95,31 +95,35 @@ private async Task ExecutarClicouNaAbaPerfilCommand()

IsBusy = true;
await Navigate<PerfilPageViewModel>();
//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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private async Task ExecutarExecutarClicouNaAbaPerfilCommand()
if (IsBusy) return;

IsBusy = true;
await escolherTurmaBottomSheetService.AbrirBottomSheetAsync();
await escolherTurmaBottomSheetService.AbrirBottomSheetAsync(true);
IsBusy = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ObservableCollection<TurmaResponse> 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();
Expand Down Expand Up @@ -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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
<the49:BottomSheet.Resources>
<mct:IsListNotNullOrEmptyConverter x:Key="IsListNotNullOrEmpty" />
</the49:BottomSheet.Resources>
<the49:BottomSheet.Detents>
<the49:ContentDetent IsDefault="True" />
<the49:RatioDetent Ratio="0.50" />
Expand All @@ -20,8 +24,8 @@
VerticalOptions="CenterAndExpand" />

<ListView
x:Name="TurmasListView"
HasUnevenRows="True"
IsVisible="{Binding Turmas, Converter={StaticResource IsListNotNullOrEmpty}}"
ItemsSource="{Binding Turmas}"
SelectionMode="None">
<ListView.ItemTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public EscolherTurmaBottomSheet()
{
InitializeComponent();
BindingContext = viewModel = DependencyInjection.GetService<EscolherTurmaBottomSheetViewModel>();
MainThread.BeginInvokeOnMainThread(async () => await viewModel.OnAppearingAsync());
}

public async Task LoadDataAsync()
{
await viewModel.LoadDataAsync();
}
}

0 comments on commit 07d8eee

Please sign in to comment.