4using System.Runtime.CompilerServices;
6using System.Threading.Tasks;
7using CommunityToolkit.Mvvm.ComponentModel;
8using CommunityToolkit.Mvvm.Input;
17 #region Private Properties
19 private byte[] qrCodeBin = [];
20 private readonly IDispatcherTimer? timer;
21 private int timerSeconds = 60;
30 private string? legalId;
36 private ImageSource? qrCode;
42 private string? qrCodeUri;
48 private int qrCodeWidth;
54 private int qrCodeHeight;
62 private int qrResolutionScale;
68 private string? qrCodeContentType;
71 #region Public Properties
73 public byte[] QrCodeBin
75 get => this.qrCodeBin;
78 if (value == this.qrCodeBin)
return;
79 this.qrCodeBin = value;
80 this.OnPropertyChanged();
101 public ShowQRViewModel(
byte[] QrCodeBin,
string? QrCodeUri) : this(QrCodeBin, QrCodeUri,
"QR Code")
105 public ShowQRViewModel(
byte[] QrCodeBin,
string? QrCodeUri,
string Title)
109 this.QrCodeBin = QrCodeBin;
110 this.QrCodeUri = QrCodeUri;
113 if (this.QrCodeWidth == 0 || this.QrCodeHeight == 0)
119 if (this.QrResolutionScale == 0)
122 this.QrCode = ImageSource.FromStream(() =>
new MemoryStream(QrCodeBin));
126 this.timer = Application.Current?.Dispatcher.CreateTimer();
127 if (this.timer is
null)
129 this.timer.Interval = TimeSpan.FromSeconds(1);
130 this.timer.Tick += this.OnTimerTick;
138 private async Task Close()
145 private async Task ShareQR()
147 if (this.QrCodeBin is
null)
153 string FileName = $
"{Guid.NewGuid()}.png";
156 string FilePath = Path.Combine(FileSystem.CacheDirectory, FileName);
159 await File.WriteAllBytesAsync(FilePath, this.QrCodeBin);
162 await Share.Default.RequestAsync(
new ShareFileRequest
164 Title = this.Title ??
"QR Code",
165 File =
new ShareFile(FilePath,
"image/png")
180 private async Task Copy()
186 await Clipboard.SetTextAsync(this.QrCodeUri);
202 private void OnTimerTick(
object? sender, EventArgs e)
204 MainThread.BeginInvokeOnMainThread(async () =>
206 if (this.timerSeconds > 0)
215 await this.CloseCommand.ExecuteAsync(
null);
225 protected override Task OnPopAsync()
228 return base.OnPopAsync();
const int DefaultImageHeight
The default height to use when generating QR Code images.
const int DefaultImageWidth
The default width to use when generating QR Code images.
const int DefaultResolutionScale
The default scale factor to apply to the QR Code image resolution.
static readonly TimeSpan IdentityAllowedWatch
Allowed time to watch an Identity
A set of never changing property constants and helpful values.
A strongly-typed resource class, for looking up localized strings, etc.
static string SuccessfullyCopiedToClipboard
Looks up a localized string similar to Successfully copied to clipboard.
static string SuccessTitle
Looks up a localized string similar to Success.
Base class that references services in the app.
static ILogService LogService
Log service.
static IUiService UiService
Service serializing and managing UI-related tasks.
static IPopupService PopupService
Popup service for presenting application popups.
static ITagProfile TagProfile
TAG Profile service.
static IReportingStringLocalizer Localizer
Localization service
virtual void SetIsBusy(bool IsBusy)
Sets the IsBusy property.