Add a loading indicator to QR codes

This commit is contained in:
Brahim Hadriche committed 2024-03-09 18:34:32 -05:00
1 parent 7bb73e0fb6
commit ee3312763d
9 files changed
+97 -27

No files matched your search

@@ -1,32 +0,0 @@
import "pkg:/source/QrCode/QrImage.bs"
import "pkg:/source/utils/StringUtils.bs"
' TODO:P1 create a QRCode component that has a loading spinner while the QRCode is being generated
' It is slow and can take several seconds.
@asynctask
function GenerateQrCodeTask(input as object)
poster = input.poster
mode = input.mode
text = input.text
size = input.size
padding = input.padding
if mode = invalid
mode = QrCode.QRMode.Byte
end if
if size = invalid
size = 200
end if
if padding = invalid
padding = 0
end if
qr = new QrCode.QRImage()
imagePath = qr.Generate(text, size, padding, mode)
if not StringUtils.IsNullOrEmpty(imagePath)
poster.uri = imagePath
end if
end function
@@ -1,8 +1,6 @@
import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
@@ -18,6 +16,8 @@ function Init()
m.linkWithWifiPanel = m.top.findNode("LinkWithWiFiPanel")
m.linkWithTvPanel = m.top.findNode("LinkWithTvPanel")
m.webAppUrlLabel = m.top.findNode("WebAppUrlLabel")
m.webAppQrCodePoster = m.top.findNode("WebAppQrCodePoster")
m.wifiNameLabel = m.top.findNode("WifiNameLabel")
m.wifiInstructionWithDeviceNameLabel = m.top.findNode("WifiInstructionWithDeviceNameLabel")
m.linkCodeLabel = m.top.findNode("LinkCodeLabel")
@@ -65,16 +65,8 @@ end function
function OnUrlSet()
url = m.top.url
urlLabel = m.top.findNode("urlLabel")
urlLabel.text = url
qrCodePoster = m.top.findNode("QrCodePoster")
AsyncTask.Start(Tasks.GenerateQrCodeTask, {
poster: qrCodePoster
text: url
size: qrCodePoster.loadWidth
padding: 20
})
m.webAppUrlLabel.text = url
m.webAppQrCodePoster.text = url
end function
function OnkeyEvent(key as string, press as boolean) as boolean
@@ -47,15 +47,16 @@
font="font:SmallBoldSystemFont"
horizAlign="center"
text="Scan the QR code" />
<Poster
id="QrCodePoster"
<QrCodePoster
id="WebAppQrCodePoster"
height="400"
width="400"
loadHeight="400"
loadWidth="400"
padding="20"
translation="[0,40]" />
<Label
id="UrlLabel"
id="WebAppUrlLabel"
height="30"
width="400"
font="font:SmallBoldSystemFont"
@@ -9,6 +9,7 @@
<children>
<BusySpinner
id="busySpinner"
spinInterval="2"
translation="[5,0]" />
<Label
id="nameLabel"
@@ -5,6 +5,7 @@
<children>
<BusySpinner
id="busySpinner"
spinInterval="1"
translation="[380,96]" />
<Label
id="failedLabel"