mobile/startup: show notification directly in the UI window

Until the app is initialized, we have problems getting the 'floating'
passive notifications to show up and be useful. Instead update the user
by filling a text block on the otherwise empty initial page of the app.

Delay the switch to the dive list until the app is initialized and then
use the passive notifications again. While we are initializing also show
a busy spinner so the user doesn't think the app is hung.

As a side effect of this change, the dive list isn't shown until our
models are initialized. And strangely this causes every single possible
delegate to be instantiated. We can prevent that by not setting the dive
list model until after we are done setting up the model.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-04-01 07:27:10 -07:00
parent d317eefb67
commit 8801ae857e
2 changed files with 57 additions and 19 deletions

View file

@ -13,7 +13,7 @@ Kirigami.ScrollablePage {
title: qsTr("Dive list")
verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
property int horizontalPadding: Kirigami.Units.gridUnit / 2 - Kirigami.Units.smallSpacing + 1
property QtObject diveListModel: diveModel
property QtObject diveListModel: null
supportsRefreshing: true
onRefreshingChanged: {

View file

@ -36,13 +36,28 @@ Kirigami.ApplicationWindow {
property int colWidth: undefined
onNotificationTextChanged: {
if (notificationText != "") {
// once the app is fully initialized and the UI is running, we use passive
// notifications to show the notification text, but during initialization
// we instead dump the information into the textBlock below - and to make
// this visually more useful we interpret a "\r" at the beginning of a notification
// to mean that we want to simply over-write the last line, not create a new one
if (initialized) {
// make sure any old notification is hidden
hidePassiveNotification()
if (notificationText !== "") {
// there's a risk that we have a >5 second gap in update events;
// still, keep the timeout at 5s to avoid odd unchanging notifications
showPassiveNotification(notificationText, 5000)
}
} else {
// hiding the notification right away may be a mistake as it hides the last warning / error
hidePassiveNotification();
var oldText = textBlock.text
if (notificationText.startsWith("\r")) {
// replace the last line that was sent
oldText = oldText.substr(0, oldText.lastIndexOf("\n"))
textBlock.text = oldText + "\n" + notificationText.substr(1)
} else {
textBlock.text = oldText + "\n" + notificationText
}
}
}
visible: false
@ -63,7 +78,7 @@ Kirigami.ApplicationWindow {
function hideBusy() {
busy.running = false
showPassiveNotification("", 10) // this hides a notification messssage that's still shown
hidePassiveNotification()
}
function returnTopPage() {
@ -707,22 +722,14 @@ if you have network connectivity and want to sync your data to cloud storage."),
id: manager
}
StartPage {
id: startPage
anchors.fill: parent
visible: Backend.cloud_verification_status !== Enums.CS_NOCLOUD &&
Backend.cloud_verification_status !== Enums.CS_VERIFIED
onVisibleChanged: {
if (visible) {
pageStack.clear()
} else {
showDiveList()
}
}
Component.onCompleted: {
if (!visible) {
manager.appendTextToLog("StartPage completed - showing the dive list")
property bool initialized: manager.initialized
onInitializedChanged: {
if (initialized) {
hideBusy()
manager.appendTextToLog("initialization completed - showing the dive list")
showPage(diveList) // we want to make sure that gets on the stack
diveList.diveListModel = diveModel
manager.appendTextToLog("if we got started by a plugged in device, switch to download page -- pluggedInDeviceName = " + pluggedInDeviceName)
if (pluggedInDeviceName !== "")
// if we were started with a dive computer plugged in,
@ -730,6 +737,37 @@ if you have network connectivity and want to sync your data to cloud storage."),
showDownloadForPluggedInDevice()
}
}
Label {
id: textBlock
visible: !initialized
text: qsTr("Subsurface-mobile starting up")
font.pointSize: subsurfaceTheme.headingPointSize
topPadding: 2 * Kirigami.Units.gridUnit
leftPadding: Kirigami.Units.gridUnit
}
StartPage {
id: startPage
anchors.fill: parent
visible: initialized &&
Backend.cloud_verification_status !== Enums.CS_NOCLOUD &&
Backend.cloud_verification_status !== Enums.CS_VERIFIED
onVisibleChanged: {
manager.appendTextToLog("StartPage visibility changed to " + visible)
if (!initialized) {
manager.appendTextToLog("not yet initialized, show busy spinner")
showBusy()
}
if (visible) {
pageStack.clear()
} else if (initialized) {
showDiveList()
}
}
Component.onCompleted: {
manager.appendTextToLog("StartPage completed -- initialized is " + initialized)
}
}
DiveList {