1
0
Fork 0
mirror of https://github.com/subsurface/subsurface.git synced 2025-02-19 22:16:15 +00:00

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
mobile-widgets/qml

View file

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

View file

@ -36,13 +36,28 @@ Kirigami.ApplicationWindow {
property int colWidth: undefined property int colWidth: undefined
onNotificationTextChanged: { onNotificationTextChanged: {
if (notificationText != "") { // once the app is fully initialized and the UI is running, we use passive
// there's a risk that we have a >5 second gap in update events; // notifications to show the notification text, but during initialization
// still, keep the timeout at 5s to avoid odd unchanging notifications // we instead dump the information into the textBlock below - and to make
showPassiveNotification(notificationText, 5000) // 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 { } else {
// hiding the notification right away may be a mistake as it hides the last warning / error var oldText = textBlock.text
hidePassiveNotification(); 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 visible: false
@ -63,7 +78,7 @@ Kirigami.ApplicationWindow {
function hideBusy() { function hideBusy() {
busy.running = false busy.running = false
showPassiveNotification("", 10) // this hides a notification messssage that's still shown hidePassiveNotification()
} }
function returnTopPage() { function returnTopPage() {
@ -707,28 +722,51 @@ if you have network connectivity and want to sync your data to cloud storage."),
id: manager id: manager
} }
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,
// immediately switch to download page
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 { StartPage {
id: startPage id: startPage
anchors.fill: parent anchors.fill: parent
visible: Backend.cloud_verification_status !== Enums.CS_NOCLOUD && visible: initialized &&
Backend.cloud_verification_status !== Enums.CS_NOCLOUD &&
Backend.cloud_verification_status !== Enums.CS_VERIFIED Backend.cloud_verification_status !== Enums.CS_VERIFIED
onVisibleChanged: { onVisibleChanged: {
manager.appendTextToLog("StartPage visibility changed to " + visible)
if (!initialized) {
manager.appendTextToLog("not yet initialized, show busy spinner")
showBusy()
}
if (visible) { if (visible) {
pageStack.clear() pageStack.clear()
} else { } else if (initialized) {
showDiveList() showDiveList()
} }
} }
Component.onCompleted: { Component.onCompleted: {
if (!visible) { manager.appendTextToLog("StartPage completed -- initialized is " + initialized)
manager.appendTextToLog("StartPage completed - showing the dive list")
showPage(diveList) // we want to make sure that gets on the stack
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,
// immediately switch to download page
showDownloadForPluggedInDevice()
}
} }
} }