diff --git a/Jugenddienst Stunden/AppShell.xaml b/Jugenddienst Stunden/AppShell.xaml
index 41e9097..147ca19 100644
--- a/Jugenddienst Stunden/AppShell.xaml
+++ b/Jugenddienst Stunden/AppShell.xaml
@@ -18,7 +18,7 @@
Icon="{OnPlatform 'icon_about.png', iOS='icon_about_ios.png', MacCatalyst='icon_about_ios.png'}" />
diff --git a/Jugenddienst Stunden/Models/Auth.cs b/Jugenddienst Stunden/Models/Auth.cs
index 1ca2b9b..5cf2999 100644
--- a/Jugenddienst Stunden/Models/Auth.cs
+++ b/Jugenddienst Stunden/Models/Auth.cs
@@ -2,6 +2,7 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
+using ZXing.QrCode.Internal;
namespace Jugenddienst_Stunden.Models
{
@@ -14,6 +15,8 @@ namespace Jugenddienst_Stunden.Models
public static async Task GetApiDataWithAuthAsync(string url, string token) {
using (HttpClient client = new HttpClient()) {
try {
+ client.DefaultRequestHeaders.Add("Accept", "application/json");
+
// Hinzufügen des Bearer-Tokens zum Authorization-Header
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
diff --git a/Jugenddienst Stunden/Models/Hours.cs b/Jugenddienst Stunden/Models/Hours.cs
index d33d497..765100b 100644
--- a/Jugenddienst Stunden/Models/Hours.cs
+++ b/Jugenddienst Stunden/Models/Hours.cs
@@ -9,7 +9,7 @@ namespace Jugenddienst_Stunden.Models {
public Dictionary nominal_week_api;
//public List time_line;
public string zeit_total;
- public Dictionary zeit_total_daily;
+ public Dictionary? zeit_total_daily;
//public List wochensumme;
public string overtime_month;
public string overtime;
diff --git a/Jugenddienst Stunden/Models/Operator.cs b/Jugenddienst Stunden/Models/Operator.cs
index 355deb3..29910aa 100644
--- a/Jugenddienst Stunden/Models/Operator.cs
+++ b/Jugenddienst Stunden/Models/Operator.cs
@@ -1,6 +1,10 @@
+using CommunityToolkit.Mvvm.ComponentModel;
+using Newtonsoft.Json;
+using System.Text;
+
namespace Jugenddienst_Stunden.Models {
- public class Operator {
+ public class Operator : ObservableObject {
public string id;
public string name;
public string surname;
@@ -23,5 +27,29 @@ namespace Jugenddienst_Stunden.Models {
public string year;
//public List? timetable;
+
+
+
+ public static async Task LoadData(string apiKey) {
+ //var apiKey = Preferences.Default.Get("apiKey", "");
+ Operator OperatorVar = new Operator();
+ //Operator operator = new Operator();
+ 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 {
+ var tokendata = new TokenData(apiKey);
+ string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
+ if (data != null) {
+ OperatorVar = Newtonsoft.Json.JsonConvert.DeserializeObject(data);
+ Preferences.Default.Set("name", OperatorVar.name);
+ Preferences.Default.Set("surname", OperatorVar.surname);
+ }
+
+ }
+ return OperatorVar;
+ }
}
}
diff --git a/Jugenddienst Stunden/Models/Stunde.cs b/Jugenddienst Stunden/Models/Stunde.cs
index d114c47..87da5b6 100644
--- a/Jugenddienst Stunden/Models/Stunde.cs
+++ b/Jugenddienst Stunden/Models/Stunde.cs
@@ -2,35 +2,48 @@
using Newtonsoft.Json;
using Microsoft.Maui.Networking;
using Microsoft.Maui.Controls;
+using System;
+using System.Text;
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
- public static string apiKey = "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Damian
- private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
+ //Katharina
+ public static string apiKey = Preferences.Default.Get("apiKey", "MTAyfEJZZnB1L3VwcnhoVms0dDlLZENPZWtUVy85b3xodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
+
+ //Damian
+ //public static string apiKey = Preferences.Default.Get("apiKey", "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
+
+ //private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
public DateTime Date { get; set; }
- public static async Task LoadData() {
+
+ public static async Task LoadData() {
+
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);
+ var tokendata = new TokenData(apiKey);
+
+ //string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
+ string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours", tokendata.apiKey);
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
hours = JsonConvert.DeserializeObject(data);
+ //Preferences.Default.Set("name", hours.operator_api.name);
+ //Preferences.Default.Set("surname", hours.operator_api.surname);
+
}
return hours;
diff --git a/Jugenddienst Stunden/Models/TokenData.cs b/Jugenddienst Stunden/Models/TokenData.cs
new file mode 100644
index 0000000..7854925
--- /dev/null
+++ b/Jugenddienst Stunden/Models/TokenData.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+namespace Jugenddienst_Stunden.Models {
+ class TokenData {
+ public string token { get; set; }
+ public string apiKey { get; set; }
+ public string url { get; set; }
+ public string operator_id { get; set; }
+
+ public TokenData(string apiKey) {
+ string dat = Encoding.UTF8.GetString(System.Convert.FromBase64String(apiKey));
+ this.token = dat.Split('|')[1]; ;
+ this.url = dat.Split('|')[2]; ;
+ this.operator_id = dat.Split('|')[0]; ;
+ this.apiKey = apiKey;
+ }
+ }
+}
diff --git a/Jugenddienst Stunden/ViewModels/AboutViewModel.cs b/Jugenddienst Stunden/ViewModels/AboutViewModel.cs
index 82bbb02..1e2e190 100644
--- a/Jugenddienst Stunden/ViewModels/AboutViewModel.cs
+++ b/Jugenddienst Stunden/ViewModels/AboutViewModel.cs
@@ -7,19 +7,21 @@ namespace Jugenddienst_Stunden.ViewModels {
internal class AboutViewModel {
public string Title => AppInfo.Name;
public string Version => AppInfo.VersionString;
- public string MoreInfoUrl => "https://aka.ms/maui";
- public string Message => "This app is written in XAML and C# with .NET MAUI.";
- public ICommand ShowMoreInfoCommand { get; }
+
+ public string Message => "Scanne den QR-Code von deinem Benutzerprofil auf der Stundenseite.";
- public AboutViewModel() {
- ShowMoreInfoCommand = new AsyncRelayCommand(ShowMoreInfo);
- }
-
- async Task ShowMoreInfo() =>
- await Launcher.Default.OpenAsync(MoreInfoUrl);
+ //private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
+ // var first = e.Results?.FirstOrDefault();
+ // if (first is null) {
+ // return;
+ // }
+ // System.Windows.Application.Current.Dispatcher.DispatchAsync(async () => {
+ // await DisplayAlert("Scan-Ergebnis", $"Barcode: {first.Value}", "OK");
+ // });
+ //}
//private async void SetupBarcodeScanner() {
// try {
@@ -44,7 +46,7 @@ namespace Jugenddienst_Stunden.ViewModels {
// }
//}
-
+
}
}
diff --git a/Jugenddienst Stunden/ViewModels/StundenViewModel.cs b/Jugenddienst Stunden/ViewModels/StundenViewModel.cs
index ecdf4c2..77bbb74 100644
--- a/Jugenddienst Stunden/ViewModels/StundenViewModel.cs
+++ b/Jugenddienst Stunden/ViewModels/StundenViewModel.cs
@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.Input;
using System.Windows.Input;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Networking;
+using ZXing.Net.Maui;
namespace Jugenddienst_Stunden.ViewModels {
@@ -33,6 +34,7 @@ namespace Jugenddienst_Stunden.ViewModels {
public string OvertimeMonth {
get => _hour.overtime_month;
}
+ public string Title { get; set; } = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
public StundenViewModel() {
_hour = new Models.Hours();
@@ -43,9 +45,10 @@ namespace Jugenddienst_Stunden.ViewModels {
// await Models.Stunde.LoadData();
public async Task LoadData() {
- _hour = await Models.Stunde.LoadData();
- Models.Hours Hours = new Models.Hours();
- RefreshProperties();
+ _hour = await Models.Stunde.LoadData();
+ Models.Hours Hours = new Models.Hours();
+ //Title = _hour.operator_api.name + " " + _hour.operator_api.surname;
+ RefreshProperties();
}
private void RefreshProperties() {
@@ -55,8 +58,9 @@ namespace Jugenddienst_Stunden.ViewModels {
OnPropertyChanged(nameof(ZeitCalculated));
OnPropertyChanged(nameof(ZeitDone));
OnPropertyChanged(nameof(Hours));
+ OnPropertyChanged(nameof(Title));
}
-
+
}
}
diff --git a/Jugenddienst Stunden/Views/AboutPage.xaml b/Jugenddienst Stunden/Views/AboutPage.xaml
index 0f2a1cc..5e43fc1 100644
--- a/Jugenddienst Stunden/Views/AboutPage.xaml
+++ b/Jugenddienst Stunden/Views/AboutPage.xaml
@@ -19,17 +19,15 @@
-
+
-
+
+ VerticalOptions="FillAndExpand"
+ Margin="0,60,0,0"/>
diff --git a/Jugenddienst Stunden/Views/AboutPage.xaml.cs b/Jugenddienst Stunden/Views/AboutPage.xaml.cs
index 73070ca..8df3859 100644
--- a/Jugenddienst Stunden/Views/AboutPage.xaml.cs
+++ b/Jugenddienst Stunden/Views/AboutPage.xaml.cs
@@ -1,3 +1,4 @@
+using Jugenddienst_Stunden.Models;
using Microsoft.Maui.Controls;
using System.Collections.Generic;
using ZXing.Net.Maui;
@@ -21,15 +22,31 @@ public partial class AboutPage : ContentPage {
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
//var first = e.Results?.FirstOrDefault();
-
var currentTime = DateTime.Now;
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
_lastDetectionTime = currentTime;
foreach (var barcode in e.Results) {
- MainThread.InvokeOnMainThreadAsync(() => {
- DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
- Models.Stunde.apiKey = barcode.Value;
- });
+ if (Preferences.Default.Get("apiKey", "") != barcode.Value) {
+ MainThread.InvokeOnMainThreadAsync(async() => {
+ //DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
+ Preferences.Default.Set("apiKey", barcode.Value);
+
+ Models.Stunde.apiKey = barcode.Value;
+
+ var op = await Models.Operator.LoadData(barcode.Value);
+ Preferences.Default.Set("name", op.name);
+ Preferences.Default.Set("surname", op.surname);
+ DisplayAlert("Neuer Barcode erkannt", op.name + " " + op.surname, "OK");
+
+
+ });
+ } else {
+ MainThread.InvokeOnMainThreadAsync(() => {
+ DisplayAlert("Barcode bereits vorhanden",
+ Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", ""),
+ "OK");
+ });
+ }
}
}
@@ -50,12 +67,12 @@ public partial class AboutPage : ContentPage {
base.OnDisappearing();
barcodeScannerView.CameraLocation = CameraLocation.Front;
barcodeScannerView.IsDetecting = false;
-
+
}
protected override void OnAppearing() {
base.OnAppearing();
-
+
barcodeScannerView.IsDetecting = true;
barcodeScannerView.CameraLocation = CameraLocation.Rear;
}
diff --git a/Jugenddienst Stunden/Views/StundenPage.xaml b/Jugenddienst Stunden/Views/StundenPage.xaml
index c17001d..6b46180 100644
--- a/Jugenddienst Stunden/Views/StundenPage.xaml
+++ b/Jugenddienst Stunden/Views/StundenPage.xaml
@@ -3,10 +3,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels"
x:Class="Jugenddienst_Stunden.Views.StundenPage"
- Title="StundenPage">
+ Title="{Binding Title}">
+
+
@@ -18,13 +20,13 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Jugenddienst Stunden/Views/StundenPage.xaml.cs b/Jugenddienst Stunden/Views/StundenPage.xaml.cs
index 4103bf0..559b1f0 100644
--- a/Jugenddienst Stunden/Views/StundenPage.xaml.cs
+++ b/Jugenddienst Stunden/Views/StundenPage.xaml.cs
@@ -1,9 +1,12 @@
namespace Jugenddienst_Stunden.Views;
-public partial class StundenPage : ContentPage
-{
- public StundenPage()
- {
+public partial class StundenPage : ContentPage {
+ public StundenPage() {
InitializeComponent();
}
+
+ protected override void OnAppearing() {
+ base.OnAppearing();
+ Title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
+ }
}
\ No newline at end of file