Add a loading indicator to QR codes
This commit is contained in:
1 parent
7bb73e0fb6
commit
ee3312763d
9 files changed
+97
-27
No files matched your search
@@ -1,6 +1,4 @@
|
|||||||
import "DialogPalette.bs"
|
import "DialogPalette.bs"
|
||||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
|
||||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
|
||||||
import "pkg:/source/utils/StringUtils.bs"
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
@@ -33,12 +31,7 @@ function OnUrlSet()
|
|||||||
url = m.top.url
|
url = m.top.url
|
||||||
|
|
||||||
m.urlLabel.text = url
|
m.urlLabel.text = url
|
||||||
AsyncTask.Start(Tasks.GenerateQrCodeTask, {
|
m.qrCode.text = url
|
||||||
poster: m.qrCode
|
|
||||||
text: url
|
|
||||||
size: m.qrCode.loadWidth
|
|
||||||
padding: 10
|
|
||||||
})
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnAuthTokenChange()
|
function OnAuthTokenChange()
|
||||||
|
|||||||
@@ -25,12 +25,13 @@
|
|||||||
wrap="true" width="400">
|
wrap="true" width="400">
|
||||||
<Font role="font" uri="font:SystemFontFile" size="24" />
|
<Font role="font" uri="font:SystemFontFile" size="24" />
|
||||||
</Label>
|
</Label>
|
||||||
<Poster
|
<QrCodePoster
|
||||||
id="QrCodePoster"
|
id="QrCodePoster"
|
||||||
width="300"
|
width="300"
|
||||||
height="300"
|
height="300"
|
||||||
loadWidth="300"
|
loadWidth="300"
|
||||||
loadHeight="300"
|
loadHeight="300"
|
||||||
|
padding="10"
|
||||||
translation="[50, 50]" />
|
translation="[50, 50]" />
|
||||||
<Label
|
<Label
|
||||||
id="urlLabel"
|
id="urlLabel"
|
||||||
|
|||||||
+7
-3
@@ -1,10 +1,8 @@
|
|||||||
import "pkg:/source/QrCode/QrImage.bs"
|
import "pkg:/source/QrCode/QrImage.bs"
|
||||||
import "pkg:/source/utils/StringUtils.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
|
@asynctask
|
||||||
function GenerateQrCodeTask(input as object)
|
function GenerateQrCodeTask(input as object) as object
|
||||||
poster = input.poster
|
poster = input.poster
|
||||||
mode = input.mode
|
mode = input.mode
|
||||||
text = input.text
|
text = input.text
|
||||||
@@ -26,7 +24,13 @@ function GenerateQrCodeTask(input as object)
|
|||||||
qr = new QrCode.QRImage()
|
qr = new QrCode.QRImage()
|
||||||
imagePath = qr.Generate(text, size, padding, mode)
|
imagePath = qr.Generate(text, size, padding, mode)
|
||||||
|
|
||||||
|
if m.top.cancel
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
if not StringUtils.IsNullOrEmpty(imagePath)
|
if not StringUtils.IsNullOrEmpty(imagePath)
|
||||||
poster.uri = imagePath
|
poster.uri = imagePath
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
return invalid
|
||||||
end function
|
end function
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||||
|
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||||
|
import "pkg:/source/utils/StringUtils.bs"
|
||||||
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.busySpinner = m.top.findNode("busySpinner")
|
||||||
|
m.busySpinnerPoster = m.busySpinner.poster
|
||||||
|
|
||||||
|
m.busySpinnerPoster.uri = "pkg:/images/spinner.png"
|
||||||
|
|
||||||
|
m.top.observeField("width", FuncName(OnSizeChange))
|
||||||
|
m.top.observeField("height", FuncName(OnSizeChange))
|
||||||
|
OnSizeChange()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnSizeChange()
|
||||||
|
width = m.top.width
|
||||||
|
height = m.top.height
|
||||||
|
|
||||||
|
m.busySpinnerPoster.width = width / 2
|
||||||
|
m.busySpinnerPoster.height = height / 2
|
||||||
|
m.busySpinner.translation = [width / 4, height / 4]
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnTextChange() as void
|
||||||
|
if m.qrCodeGenTask <> invalid
|
||||||
|
m.qrCodeGenTask.cancel = true
|
||||||
|
end if
|
||||||
|
|
||||||
|
text = m.top.text
|
||||||
|
|
||||||
|
width = m.top.loadWidth
|
||||||
|
if width = 0
|
||||||
|
width = m.top.width
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.uri = ""
|
||||||
|
|
||||||
|
if StringUtils.IsNullOrEmpty(text)
|
||||||
|
m.busySpinner.control = "stop"
|
||||||
|
m.busySpinner.visible = false
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.busySpinnerPoster.rotation = 0
|
||||||
|
m.busySpinner.visible = true
|
||||||
|
m.busySpinner.control = "start"
|
||||||
|
|
||||||
|
m.qrCodeGenTask = AsyncTask.Start(Tasks.GenerateQrCodeTask, {
|
||||||
|
poster: m.top
|
||||||
|
text: text
|
||||||
|
size: width
|
||||||
|
padding: m.top.padding
|
||||||
|
}, OnGenerateQrCodeTaskResult)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnGenerateQrCodeTaskResult(output as object) as void
|
||||||
|
if output.cancelled
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.busySpinner.control = "stop"
|
||||||
|
m.busySpinner.visible = false
|
||||||
|
end function
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<component name="QrCodePoster" extends="Poster">
|
||||||
|
<interface>
|
||||||
|
<field id="text" type="string" onChange="OnTextChange" />
|
||||||
|
<field id="padding" type="integer" />
|
||||||
|
</interface>
|
||||||
|
<children>
|
||||||
|
<BusySpinner
|
||||||
|
id="busySpinner"
|
||||||
|
spinInterval="1"
|
||||||
|
visible="false" />
|
||||||
|
</children>
|
||||||
|
</component>
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
import "pkg:/components/Navigation/Navigation.bs"
|
import "pkg:/components/Navigation/Navigation.bs"
|
||||||
import "pkg:/source/AsyncTask/AsyncTask.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/AsyncTask/Tasks.bs"
|
||||||
import "pkg:/source/utils/ErrorUtils.bs"
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
import "pkg:/source/utils/FocusManagement.bs"
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
@@ -18,6 +16,8 @@ function Init()
|
|||||||
m.linkWithWifiPanel = m.top.findNode("LinkWithWiFiPanel")
|
m.linkWithWifiPanel = m.top.findNode("LinkWithWiFiPanel")
|
||||||
m.linkWithTvPanel = m.top.findNode("LinkWithTvPanel")
|
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.wifiNameLabel = m.top.findNode("WifiNameLabel")
|
||||||
m.wifiInstructionWithDeviceNameLabel = m.top.findNode("WifiInstructionWithDeviceNameLabel")
|
m.wifiInstructionWithDeviceNameLabel = m.top.findNode("WifiInstructionWithDeviceNameLabel")
|
||||||
m.linkCodeLabel = m.top.findNode("LinkCodeLabel")
|
m.linkCodeLabel = m.top.findNode("LinkCodeLabel")
|
||||||
@@ -65,16 +65,8 @@ end function
|
|||||||
function OnUrlSet()
|
function OnUrlSet()
|
||||||
url = m.top.url
|
url = m.top.url
|
||||||
|
|
||||||
urlLabel = m.top.findNode("urlLabel")
|
m.webAppUrlLabel.text = url
|
||||||
urlLabel.text = url
|
m.webAppQrCodePoster.text = url
|
||||||
|
|
||||||
qrCodePoster = m.top.findNode("QrCodePoster")
|
|
||||||
AsyncTask.Start(Tasks.GenerateQrCodeTask, {
|
|
||||||
poster: qrCodePoster
|
|
||||||
text: url
|
|
||||||
size: qrCodePoster.loadWidth
|
|
||||||
padding: 20
|
|
||||||
})
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||||
|
|||||||
@@ -47,15 +47,16 @@
|
|||||||
font="font:SmallBoldSystemFont"
|
font="font:SmallBoldSystemFont"
|
||||||
horizAlign="center"
|
horizAlign="center"
|
||||||
text="Scan the QR code" />
|
text="Scan the QR code" />
|
||||||
<Poster
|
<QrCodePoster
|
||||||
id="QrCodePoster"
|
id="WebAppQrCodePoster"
|
||||||
height="400"
|
height="400"
|
||||||
width="400"
|
width="400"
|
||||||
loadHeight="400"
|
loadHeight="400"
|
||||||
loadWidth="400"
|
loadWidth="400"
|
||||||
|
padding="20"
|
||||||
translation="[0,40]" />
|
translation="[0,40]" />
|
||||||
<Label
|
<Label
|
||||||
id="UrlLabel"
|
id="WebAppUrlLabel"
|
||||||
height="30"
|
height="30"
|
||||||
width="400"
|
width="400"
|
||||||
font="font:SmallBoldSystemFont"
|
font="font:SmallBoldSystemFont"
|
||||||
|
|||||||
+1
@@ -9,6 +9,7 @@
|
|||||||
<children>
|
<children>
|
||||||
<BusySpinner
|
<BusySpinner
|
||||||
id="busySpinner"
|
id="busySpinner"
|
||||||
|
spinInterval="2"
|
||||||
translation="[5,0]" />
|
translation="[5,0]" />
|
||||||
<Label
|
<Label
|
||||||
id="nameLabel"
|
id="nameLabel"
|
||||||
|
|||||||
+1
@@ -5,6 +5,7 @@
|
|||||||
<children>
|
<children>
|
||||||
<BusySpinner
|
<BusySpinner
|
||||||
id="busySpinner"
|
id="busySpinner"
|
||||||
|
spinInterval="1"
|
||||||
translation="[380,96]" />
|
translation="[380,96]" />
|
||||||
<Label
|
<Label
|
||||||
id="failedLabel"
|
id="failedLabel"
|
||||||
|
|||||||
Reference in new issue
Block a user