Skip to content
Snippets Groups Projects
Commit c4ecf286 authored by Burak Hançerli's avatar Burak Hançerli :headphones:
Browse files

QDS-11911 Project list dropdown update issues

parent 20733343
No related branches found
No related tags found
1 merge request!37QDS-11911 Project list dropdown update issues
Pipeline #67177 passed
<?xml version="1.0"?> <?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.qt.qtdesignviewer" <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.qt.qtdesignviewer"
android:installLocation="auto" android:versionCode="24" android:versionName="1.2"> android:installLocation="auto" android:versionCode="25" android:versionName="1.2">
<!-- %%INSERT_PERMISSIONS --> <!-- %%INSERT_PERMISSIONS -->
<!-- %%INSERT_FEATURES --> <!-- %%INSERT_FEATURES -->
<supports-screens android:anyDensity="true" android:largeScreens="true" <supports-screens android:anyDensity="true" android:largeScreens="true"
......
...@@ -92,7 +92,9 @@ void Backend::initialize() ...@@ -92,7 +92,9 @@ void Backend::initialize()
updateUserProjectList(); updateUserProjectList();
} }
// Check if updateInBackground is enabled // Initialize background update
connect(&m_backgroundTimer, &QTimer::timeout, this, &Backend::updateUserProjectList);
m_backgroundTimer.setInterval(1000 * 10);
enableBackgroundUpdate(updateInBackground()); enableBackgroundUpdate(updateInBackground());
qDebug() << "Initialization complete"; qDebug() << "Initialization complete";
} }
...@@ -100,26 +102,6 @@ void Backend::initialize() ...@@ -100,26 +102,6 @@ void Backend::initialize()
void Backend::enableBackgroundUpdate(const bool &enabled) void Backend::enableBackgroundUpdate(const bool &enabled)
{ {
if (enabled) { if (enabled) {
m_backgroundTimer.setInterval(1000 * 10);
connect(&m_backgroundTimer, &QTimer::timeout, this, [&] {
qDebug() << "Checking for updates in background";
const QString userHash = Backend::userHash();
if (userHash.isEmpty())
return;
QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash);
if (projectList.isEmpty()) {
qWarning() << "Could not fetch project list. Please check your internet "
"connection and try again";
return;
}
qDebug() << "New projects available. Updating project list";
updateUserProjectList();
});
m_backgroundTimer.start(); m_backgroundTimer.start();
} else { } else {
m_backgroundTimer.stop(); m_backgroundTimer.stop();
...@@ -150,7 +132,7 @@ void Backend::setAutoScaleProject(const bool &enabled) ...@@ -150,7 +132,7 @@ void Backend::setAutoScaleProject(const bool &enabled)
void Backend::setUserHash(const QString &userHash) void Backend::setUserHash(const QString &userHash)
{ {
QSettings().setValue("user/hash", userHash); QSettings().setValue("user/hash", userHash);
emit userRegistered(); emit userHashChanged();
} }
bool Backend::updateInBackground() bool Backend::updateInBackground()
...@@ -504,23 +486,23 @@ void Backend::updateUserProjectList() ...@@ -504,23 +486,23 @@ void Backend::updateUserProjectList()
qDebug() << "Fetching available project list for user:" << userHash; qDebug() << "Fetching available project list for user:" << userHash;
QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash); QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash);
if (projectList.isEmpty()) {
qCritical("Could not fetch available project list");
return;
}
if (projectList == m_projectList) { if (projectList == m_projectList) {
qDebug("No new projects available"); qDebug("No new projects are available");
return; } else if (projectList.isEmpty()) {
} qWarning("Could not fetch project list. Either there are no projects or there is a "
"network issue");
m_projectList = projectList; } else {
qDebug("List of available projects fetched:"); qDebug("List of available projects fetched:");
for (const auto &project : projectList) { for (const auto &project : projectList) {
const QString projectName{project.toObject().value("appName").toString()}; const QString projectName{project.toObject().value("appName").toString()};
qDebug() << "--" << projectName; qDebug() << "--" << projectName;
} }
}
// we need to set m_projectList even if it is empty
// because this triggers the onModelChanged function in the QML
// in order to update the UI
m_projectList = projectList;
emit projectListChanged(); emit projectListChanged();
} }
......
...@@ -89,23 +89,29 @@ private: ...@@ -89,23 +89,29 @@ private:
QTimer m_backgroundTimer; QTimer m_backgroundTimer;
// member functions // member functions
void updateUserProjectList();
void updatePopup(const QString &text, bool indeterminate = true); void updatePopup(const QString &text, bool indeterminate = true);
signals: signals:
// UI signals // UI signals - Home page
void projectListChanged();
void urlUpdated(QString);
void userHashChanged();
// UI signals - Logs page
void logsChanged(QString); void logsChanged(QString);
// UI signals - About page
void buildInfoChanged(QString); void buildInfoChanged(QString);
// UI signals - Popup
void downloadProgress(float); void downloadProgress(float);
void projectListChanged();
void popupProgressIndeterminateChanged(bool indeterminate); void popupProgressIndeterminateChanged(bool indeterminate);
void popupTextChanged(QString text); void popupTextChanged(QString text);
void popupOpen(); void popupOpen();
void popupClose(); void popupClose();
void userRegistered();
// UI signals - Network page
void networkUpdated(QString); void networkUpdated(QString);
void urlUpdated(QString);
void userHashChanged(QString);
public slots: public slots:
void scanQrCode(); void scanQrCode();
...@@ -133,6 +139,7 @@ public slots: ...@@ -133,6 +139,7 @@ public slots:
private slots: private slots:
void initializeProjectManager(); void initializeProjectManager();
void enableBackgroundUpdate(const bool &enabled); void enableBackgroundUpdate(const bool &enabled);
void updateUserProjectList();
}; };
#endif // DV_ANDROID_H #endif // DV_ANDROID_H
...@@ -27,7 +27,7 @@ Item { ...@@ -27,7 +27,7 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
Connections { Connections {
target: backend target: backend
function onUserRegistered(){ function onUserHashChanged(){
qrCodeStatus.text = "User registration is completed.\nScan a new QR code to access the shared project from a different user."; qrCodeStatus.text = "User registration is completed.\nScan a new QR code to access the shared project from a different user.";
qrCodeInstructions.text = ""; qrCodeInstructions.text = "";
} }
...@@ -67,11 +67,19 @@ Item { ...@@ -67,11 +67,19 @@ Item {
id: projectList id: projectList
Layout.fillWidth: true Layout.fillWidth: true
enabled: true enabled: true
onCurrentIndexChanged: {
displayText = textAt(currentIndex)
}
textRole: "appName" textRole: "appName"
model: backend.projectList model: backend.projectList
onModelChanged: {
if (backend.projectList.length > 0) {
projectList.displayText = backend.projectList[0].appName;
projectList.enabled = true;
downloadUserProject.enabled = true;
} else {
projectList.displayText = "No projects are available";
projectList.enabled = false;
downloadUserProject.enabled = false;
}
}
displayText: "Scan QR code to access your projects"; displayText: "Scan QR code to access your projects";
currentIndex: -1 currentIndex: -1
Layout.preferredHeight: 50 Layout.preferredHeight: 50
...@@ -85,19 +93,6 @@ Item { ...@@ -85,19 +93,6 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
} }
Connections {
target: backend
function onUserRegistered(){
projectList.displayText = "No projects available for the user";
projectList.enabled = false;
downloadUserProject.enabled = false;
}
function onProjectListChanged(){
projectList.enabled = true;
downloadUserProject.enabled = true;
}
}
} }
Item { Item {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment