Fix e migliorati caricamenti
This commit is contained in:
@@ -7,14 +7,39 @@ public class AttachedService : IAttachedService
|
||||
{
|
||||
public async Task<AttachedDTO?> SelectImage()
|
||||
{
|
||||
var perm = await Permissions.RequestAsync<Permissions.Photos>();
|
||||
if (perm != PermissionStatus.Granted) return null;
|
||||
// Richiesta permessi base
|
||||
var cameraPerm = await Permissions.RequestAsync<Permissions.Camera>();
|
||||
var storagePerm = await Permissions.RequestAsync<Permissions.StorageRead>();
|
||||
|
||||
var result = await FilePicker.PickAsync(new PickOptions
|
||||
if (cameraPerm != PermissionStatus.Granted && storagePerm != PermissionStatus.Granted)
|
||||
return null;
|
||||
|
||||
// Mostro all'utente un popup di scelta
|
||||
var action = await Application.Current.MainPage.DisplayActionSheet(
|
||||
"Aggiungi immagine",
|
||||
"Annulla",
|
||||
null,
|
||||
"Scatta foto",
|
||||
"Scegli dalla galleria");
|
||||
|
||||
FileResult? result = null;
|
||||
|
||||
try
|
||||
{
|
||||
PickerTitle = "Scegli un'immagine",
|
||||
FileTypes = FilePickerFileType.Images
|
||||
});
|
||||
if (action == "Scatta foto")
|
||||
{
|
||||
result = await MediaPicker.Default.CapturePhotoAsync();
|
||||
}
|
||||
else if (action == "Scegli dalla galleria")
|
||||
{
|
||||
result = await MediaPicker.Default.PickPhotoAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Errore selezione immagine: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return result is null ? null : await ConvertToDto(result, AttachedDTO.TypeAttached.Image);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user