NFC teszt és egyebek javítása, fejlesztése

This commit is contained in:
2025-02-14 16:15:33 +01:00
parent f400bbf3c8
commit 872e7b3a4f
6 changed files with 92 additions and 18 deletions
@@ -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!;
}
}
@@ -3,10 +3,18 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.NFC.NFCTestPage" x:Class="WorkFlowCheck.MAUI.Pages.NFC.NFCTestPage"
Title="NFCTestPage"> Title="NFCTestPage">
<VerticalStackLayout> <RefreshView x:Name="refreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
<Label <CollectionView x:Name="NFCDataListCollection" ItemsSource="{Binding NFCDataList}">
Text="NFC Teszt" <CollectionView.ItemTemplate>
VerticalOptions="Center" <DataTemplate>
HorizontalOptions="Center" /> <Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True">
</VerticalStackLayout> <StackLayout>
<Label Text="{Binding SerialNumber}" FontSize="16" FontAttributes="Bold" />
<Label Text="{Binding DateReceived}" FontSize="14" />
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</ContentPage> </ContentPage>
@@ -1,19 +1,29 @@
using Plugin.NFC; using Plugin.NFC;
using System.Collections.ObjectModel;
using System.Text; using System.Text;
using System.Windows.Input;
using System.Linq;
namespace WorkFlowCheck.MAUI.Pages.NFC; namespace WorkFlowCheck.MAUI.Pages.NFC;
public partial class NFCTestPage : ContentPage public partial class NFCTestPage : ContentPage
{ {
public NFCTestPage() public NFCTestPage()
{ {
InitializeComponent(); InitializeComponent();
} }
public ObservableCollection<NFCData> NFCDataList { get; set; }
public ICommand RefreshCommand { get; set; }
public const string ALERT_TITLE = "NFC"; public const string ALERT_TITLE = "NFC";
bool _eventsAlreadySubscribed = false; bool _eventsAlreadySubscribed = false;
public bool IsRefreshing { get; set; }
protected override async void OnAppearing() protected override async void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
CrossNFC.Legacy = false; CrossNFC.Legacy = false;
if (CrossNFC.IsSupported) if (CrossNFC.IsSupported)
{ {
@@ -29,6 +39,8 @@ public partial class NFCTestPage : ContentPage
{ {
await ShowAlert("NFC is not available"); 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"); Task ShowAlert(string message, string title = null) => DisplayAlert(string.IsNullOrWhiteSpace(title) ? ALERT_TITLE : title, message, "OK");
async Task AutoStartAsync() async Task AutoStartAsync()
@@ -64,7 +76,7 @@ public partial class NFCTestPage : ContentPage
_eventsAlreadySubscribed = true; _eventsAlreadySubscribed = true;
CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived; CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived_NFCData;
//CrossNFC.Current.OnMessagePublished += Current_OnMessagePublished; //CrossNFC.Current.OnMessagePublished += Current_OnMessagePublished;
//CrossNFC.Current.OnTagDiscovered += Current_OnTagDiscovered; //CrossNFC.Current.OnTagDiscovered += Current_OnTagDiscovered;
//CrossNFC.Current.OnNfcStatusChanged += Current_OnNfcStatusChanged; //CrossNFC.Current.OnNfcStatusChanged += Current_OnNfcStatusChanged;
@@ -74,7 +86,7 @@ public partial class NFCTestPage : ContentPage
} }
void UnsubscribeEvents() void UnsubscribeEvents()
{ {
CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived; CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived_NFCData;
//CrossNFC.Current.OnMessagePublished -= Current_OnMessagePublished; //CrossNFC.Current.OnMessagePublished -= Current_OnMessagePublished;
//CrossNFC.Current.OnTagDiscovered -= Current_OnTagDiscovered; //CrossNFC.Current.OnTagDiscovered -= Current_OnTagDiscovered;
//CrossNFC.Current.OnNfcStatusChanged -= Current_OnNfcStatusChanged; //CrossNFC.Current.OnNfcStatusChanged -= Current_OnNfcStatusChanged;
@@ -111,6 +123,42 @@ public partial class NFCTestPage : ContentPage
await ShowAlert(GetMessage(first), title); 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<NFCData>();
}
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) string GetMessage(NFCNdefRecord record)
{ {
var message = $"Message: {record.Message}"; var message = $"Message: {record.Message}";
@@ -127,7 +175,8 @@ public partial class NFCTestPage : ContentPage
return message; return message;
} }
protected override bool OnBackButtonPressed() { protected override bool OnBackButtonPressed()
{
Shell.Current.GoToAsync("//MainPage"); Shell.Current.GoToAsync("//MainPage");
return true; return true;
} }
@@ -96,7 +96,7 @@
<MauiXaml Update="Pages\BaseStock\Equipments\EquipmentsPage.xaml"> <MauiXaml Update="Pages\BaseStock\Equipments\EquipmentsPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Pages\BaseStock\LocationsPage.xaml"> <MauiXaml Update="Pages\BaseStock\Locations\LocationsPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Pages\NFC\NFCTestPage.xaml"> <MauiXaml Update="Pages\NFC\NFCTestPage.xaml">