Release 0.4.8 with Android file imports
This commit is contained in:
1 parent
b600412285
commit
3dfeef54ea
9 files changed
+328
-32
No files matched your search
+101
-2
@@ -10,6 +10,7 @@
|
||||
@inject MapExportService MapExportService
|
||||
@inject CloudSyncService CloudSyncService
|
||||
@inject AppUpdateService AppUpdateService
|
||||
@inject IncomingFileService IncomingFiles
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<PageTitle>LME Mappe Catastali</PageTitle>
|
||||
@@ -697,6 +698,7 @@
|
||||
private bool SyncBusy { get; set; }
|
||||
private string SyncStatus { get; set; } = "Sincronizzazione non configurata.";
|
||||
private bool UpdateBusy { get; set; }
|
||||
private bool MapReady { get; set; }
|
||||
private string UpdateStatus { get; set; } = $"Versione installata: {AppUpdateService.CurrentVersion}";
|
||||
private string UpdateDownloadUrl { get; set; } = string.Empty;
|
||||
private string UpdateReleaseNotes { get; set; } = string.Empty;
|
||||
@@ -754,6 +756,7 @@
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
IncomingFiles.FileAvailable += OnIncomingFileAvailable;
|
||||
LoadFlagPreferences();
|
||||
|
||||
try
|
||||
@@ -797,12 +800,14 @@
|
||||
{
|
||||
MapCallbackReference = DotNetObjectReference.Create(this);
|
||||
await JS.InvokeVoidAsync("lmeMap.init", MapCallbackReference);
|
||||
MapReady = true;
|
||||
await ApplyFlagPreferencesToMapAsync();
|
||||
await ApplyAdvancedOptions();
|
||||
await CenterOnInitialLocationAsync();
|
||||
await MigrateLegacyProjectAsync();
|
||||
var offlineCount = await JS.InvokeAsync<int>("lmeMap.getOfflineTileStats");
|
||||
OfflineStatus = offlineCount == 0 ? "Nessuna tessera salvata." : $"{offlineCount} tessere disponibili offline.";
|
||||
await ProcessIncomingFilesAsync();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -1492,7 +1497,11 @@
|
||||
|
||||
private async Task RestoreBackup()
|
||||
{
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions { PickerTitle = "Scegli backup LME" });
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions
|
||||
{
|
||||
PickerTitle = "Scegli backup LME (.lmebackup.zip)",
|
||||
FileTypes = BackupPickerFileTypes
|
||||
});
|
||||
if (file is null) return;
|
||||
var path = await CopyPickedFileToCacheAsync(file);
|
||||
var count = await ProjectStorageService.RestoreBackupAsync(path);
|
||||
@@ -1502,7 +1511,11 @@
|
||||
|
||||
private async Task ImportProject()
|
||||
{
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions { PickerTitle = "Scegli progetto LME" });
|
||||
var file = await FilePicker.Default.PickAsync(new PickOptions
|
||||
{
|
||||
PickerTitle = "Scegli progetto LME (.lmeproject.json)",
|
||||
FileTypes = ProjectPickerFileTypes
|
||||
});
|
||||
if (file is null) return;
|
||||
var path = await CopyPickedFileToCacheAsync(file);
|
||||
var imported = await ProjectStorageService.ImportProjectAsync(path);
|
||||
@@ -1521,6 +1534,91 @@
|
||||
return path;
|
||||
}
|
||||
|
||||
private void OnIncomingFileAvailable()
|
||||
{
|
||||
if (MapReady) _ = InvokeAsync(ProcessIncomingFilesAsync);
|
||||
}
|
||||
|
||||
private async Task ProcessIncomingFilesAsync()
|
||||
{
|
||||
while (IncomingFiles.TryDequeue(out var incoming) && incoming is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lowerName = incoming.FileName.ToLowerInvariant();
|
||||
if (lowerName.EndsWith(".kml", StringComparison.Ordinal)
|
||||
|| lowerName.EndsWith(".kmz", StringComparison.Ordinal)
|
||||
|| lowerName.EndsWith(".geojson", StringComparison.Ordinal)
|
||||
|| await IsGeoJsonAsync(incoming.Path))
|
||||
{
|
||||
var content = Convert.ToBase64String(await File.ReadAllBytesAsync(incoming.Path));
|
||||
await JS.InvokeAsync<string>("lmeMap.importExternalGisFile", incoming.FileName, content, incoming.ContentType);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lowerName.EndsWith(".zip", StringComparison.Ordinal))
|
||||
{
|
||||
var count = await ProjectStorageService.RestoreBackupAsync(incoming.Path);
|
||||
await RefreshProjectsAsync();
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Backup aperto: {count} progetti ripristinati.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lowerName.EndsWith(".json", StringComparison.Ordinal))
|
||||
{
|
||||
var imported = await ProjectStorageService.ImportProjectAsync(incoming.Path);
|
||||
await RefreshProjectsAsync();
|
||||
SelectedProjectId = imported.Id;
|
||||
await RefreshProjectVersionsAsync(true);
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Progetto aperto: {imported.Name}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Formato non riconosciuto: {incoming.FileName}.");
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
await JS.InvokeVoidAsync("lmeMap.showInfo", $"Impossibile aprire {incoming.FileName}: {error.GetBaseException().Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { File.Delete(incoming.Path); } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<bool> IsGeoJsonAsync(string path)
|
||||
{
|
||||
if (!Path.GetExtension(path).Equals(".json", StringComparison.OrdinalIgnoreCase)) return false;
|
||||
try
|
||||
{
|
||||
await using var stream = File.OpenRead(path);
|
||||
using var document = await System.Text.Json.JsonDocument.ParseAsync(stream);
|
||||
if (!document.RootElement.TryGetProperty("type", out var typeProperty)) return false;
|
||||
var type = typeProperty.GetString();
|
||||
return type is "Feature" or "FeatureCollection" or "Point" or "MultiPoint"
|
||||
or "LineString" or "MultiLineString" or "Polygon" or "MultiPolygon"
|
||||
or "GeometryCollection";
|
||||
}
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
private static readonly FilePickerFileType ProjectPickerFileTypes = new(new Dictionary<DevicePlatform, IEnumerable<string>>
|
||||
{
|
||||
[DevicePlatform.Android] = ["application/json", "text/json", "text/plain", "application/octet-stream"],
|
||||
[DevicePlatform.WinUI] = [".json"],
|
||||
[DevicePlatform.iOS] = ["public.json", "public.data"],
|
||||
[DevicePlatform.macOS] = ["public.json", "public.data"]
|
||||
});
|
||||
|
||||
private static readonly FilePickerFileType BackupPickerFileTypes = new(new Dictionary<DevicePlatform, IEnumerable<string>>
|
||||
{
|
||||
[DevicePlatform.Android] = ["application/zip", "application/x-zip-compressed", "application/octet-stream"],
|
||||
[DevicePlatform.WinUI] = [".zip"],
|
||||
[DevicePlatform.iOS] = ["public.zip-archive", "public.data"],
|
||||
[DevicePlatform.macOS] = ["public.zip-archive", "public.data"]
|
||||
});
|
||||
|
||||
private async Task LoadProjectVersion()
|
||||
{
|
||||
if (SelectedProject is null || string.IsNullOrWhiteSpace(SelectedVersionId)) return;
|
||||
@@ -2121,6 +2219,7 @@
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
IncomingFiles.FileAvailable -= OnIncomingFileAvailable;
|
||||
CancelCatalogWork();
|
||||
LocationService.StopTracking();
|
||||
GpsLookupCancellation?.Cancel();
|
||||
|
||||
Reference in new issue
Block a user