From 872e7b3a4f72a8cb318177a17014eaa10078670e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Szab=C3=B3?= Date: Fri, 14 Feb 2025 16:15:33 +0100 Subject: [PATCH] =?UTF-8?q?NFC=20teszt=20=C3=A9s=20egyebek=20jav=C3=ADt?= =?UTF-8?q?=C3=A1sa,=20fejleszt=C3=A9se?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => Locations}/LocationsPage.xaml | 0 .../{ => Locations}/LocationsPage.xaml.cs | 0 src/WorkFlowCheck.MAUI/Pages/NFC/NFCData.cs | 17 +++++ .../Pages/NFC/NFCTestPage.xaml | 20 ++++-- .../Pages/NFC/NFCTestPage.xaml.cs | 71 ++++++++++++++++--- .../WorkFlowCheck.MAUI.csproj | 2 +- 6 files changed, 92 insertions(+), 18 deletions(-) rename src/WorkFlowCheck.MAUI/Pages/BaseStock/{ => Locations}/LocationsPage.xaml (100%) rename src/WorkFlowCheck.MAUI/Pages/BaseStock/{ => Locations}/LocationsPage.xaml.cs (100%) create mode 100644 src/WorkFlowCheck.MAUI/Pages/NFC/NFCData.cs diff --git a/src/WorkFlowCheck.MAUI/Pages/BaseStock/LocationsPage.xaml b/src/WorkFlowCheck.MAUI/Pages/BaseStock/Locations/LocationsPage.xaml similarity index 100% rename from src/WorkFlowCheck.MAUI/Pages/BaseStock/LocationsPage.xaml rename to src/WorkFlowCheck.MAUI/Pages/BaseStock/Locations/LocationsPage.xaml diff --git a/src/WorkFlowCheck.MAUI/Pages/BaseStock/LocationsPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/BaseStock/Locations/LocationsPage.xaml.cs similarity index 100% rename from src/WorkFlowCheck.MAUI/Pages/BaseStock/LocationsPage.xaml.cs rename to src/WorkFlowCheck.MAUI/Pages/BaseStock/Locations/LocationsPage.xaml.cs diff --git a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCData.cs b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCData.cs new file mode 100644 index 0000000..db88db9 --- /dev/null +++ b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCData.cs @@ -0,0 +1,17 @@ +using Plugin.NFC; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.MAUI.Pages.NFC +{ + public class NFCData + + { + public string DateReceived { get; set; } + public string SerialNumber { get; set; } = null!; + + } +} diff --git a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml index e17660a..50058b8 100644 --- a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml +++ b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml @@ -3,10 +3,18 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="WorkFlowCheck.MAUI.Pages.NFC.NFCTestPage" Title="NFCTestPage"> - - + + + + + + + + + + + + \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs index 3b53ff7..e45142e 100644 --- a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs @@ -1,25 +1,35 @@ using Plugin.NFC; +using System.Collections.ObjectModel; using System.Text; +using System.Windows.Input; +using System.Linq; namespace WorkFlowCheck.MAUI.Pages.NFC; public partial class NFCTestPage : ContentPage { - public NFCTestPage() - { - InitializeComponent(); - } + public NFCTestPage() + { + InitializeComponent(); + } + + public ObservableCollection NFCDataList { get; set; } + public ICommand RefreshCommand { get; set; } + public const string ALERT_TITLE = "NFC"; bool _eventsAlreadySubscribed = false; + public bool IsRefreshing { get; set; } + protected override async void OnAppearing() { base.OnAppearing(); + CrossNFC.Legacy = false; if (CrossNFC.IsSupported) { if (!CrossNFC.Current.IsAvailable) await ShowAlert("NFC is not available"); - + if (!CrossNFC.Current.IsEnabled) await ShowAlert("NFC is disabled"); @@ -29,6 +39,8 @@ public partial class NFCTestPage : ContentPage { await ShowAlert("NFC is not available"); } + RefreshCommand = new Command(async () => await LoadNFCDataList()); + BindingContext = this; } Task ShowAlert(string message, string title = null) => DisplayAlert(string.IsNullOrWhiteSpace(title) ? ALERT_TITLE : title, message, "OK"); async Task AutoStartAsync() @@ -39,7 +51,7 @@ public partial class NFCTestPage : ContentPage } async Task StartListeningIfNotiOS() { - + await BeginListening(); } async Task BeginListening() @@ -64,23 +76,23 @@ public partial class NFCTestPage : ContentPage _eventsAlreadySubscribed = true; - CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived; + CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived_NFCData; //CrossNFC.Current.OnMessagePublished += Current_OnMessagePublished; //CrossNFC.Current.OnTagDiscovered += Current_OnTagDiscovered; //CrossNFC.Current.OnNfcStatusChanged += Current_OnNfcStatusChanged; //CrossNFC.Current.OnTagListeningStatusChanged += Current_OnTagListeningStatusChanged; - + } void UnsubscribeEvents() { - CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived; + CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived_NFCData; //CrossNFC.Current.OnMessagePublished -= Current_OnMessagePublished; //CrossNFC.Current.OnTagDiscovered -= Current_OnTagDiscovered; //CrossNFC.Current.OnNfcStatusChanged -= Current_OnNfcStatusChanged; //CrossNFC.Current.OnTagListeningStatusChanged -= Current_OnTagListeningStatusChanged; - + _eventsAlreadySubscribed = false; } @@ -111,6 +123,42 @@ public partial class NFCTestPage : ContentPage await ShowAlert(GetMessage(first), title); } } + async void Current_OnMessageReceived_NFCData(ITagInfo tagInfo) + { + + if (tagInfo == null) + { + await ShowAlert("No tag found"); + return; + } + + // Customized serial number + var identifier = tagInfo.Identifier; + var serialNumber = NFCUtils.ByteArrayToHexString(identifier, ":"); + + if (NFCDataList == null) + { + NFCDataList = new ObservableCollection(); + } + + + NFCDataList.Add(new NFCData() + { + SerialNumber = serialNumber, + DateReceived = $"{DateTime.Now.Date.ToShortDateString()} {DateTime.Now.ToLongTimeString()}" + }); + + NFCDataListCollection.ItemsSource = NFCDataList.OrderByDescending(o => o.DateReceived); + await LoadNFCDataList(); + } + + private async Task LoadNFCDataList() + { + IsRefreshing = true; + IsRefreshing = false; + OnPropertyChanged(nameof(IsRefreshing)); + OnPropertyChanged(nameof(NFCDataList)); + } string GetMessage(NFCNdefRecord record) { var message = $"Message: {record.Message}"; @@ -127,7 +175,8 @@ public partial class NFCTestPage : ContentPage return message; } - protected override bool OnBackButtonPressed() { + protected override bool OnBackButtonPressed() + { Shell.Current.GoToAsync("//MainPage"); return true; } diff --git a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj index 205be8a..6b65968 100644 --- a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj +++ b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj @@ -96,7 +96,7 @@ MSBuild:Compile - + MSBuild:Compile