Compare commits
8
Commits
e524c12a96
...
v1.2.3(9)
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42e2403362 | ||
|
|
249b301920 | ||
|
|
885b3cc6b6 | ||
|
|
7e1492d118 | ||
|
|
fd0c218ab5 | ||
|
|
deda374b5b | ||
|
|
e1ca03f646 | ||
|
|
92271e20fb |
No files matched your search
@@ -8,12 +8,21 @@ namespace SteUp.Maui.Core.Services;
|
|||||||
|
|
||||||
public class AttachedService(ILogger<FileManager> logger) : IAttachedService
|
public class AttachedService(ILogger<FileManager> logger) : IAttachedService
|
||||||
{
|
{
|
||||||
public async Task<AttachedDto?> SelectImageFromCamera()
|
public bool IsCameraAvailable => MediaPicker.Default.IsCaptureSupported;
|
||||||
|
|
||||||
|
public async Task<bool> RequestCameraPermissions()
|
||||||
{
|
{
|
||||||
var cameraPerm = await Permissions.RequestAsync<Permissions.Camera>();
|
var cameraPerm = await Permissions.RequestAsync<Permissions.Camera>();
|
||||||
var storagePerm = await Permissions.RequestAsync<Permissions.StorageWrite>();
|
var storagePerm = await Permissions.RequestAsync<Permissions.StorageWrite>();
|
||||||
|
|
||||||
if (cameraPerm != PermissionStatus.Granted || storagePerm != PermissionStatus.Granted)
|
return cameraPerm == PermissionStatus.Granted && storagePerm == PermissionStatus.Granted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenAppSettings() => AppInfo.Current.ShowSettingsUI();
|
||||||
|
|
||||||
|
public async Task<AttachedDto?> SelectImageFromCamera()
|
||||||
|
{
|
||||||
|
if (!await RequestCameraPermissions())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
FileResult? result;
|
FileResult? result;
|
||||||
@@ -28,7 +37,10 @@ public class AttachedService(ILogger<FileManager> logger) : IAttachedService
|
|||||||
logger.LogError(ex, ex.Message);
|
logger.LogError(ex, ex.Message);
|
||||||
Console.WriteLine($"Errore cattura foto: {ex.Message}");
|
Console.WriteLine($"Errore cattura foto: {ex.Message}");
|
||||||
SentrySdk.CaptureException(ex);
|
SentrySdk.CaptureException(ex);
|
||||||
return null;
|
|
||||||
|
// Rilancia: restituire null qui era indistinguibile da un annullamento,
|
||||||
|
// e il rilevatore toccava "Aggiungi una foto" senza vedere nulla.
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result is null ? null : await UtilityFile.ConvertToDto(result, AttachedDto.TypeAttached.Image);
|
return result is null ? null : await UtilityFile.ConvertToDto(result, AttachedDto.TypeAttached.Image);
|
||||||
|
|||||||
@@ -25,4 +25,11 @@
|
|||||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||||
|
|
||||||
|
<!-- Android 11+: rende visibile l'app fotocamera di sistema a MediaPicker -->
|
||||||
|
<queries>
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.media.action.IMAGE_CAPTURE" />
|
||||||
|
</intent>
|
||||||
|
</queries>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
<ApplicationId>it.integry.SteUp</ApplicationId>
|
<ApplicationId>it.integry.SteUp</ApplicationId>
|
||||||
|
|
||||||
<!-- Versions -->
|
<!-- Versions -->
|
||||||
<ApplicationDisplayVersion>1.2.1</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.2.3</ApplicationDisplayVersion>
|
||||||
<ApplicationVersion>7</ApplicationVersion>
|
<ApplicationVersion>9</ApplicationVersion>
|
||||||
|
|
||||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
|
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
|
||||||
<!-- <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">-->
|
<!-- <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">-->
|
||||||
|
|||||||
@@ -40,7 +40,32 @@
|
|||||||
|
|
||||||
private async Task OnCamera()
|
private async Task OnCamera()
|
||||||
{
|
{
|
||||||
var selectImageFromCamera = await AttachedService.SelectImageFromCamera();
|
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)
|
if (selectImageFromCamera != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -754,12 +754,60 @@
|
|||||||
|
|
||||||
#region File
|
#region File
|
||||||
|
|
||||||
|
// Dopo un rifiuto definitivo Android non ripropone la richiesta: il
|
||||||
|
// permesso si riattiva solo dalle impostazioni, quindi le apriamo noi.
|
||||||
|
private void ShowCameraPermissionDenied()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async Task OpenAddAttached()
|
private async Task OpenAddAttached()
|
||||||
{
|
{
|
||||||
var selectImageFromCamera = await AttachedService.SelectImageFromCamera();
|
List<AttachedDto>? attachedList;
|
||||||
if (selectImageFromCamera == null) return;
|
|
||||||
|
|
||||||
var attachedList = new List<AttachedDto> { selectImageFromCamera };
|
if (AttachedService.IsCameraAvailable)
|
||||||
|
{
|
||||||
|
if (!await AttachedService.RequestCameraPermissions())
|
||||||
|
{
|
||||||
|
ShowCameraPermissionDenied();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttachedDto? selectImageFromCamera;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
selectImageFromCamera = await AttachedService.SelectImageFromCamera();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// Gia' registrato e inviato a Sentry dal servizio
|
||||||
|
Snackbar.Clear();
|
||||||
|
Snackbar.Add("Non è stato possibile scattare la foto, riprova", Severity.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectImageFromCamera == null) return;
|
||||||
|
attachedList = [selectImageFromCamera];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Senza fotocamera "Aggiungi una foto" non avrebbe altra strada:
|
||||||
|
// si passa alla galleria invece di lasciare il rilevatore fermo.
|
||||||
|
Snackbar.Clear();
|
||||||
|
Snackbar.Add("Fotocamera non disponibile: scegli la foto dalla galleria", Severity.Warning);
|
||||||
|
|
||||||
|
attachedList = await AttachedService.SelectImageFromGallery();
|
||||||
|
if (attachedList is null || attachedList.Count == 0) return;
|
||||||
|
}
|
||||||
|
|
||||||
OnLoading = true;
|
OnLoading = true;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ namespace SteUp.Shared.Core.Interface.System;
|
|||||||
|
|
||||||
public interface IAttachedService
|
public interface IAttachedService
|
||||||
{
|
{
|
||||||
|
bool IsCameraAvailable { get; }
|
||||||
|
|
||||||
|
/// <summary>Chiede i permessi per scattare; false se negati.</summary>
|
||||||
|
Task<bool> RequestCameraPermissions();
|
||||||
|
|
||||||
|
void OpenAppSettings();
|
||||||
|
|
||||||
|
/// <summary>Null se l'utente annulla; lancia se lo scatto fallisce.</summary>
|
||||||
Task<AttachedDto?> SelectImageFromCamera();
|
Task<AttachedDto?> SelectImageFromCamera();
|
||||||
Task<List<AttachedDto>?> SelectImageFromGallery();
|
Task<List<AttachedDto>?> SelectImageFromGallery();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user