Megy a program letöltése is...

This commit is contained in:
2025-04-06 19:33:47 +02:00
parent dc3e6e2f7b
commit a64304a05f
11 changed files with 242 additions and 32 deletions
+1
View File
@@ -16,6 +16,7 @@
<ShellContent Title="Login" ContentTemplate="{DataTemplate security:LoginPage}" Route="LoginPage" /> <ShellContent Title="Login" ContentTemplate="{DataTemplate security:LoginPage}" Route="LoginPage" />
<ShellContent Title="NFC Test" ContentTemplate="{DataTemplate nfc:NFCTestPage}" Route="NFCTestPage" /> <ShellContent Title="NFC Test" ContentTemplate="{DataTemplate nfc:NFCTestPage}" Route="NFCTestPage" />
<ShellContent Title="Sync data" ContentTemplate="{DataTemplate system:SyncPage}" Route="SyncPage" /> <ShellContent Title="Sync data" ContentTemplate="{DataTemplate system:SyncPage}" Route="SyncPage" />
<ShellContent Title="Download APK" ContentTemplate="{DataTemplate system:DownloadAPKPage}" Route="DownloadAPKPage" />
<ShellContent Title="Base" ContentTemplate="{DataTemplate base:BaseStockPage}" Route="BaseStockPage" /> <ShellContent Title="Base" ContentTemplate="{DataTemplate base:BaseStockPage}" Route="BaseStockPage" />
<ShellContent Title="Checkpoints" ContentTemplate="{DataTemplate base:CheckPointsPage}" Route="CheckPointsPage" /> <ShellContent Title="Checkpoints" ContentTemplate="{DataTemplate base:CheckPointsPage}" Route="CheckPointsPage" />
+16
View File
@@ -5,6 +5,14 @@
Title="Főmenü" Title="Főmenü"
BackgroundColor="#f0f0f0"> BackgroundColor="#f0f0f0">
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="DeviceId"
Text="MK001"
Order="Primary"
Priority="0" />
<!--<ToolbarItem Text="Gomb" Order="Primary" Priority="1" Clicked="OnButtonAction" />-->
</ContentPage.ToolbarItems>
<Grid RowDefinitions="Auto, * , Auto" Padding="30,0"> <Grid RowDefinitions="Auto, * , Auto" Padding="30,0">
<ScrollView Grid.Row="1" <ScrollView Grid.Row="1"
@@ -17,6 +25,12 @@
HasShadow="True"> HasShadow="True">
<VerticalStackLayout> <VerticalStackLayout>
<Label Text="Alapműveletek" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" /> <Label Text="Alapműveletek" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
<Button
x:Name="DownloadAPK" Margin="5"
Text="Program letöltése"
SemanticProperties.Hint="Program letöltése"
Clicked="OnButtonDownloadAPK"
HorizontalOptions="Fill" />
<Button <Button
x:Name="ButtonSync" Margin="5" x:Name="ButtonSync" Margin="5"
Text="Adatok szinkronizálása" Text="Adatok szinkronizálása"
@@ -78,4 +92,6 @@
</Grid> </Grid>
</ContentPage> </ContentPage>
+28 -27
View File
@@ -13,37 +13,38 @@ namespace WorkFlowCheck.MAUI
InitializeComponent(); InitializeComponent();
_userService = userService; _userService = userService;
} }
//public void Initialize(IUserService userService)
//{
// _userService = userService;
//}
//private void OnCounterClicked(object sender, EventArgs e)
//{
// count++;
// if (count == 1) override protected async void OnAppearing()
// CounterBtn.Text = $"Clicked {count} time"; {
// else base.OnAppearing();
// CounterBtn.Text = $"Clicked {count} times"; var currentUser = _userService.GetCurrentUser();
DeviceId.Text = DeviceInfo.Current.Idiom.ToString();
if (currentUser != null)
{
foreach (var role in currentUser.RoleDTO)
{
if (role.RoleName == "Admin")
{
// SemanticScreenReader.Announce(CounterBtn.Text); }
//} else
{
}
}
}
}
private async void OnButtonAction(object sender, EventArgs e)
{
}
private void OnButtonDownloadAPK(object sender, EventArgs e)
{
Shell.Current.GoToAsync("//DownloadAPKPage");
}
private async void OnButtonGetUser(object sender, EventArgs e) private async void OnButtonGetUser(object sender, EventArgs e)
{ {
//var response = await _userService.GetUserAsync();
//if (response != null)
//{
// try
// {
// WelcomeLabel.Text = response.Data.FirstName;
// }
// catch (Exception ex)
// {
// WelcomeLabel.Text = ex.Message;
// }
//}
await Navigation.PushAsync(new CaptureImagePage()); await Navigation.PushAsync(new CaptureImagePage());
} }
private async void OnButtonNFCTest(object sender, EventArgs e) private async void OnButtonNFCTest(object sender, EventArgs e)
@@ -24,7 +24,7 @@
Text="Mégse" Text="Mégse"
FontSize="18" FontSize="18"
TextColor="White" TextColor="White"
HorizontalOptions="Center" HorizontalOptions="Fill"
Clicked="OnCancelButtonClicked" /> Clicked="OnCancelButtonClicked" />
</VerticalStackLayout> </VerticalStackLayout>
</Frame> </Frame>
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.System.DownloadAPKPage"
Title="Program letöltés">
<ScrollView>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Frame
Grid.Row="1"
BorderColor="Gray"
CornerRadius="20"
Padding="30"
Margin="1"
HasShadow="True"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="{OnPlatform Android=350, iOS=350, WinUI=400, MacCatalyst=400}"
MaximumWidthRequest="500">
<VerticalStackLayout Margin="10,10,10,0">
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
<Button x:Name="SyncBtn" Text="Program letöltés" Clicked="OnSyncClicked" Margin="10,10,10,10" />
<ActivityIndicator x:Name="LoadingIndicator"
IsRunning="False"
IsVisible="False"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</Frame>
</Grid>
</ScrollView>
</ContentPage>
@@ -0,0 +1,54 @@
using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI.Pages.System;
public partial class DownloadAPKPage : ContentPage
{
private ISyncService _syncService;
public DownloadAPKPage()
{
InitializeComponent();
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
}
private async void OnSyncClicked(object sender, EventArgs e)
{
SyncBtn.IsEnabled = false;
LoadingIndicator.IsRunning = true;
LoadingIndicator.IsVisible = true;
progressLabel.Text = "Letöltés indítása...";
progressBar.Progress = 0;
try
{
await Task.Run(async () =>
{
await _syncService.DownloadAPK((percentage, infostring) =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
progressBar.Progress = percentage / 100;
progressLabel.Text = $"{infostring}: {percentage:0.00}%";
});
});
});
progressLabel.Text = "Letöltés kész!";
await Shell.Current.GoToAsync("//MainPage");
}
catch (Exception ex)
{
progressLabel.Text = $"Hiba történt: {ex.Message}";
}
finally
{
SyncBtn.IsEnabled = true;
LoadingIndicator.IsVisible = false;
LoadingIndicator.IsRunning = false;
}
}
protected override bool OnBackButtonPressed()
{
Shell.Current.GoToAsync("//MainPage");
return true;
}
}
@@ -4,8 +4,17 @@
<application android:allowBackup="true" <application android:allowBackup="true"
android:icon="@mipmap/appicon" android:icon="@mipmap/appicon"
android:supportsRtl="true" android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:label="Workflow Check App"> android:label="Workflow Check App">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.nuvolar.wfcapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application> </application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="Android/data/com.nuvolar.wfcapp/files/APK/" />
</paths>
@@ -10,6 +10,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
public interface ISyncService public interface ISyncService
{ {
Task SyncDatas(Action<double, string> reportProgress); Task SyncDatas(Action<double, string> reportProgress);
Task DownloadAPK(Action<double, string> reportProgress);
Task SyncCheckPoints_Down(Action<double, string> reportProgress); Task SyncCheckPoints_Down(Action<double, string> reportProgress);
Task<ApiResponseDTO<string>> SyncCheckPoints_Up(Action<double, string> reportProgress); Task<ApiResponseDTO<string>> SyncCheckPoints_Up(Action<double, string> reportProgress);
Task SyncLocations_Down(Action<double, string> reportProgress); Task SyncLocations_Down(Action<double, string> reportProgress);
+80 -1
View File
@@ -1,4 +1,5 @@
using AutoMapper; using Android.Content;
using AutoMapper;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
@@ -27,6 +28,84 @@ namespace WorkFlowCheck.MAUI.Services
await SyncCheckListTemplates_Down(reportProgress); await SyncCheckListTemplates_Down(reportProgress);
await SyncCheckListHeader_Down(reportProgress); await SyncCheckListHeader_Down(reportProgress);
} }
public async Task DownloadAPK(Action<double, string> reportProgress)
{
try
{
await PrepareAuthenticatedRequestAsync();
string endpoint = $"{_httpClient.BaseAddress}api/Sync/Download";
string fileName = "com.nuvolar.wfcapp-Signed.apk";
// Az Androidon lévő privát letöltési mappa
string downloadFolder = Path.Combine(Android.App.Application.Context.GetExternalFilesDir(null)?.AbsolutePath, "APK");
// Ellenőrizd, hogy a mappa létezik-e, ha nem, hozd létre
if (!Directory.Exists(downloadFolder))
{
Directory.CreateDirectory(downloadFolder);
}
string filePath = Path.Combine(downloadFolder, fileName);
using (_httpClient)
{
var response = await _httpClient.GetAsync(endpoint, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var totalBytes = response.Content.Headers.ContentLength ?? -1L;
long receivedBytes = 0;
using (var stream = await response.Content.ReadAsStreamAsync())
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
byte[] buffer = new byte[1024 * 1024]
;
int bytesRead;
while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await fileStream.WriteAsync(buffer, 0, bytesRead);
receivedBytes += bytesRead;
if (totalBytes != -1)
{
double progress = (double)receivedBytes / totalBytes * 100;
reportProgress(progress, $"APK letöltés...");
}
else
{
reportProgress(-1, $"APK letöltés...");
}
}
}
// Telepítés indítása a FileProvider segítségével
var apkUri = FileProvider.GetUriForFile(Android.App.Application.Context,
$"{Android.App.Application.Context.PackageName}.fileprovider",
new Java.IO.File(filePath));
var installIntent = new Intent(Intent.ActionView);
installIntent.SetDataAndType(apkUri, "application/vnd.android.package-archive");
installIntent.AddFlags(ActivityFlags.NewTask);
installIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
Android.App.Application.Context.StartActivity(installIntent);
}
else
{
reportProgress(0, $"Letöltési hiba: {response.StatusCode}");
Console.WriteLine($"Letöltési hiba: {response.StatusCode}");
}
}
}
catch (Exception ex)
{
reportProgress(0, $"Hiba történt: {ex.Message}");
Console.WriteLine($"Hiba történt: {ex.Message}");
}
}
public async Task SyncCheckPoints_Down(Action<double, string> reportProgress) public async Task SyncCheckPoints_Down(Action<double, string> reportProgress)
{ {
try try
@@ -55,6 +55,10 @@
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<AndroidResource Include="Platforms\Android\Resources\xml\file_paths.xml" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" /> <PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" /> <PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" />
@@ -134,6 +138,9 @@
<MauiXaml Update="Pages\Security\LoginPage.xaml"> <MauiXaml Update="Pages\Security\LoginPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Pages\System\DownloadAPKPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\System\SyncPage.xaml"> <MauiXaml Update="Pages\System\SyncPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>