From a1dfd3b1e78d129fe483fd3328787a89a06c7b50 Mon Sep 17 00:00:00 2001 From: DaPi Date: Tue, 20 Aug 2024 12:28:28 +0200 Subject: [PATCH] BarcodeScanner --- Jugenddienst Stunden/App.xaml.cs | 2 +- .../Jugenddienst Stunden.csproj | 5 +- Jugenddienst Stunden/MauiProgram.cs | 7 +- Jugenddienst Stunden/Models/Hours.cs | 6 +- Jugenddienst Stunden/Models/Stunde.cs | 28 +++-- Jugenddienst Stunden/Platforms/iOS/Info.plist | 4 +- .../Resources/AppIcon/appicon.svg | 7 +- .../Resources/AppIcon/appiconfg.svg | 17 +-- .../Resources/Splash/splash.svg | 22 +++- .../ViewModels/AboutViewModel.cs | 34 ++++-- .../ViewModels/StundenViewModel.cs | 16 ++- Jugenddienst Stunden/Views/AboutPage.xaml | 8 +- Jugenddienst Stunden/Views/AboutPage.xaml.cs | 18 +++ Jugenddienst Stunden/Views/StundenPage.xaml | 17 ++- Jugenddienst Stunden/efpt.config.json | 110 ------------------ appicon.afdesign | Bin 0 -> 9036 bytes appiconfg.afdesign | Bin 28064 -> 24855 bytes splash.afdesign | Bin 0 -> 23498 bytes 18 files changed, 138 insertions(+), 163 deletions(-) delete mode 100644 Jugenddienst Stunden/efpt.config.json create mode 100644 appicon.afdesign create mode 100644 splash.afdesign diff --git a/Jugenddienst Stunden/App.xaml.cs b/Jugenddienst Stunden/App.xaml.cs index c46a73a..92a98c0 100644 --- a/Jugenddienst Stunden/App.xaml.cs +++ b/Jugenddienst Stunden/App.xaml.cs @@ -10,7 +10,7 @@ namespace Jugenddienst_Stunden { //Models.Auth.Main(new string[] { "http://hours.dauni.mine.nu:81/appapi", "OTI6Y1JVUS9RTG1jMTZUbnN2c2JZRm5yRDNiUTZz" }); //Angelika //Models.Auth.Main(new string[] { "http://hours.dauni.mine.nu:81/appapi", "Njc6cjltcVJ1SmtITUtFZ3llUVpJcWJzc2NDejVZ" }); //Dario - Models.Auth.Main(new string[] { "http://hours.dauni.mine.nu:81/appapi?hours", "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=" }); //Christine + //Models.Auth.Main(new string[] { "http://hours.dauni.mine.nu:81/appapi?hours", "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=" }); //Christine } } diff --git a/Jugenddienst Stunden/Jugenddienst Stunden.csproj b/Jugenddienst Stunden/Jugenddienst Stunden.csproj index 86a10da..5bf59a7 100644 --- a/Jugenddienst Stunden/Jugenddienst Stunden.csproj +++ b/Jugenddienst Stunden/Jugenddienst Stunden.csproj @@ -2,7 +2,6 @@ net8.0-ios;net8.0-maccatalyst;net8.0-android34.0 - $(TargetFrameworks);net8.0-windows10.0.17763.0 @@ -32,7 +31,7 @@ 11.0 13.1 - 34.0 + 29.0 10.0.17763.0 10.0.17763.0 6.5 @@ -57,7 +56,6 @@ - true @@ -66,6 +64,7 @@ + diff --git a/Jugenddienst Stunden/MauiProgram.cs b/Jugenddienst Stunden/MauiProgram.cs index 84a47d6..64d4da6 100644 --- a/Jugenddienst Stunden/MauiProgram.cs +++ b/Jugenddienst Stunden/MauiProgram.cs @@ -1,7 +1,6 @@ -using BarcodeScanning; +//using BarcodeScanning; using Microsoft.Extensions.Logging; - -using Microsoft.Maui.Hosting; +using ZXing.Net.Maui.Controls; namespace Jugenddienst_Stunden { @@ -14,7 +13,7 @@ namespace Jugenddienst_Stunden { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }) - .UseBarcodeScanning(); + .UseBarcodeReader(); #if DEBUG builder.Logging.AddDebug(); diff --git a/Jugenddienst Stunden/Models/Hours.cs b/Jugenddienst Stunden/Models/Hours.cs index 1b605ea..d33d497 100644 --- a/Jugenddienst Stunden/Models/Hours.cs +++ b/Jugenddienst Stunden/Models/Hours.cs @@ -1,13 +1,15 @@  +using CommunityToolkit.Mvvm.ComponentModel; + namespace Jugenddienst_Stunden.Models { - public class Hours { + public class Hours : ObservableObject { public string zeit; public string nominal; public Dictionary nominal_day_api; public Dictionary nominal_week_api; //public List time_line; public string zeit_total; - //public List zeit_total_daily; + public Dictionary zeit_total_daily; //public List wochensumme; public string overtime_month; public string overtime; diff --git a/Jugenddienst Stunden/Models/Stunde.cs b/Jugenddienst Stunden/Models/Stunde.cs index a8410cd..1effe77 100644 --- a/Jugenddienst Stunden/Models/Stunde.cs +++ b/Jugenddienst Stunden/Models/Stunde.cs @@ -1,11 +1,15 @@ using CommunityToolkit.Mvvm.ComponentModel; using Newtonsoft.Json; +using Microsoft.Maui.Networking; +using Microsoft.Maui.Controls; + namespace Jugenddienst_Stunden.Models { internal class Stunde : ObservableObject { private static readonly string BaseAddress = "http://hours.dauni.mine.nu:81"; - private static readonly string apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Christine + //private static readonly string apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Christine + private static readonly string apiKey = "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Damian private static readonly string requestUrl = $"{BaseAddress}/appapi?hours"; public DateTime Date { get; set; } @@ -13,15 +17,23 @@ namespace Jugenddienst_Stunden.Models { public static async Task LoadData() { - string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey); + Hours hours = new Hours(); + if (Connectivity.Current.NetworkAccess == NetworkAccess.None) { + await App.Current.MainPage.DisplayAlert("Keine Internetverbindung", + "Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.", + "OK"); + //throw new Exception("Keine Internetverbindung"); + } else { + string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey); + + if (data == null) { + throw new Exception("Keine Daten erhalten"); + } + + hours = JsonConvert.DeserializeObject(data); - if(data == null) { - throw new Exception("Keine Daten erhalten"); } - - Hours hours = JsonConvert.DeserializeObject(data); - - return hours ?? new Hours(); + return hours; } diff --git a/Jugenddienst Stunden/Platforms/iOS/Info.plist b/Jugenddienst Stunden/Platforms/iOS/Info.plist index 24abae1..8bdc015 100644 --- a/Jugenddienst Stunden/Platforms/iOS/Info.plist +++ b/Jugenddienst Stunden/Platforms/iOS/Info.plist @@ -16,8 +16,6 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad @@ -30,5 +28,7 @@ This app uses barcode scanning to... XSAppIconAssets Assets.xcassets/appicon.appiconset + CFBundleIdentifier + diff --git a/Jugenddienst Stunden/Resources/AppIcon/appicon.svg b/Jugenddienst Stunden/Resources/AppIcon/appicon.svg index 9d63b65..773e284 100644 --- a/Jugenddienst Stunden/Resources/AppIcon/appicon.svg +++ b/Jugenddienst Stunden/Resources/AppIcon/appicon.svg @@ -1,4 +1,5 @@ - - - \ No newline at end of file + + + + diff --git a/Jugenddienst Stunden/Resources/AppIcon/appiconfg.svg b/Jugenddienst Stunden/Resources/AppIcon/appiconfg.svg index 4d26d0f..0a06b2f 100644 --- a/Jugenddienst Stunden/Resources/AppIcon/appiconfg.svg +++ b/Jugenddienst Stunden/Resources/AppIcon/appiconfg.svg @@ -1,15 +1,18 @@ - - - + + + - - + + - - + + + + + diff --git a/Jugenddienst Stunden/Resources/Splash/splash.svg b/Jugenddienst Stunden/Resources/Splash/splash.svg index 21dfb25..7194907 100644 --- a/Jugenddienst Stunden/Resources/Splash/splash.svg +++ b/Jugenddienst Stunden/Resources/Splash/splash.svg @@ -1,8 +1,18 @@ - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + diff --git a/Jugenddienst Stunden/ViewModels/AboutViewModel.cs b/Jugenddienst Stunden/ViewModels/AboutViewModel.cs index 22e2d59..82bbb02 100644 --- a/Jugenddienst Stunden/ViewModels/AboutViewModel.cs +++ b/Jugenddienst Stunden/ViewModels/AboutViewModel.cs @@ -1,6 +1,7 @@ using CommunityToolkit.Mvvm.Input; using System.Windows.Input; -using BarcodeScanning; +using Microsoft.Maui.Dispatching; +//using BarcodeScanning; namespace Jugenddienst_Stunden.ViewModels { internal class AboutViewModel { @@ -19,14 +20,31 @@ namespace Jugenddienst_Stunden.ViewModels { async Task ShowMoreInfo() => await Launcher.Default.OpenAsync(MoreInfoUrl); - - private static void BarcodesDetected(object sender, OnDetectionFinishedEventArg e) { - if (e.BarcodeResults.Length > 0) { - // Hier verarbeiten Sie den erkannten Barcode - Console.WriteLine($"Detected barcode: {e.BarcodeResults.GetType()} {e.BarcodeResults.ToString()}"); - } - } + //private async void SetupBarcodeScanner() { + // try { + // var scanner = new BarcodeScanner(); + // var result = await scanner.ScanAsync(); + + // if (result != null) { + // await DisplayAlert("Scan-Ergebnis", $"Barcode: {result.Barcode}", "OK"); + // } else { + // await DisplayAlert("Scan Abgebrochen", "Der Barcode-Scan wurde abgebrochen.", "OK"); + // } + // } catch (Exception ex) { + // await DisplayAlert("Fehler", $"Ein Fehler ist aufgetreten: {ex.Message}", "OK"); + // } + //} + + //private static void BarcodesDetected(object sender, OnDetectionFinishedEventArg e) { + // if (e.BarcodeResults.Length > 0) { + // // Hier verarbeiten Sie den erkannten Barcode + // //Console.WriteLine($"Detected barcode: {e.BarcodeResults.GetType()} {e.BarcodeResults.ToString()}"); + // await DisplayAlert("Scan-Ergebnis", $"Barcode: {e.BarcodeResults.GetType()} {e.BarcodeResults.ToString()}", "OK"); + // } + //} + + } } diff --git a/Jugenddienst Stunden/ViewModels/StundenViewModel.cs b/Jugenddienst Stunden/ViewModels/StundenViewModel.cs index d1f4e3d..4a8b9d9 100644 --- a/Jugenddienst Stunden/ViewModels/StundenViewModel.cs +++ b/Jugenddienst Stunden/ViewModels/StundenViewModel.cs @@ -1,6 +1,8 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System.Windows.Input; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Networking; namespace Jugenddienst_Stunden.ViewModels { @@ -16,6 +18,12 @@ namespace Jugenddienst_Stunden.ViewModels { public Models.Hours Hours { get => _hour; } + public string ZeitDone { + get => _hour.zeit; + } + public string ZeitCalculated { + get => _hour.zeit_total; + } public string Nominal { get => _hour.nominal; } @@ -35,14 +43,18 @@ namespace Jugenddienst_Stunden.ViewModels { // await Models.Stunde.LoadData(); public async Task LoadData() { - _hour = await Models.Stunde.LoadData(); - RefreshProperties(); + _hour = await Models.Stunde.LoadData(); + Models.Hours Hours = new Models.Hours(); + RefreshProperties(); } private void RefreshProperties() { OnPropertyChanged(nameof(Nominal)); OnPropertyChanged(nameof(Overtime)); OnPropertyChanged(nameof(OvertimeMonth)); + OnPropertyChanged(nameof(ZeitCalculated)); + OnPropertyChanged(nameof(ZeitDone)); + OnPropertyChanged(nameof(Hours)); } } diff --git a/Jugenddienst Stunden/Views/AboutPage.xaml b/Jugenddienst Stunden/Views/AboutPage.xaml index ec439be..0f2a1cc 100644 --- a/Jugenddienst Stunden/Views/AboutPage.xaml +++ b/Jugenddienst Stunden/Views/AboutPage.xaml @@ -2,8 +2,9 @@ + @@ -24,6 +25,11 @@ OnDetectionFinished="BarcodesDetected" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />--> + + diff --git a/Jugenddienst Stunden/Views/AboutPage.xaml.cs b/Jugenddienst Stunden/Views/AboutPage.xaml.cs index 91940c1..8d158b5 100644 --- a/Jugenddienst Stunden/Views/AboutPage.xaml.cs +++ b/Jugenddienst Stunden/Views/AboutPage.xaml.cs @@ -1,3 +1,5 @@ +using ZXing; +using ZXing.Net.Maui.Controls; namespace Jugenddienst_Stunden.Views; public partial class AboutPage : ContentPage @@ -5,6 +7,22 @@ public partial class AboutPage : ContentPage public AboutPage() { InitializeComponent(); + barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions { + Formats = ZXing.Net.Maui.BarcodeFormat.QrCode, + AutoRotate = true, + Multiple = false + }; + + } + + private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) { + var first = e.Results?.FirstOrDefault(); + if (first is null) { + return; + } + Dispatcher.DispatchAsync(async () => { + await DisplayAlert("Scan-Ergebnis", $"Barcode: {first.Value}", "OK"); + }); } } \ No newline at end of file diff --git a/Jugenddienst Stunden/Views/StundenPage.xaml b/Jugenddienst Stunden/Views/StundenPage.xaml index f8665cd..2f2ddf8 100644 --- a/Jugenddienst Stunden/Views/StundenPage.xaml +++ b/Jugenddienst Stunden/Views/StundenPage.xaml @@ -12,14 +12,19 @@