Con il permesso negato "Aggiungi una foto" non faceva nulla: il servizio restituiva null come per un annullamento. Dopo un rifiuto definitivo Android non ripropone la richiesta, quindi il rilevatore restava bloccato senza capire perche'. - AttachedService: la richiesta dei permessi diventa RequestCameraPermissions, usata anche da SelectImageFromCamera; OpenAppSettings apre le impostazioni dell'app. - ModalFormScheda e ModalAddAttached: chiedono i permessi prima di scattare e, se negati, mostrano un avviso con l'azione "Impostazioni". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
85 lines
2.7 KiB
Plaintext
85 lines
2.7 KiB
Plaintext
@using SteUp.Shared.Core.Dto
|
|
@using SteUp.Shared.Core.Interface.System
|
|
@inject IAttachedService AttachedService
|
|
|
|
<MudDialog>
|
|
<DialogContent>
|
|
<h2 class="dialog-title">Aggiungi una foto</h2>
|
|
<p class="dialog-message">Scatta sul posto oppure scegli un'immagine già sul dispositivo.</p>
|
|
|
|
<div class="stack stack-xs" style="margin-top: var(--space-md);">
|
|
<button type="button" class="action-tile" @onclick="@OnCamera">
|
|
<span class="action-tile__icon action-tile__icon--primary">
|
|
<i class="ri-camera-line" aria-hidden="true"></i>
|
|
</span>
|
|
<span class="action-tile__label">Scatta una foto</span>
|
|
</button>
|
|
|
|
<button type="button" class="action-tile" @onclick="@OnGallery">
|
|
<span class="action-tile__icon action-tile__icon--neutral">
|
|
<i class="ri-image-line" aria-hidden="true"></i>
|
|
</span>
|
|
<span class="action-tile__label">Scegli dalla galleria</span>
|
|
</button>
|
|
</div>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Outlined" OnClick="@(() => MudDialog.Cancel())">Annulla</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
|
|
|
|
private List<AttachedDto>? Attached { get; set; }
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
|
|
}
|
|
|
|
private async Task OnCamera()
|
|
{
|
|
if (!await AttachedService.RequestCameraPermissions())
|
|
{
|
|
Snackbar.Clear();
|
|
Snackbar.Add("Per scattare le foto serve il permesso della fotocamera", Severity.Warning, config =>
|
|
{
|
|
config.Action = "Impostazioni";
|
|
config.OnClick = _ =>
|
|
{
|
|
AttachedService.OpenAppSettings();
|
|
return Task.CompletedTask;
|
|
};
|
|
});
|
|
return;
|
|
}
|
|
|
|
AttachedDto? selectImageFromCamera;
|
|
try
|
|
{
|
|
selectImageFromCamera = await AttachedService.SelectImageFromCamera();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Snackbar.Clear();
|
|
Snackbar.Add("Non è stato possibile scattare la foto, riprova", Severity.Error);
|
|
return;
|
|
}
|
|
|
|
if (selectImageFromCamera != null)
|
|
{
|
|
Attached ??= [];
|
|
Attached.Add(selectImageFromCamera);
|
|
MudDialog.Close(Attached);
|
|
}
|
|
}
|
|
|
|
private async Task OnGallery()
|
|
{
|
|
Attached = await AttachedService.SelectImageFromGallery();
|
|
|
|
if (Attached != null) MudDialog.Close(Attached);
|
|
}
|
|
}
|