Every app needs a nice cover page :)

This commit is contained in:
Sebastian J. Wolf 2020-08-16 23:31:20 +02:00
parent ee31736f83
commit 666acdf1db
7 changed files with 281 additions and 2 deletions

View file

@ -18,11 +18,81 @@
*/
import QtQuick 2.5
import Sailfish.Silica 1.0
import WerkWolf.Fernschreiber 1.0
CoverBackground {
id: coverPage
property int unreadMessages: 0
property int unreadChats: 0
property bool authenticated: false
property int connectionState: TelegramAPI.WaitingForNetwork
function setUnreadInfoText() {
if (unreadMessages === 1) {
unreadMessagesText.text = qsTr("unread message");
} else {
unreadMessagesText.text = qsTr("unread messages");
}
if (unreadChats === 1) {
unreadChatsText.text = qsTr("chat");
} else {
unreadChatsText.text = qsTr("chats");
}
switch (coverPage.connectionState) {
case TelegramAPI.WaitingForNetwork:
connectionStateText.text = qsTr("Waiting for network...");
break;
case TelegramAPI.Connecting:
connectionStateText.text = qsTr("Connecting to network...");
break;
case TelegramAPI.ConnectingToProxy:
connectionStateText.text = qsTr("Connecting to proxy...");
break;
case TelegramAPI.ConnectionReady:
connectionStateText.text = qsTr("Connected");
break;
case TelegramAPI.Updating:
connectionStateText.text = qsTr("Updating content...");
break;
}
}
Component.onCompleted: {
coverPage.authenticated = (tdLibWrapper.getAuthorizationState() === TelegramAPI.AuthorizationReady);
coverPage.connectionState = tdLibWrapper.getConnectionState();
coverPage.unreadMessages = tdLibWrapper.getUnreadMessageInformation().unread_count;
coverPage.unreadChats = tdLibWrapper.getUnreadChatInformation().unread_count;
setUnreadInfoText();
}
Connections {
target: tdLibWrapper
onUnreadMessageCountUpdated: {
if (messageCountInformation.chat_list_type === "chatListMain") {
coverPage.unreadMessages = messageCountInformation.unread_count;
setUnreadInfoText();
}
}
onUnreadChatCountUpdated: {
if (chatCountInformation.chat_list_type === "chatListMain") {
coverPage.unreadChats = chatCountInformation.unread_count;
setUnreadInfoText();
}
}
onAuthorizationStateChanged: {
coverPage.authenticated = (authorizationState === TelegramAPI.AuthorizationReady);
setUnreadInfoText();
}
onConnectionStateChanged: {
coverPage.connectionState = connectionState;
setUnreadInfoText();
}
}
Image {
id: backgroundImage
source: "../../images/background" + ( Theme.colorScheme ? "-black" : "-white" ) + ".png"
@ -40,4 +110,66 @@ CoverBackground {
opacity: 0.15
}
Column {
anchors.fill: parent
anchors.margins: Theme.horizontalPageMargin
spacing: Theme.paddingMedium
visible: coverPage.authenticated
Row {
width: parent.width
spacing: Theme.paddingMedium
Text {
id: unreadMessagesCountText
font.pixelSize: Theme.fontSizeHuge
color: Theme.primaryColor
text: coverPage.unreadMessages
}
Text {
id: unreadMessagesText
font.pixelSize: Theme.fontSizeSmall
color: Theme.primaryColor
width: parent.width - unreadMessagesCountText.width - Theme.paddingMedium
wrapMode: Text.Wrap
anchors.verticalCenter: unreadMessagesCountText.verticalCenter
}
}
Row {
width: parent.width
spacing: Theme.paddingMedium
visible: coverPage.authenticated && coverPage.unreadChats > 0
Text {
id: inText
font.pixelSize: Theme.fontSizeSmall
color: Theme.primaryColor
text: qsTr("in")
anchors.verticalCenter: unreadChatsCountText.verticalCenter
}
Text {
id: unreadChatsCountText
font.pixelSize: Theme.fontSizeHuge
color: Theme.primaryColor
text: coverPage.unreadChats
}
Text {
id: unreadChatsText
font.pixelSize: Theme.fontSizeSmall
color: Theme.primaryColor
width: parent.width - unreadMessagesCountText.width - inText.width - ( 2 * Theme.paddingMedium )
wrapMode: Text.Wrap
anchors.verticalCenter: unreadChatsCountText.verticalCenter
}
}
Text {
id: connectionStateText
font.pixelSize: Theme.fontSizeLarge
color: Theme.highlightColor
visible: coverPage.authenticated
width: parent.width
maximumLineCount: 2
wrapMode: Text.Wrap
}
}
}

View file

@ -60,6 +60,8 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateUser") { this->processUpdateUser(receivedInformation); }
if (objectTypeName == "updateFile") { this->processUpdateFile(receivedInformation); }
if (objectTypeName == "updateNewChat") { this->processUpdateNewChat(receivedInformation); }
if (objectTypeName == "updateUnreadMessageCount") { this->processUpdateUnreadMessageCount(receivedInformation); }
if (objectTypeName == "updateUnreadChatCount") { this->processUpdateUnreadChatCount(receivedInformation); }
}
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -110,3 +112,26 @@ void TDLibReceiver::processUpdateNewChat(const QVariantMap &receivedInformation)
qDebug() << "[TDLibReceiver] New chat discovered: " << chatInformation.value("id").toString() << chatInformation.value("title").toString();
emit newChatDiscovered(chatInformation);
}
void TDLibReceiver::processUpdateUnreadMessageCount(const QVariantMap &receivedInformation)
{
QVariantMap messageCountInformation;
messageCountInformation.insert("chat_list_type", receivedInformation.value("chat_list").toMap().value("@type"));
messageCountInformation.insert("unread_count", receivedInformation.value("unread_count"));
messageCountInformation.insert("unread_unmuted_count", receivedInformation.value("unread_unmuted_count"));
qDebug() << "[TDLibReceiver] Unread message count updated: " << messageCountInformation.value("chat_list_type").toString() << messageCountInformation.value("unread_count").toString();
emit unreadMessageCountUpdated(messageCountInformation);
}
void TDLibReceiver::processUpdateUnreadChatCount(const QVariantMap &receivedInformation)
{
QVariantMap chatCountInformation;
chatCountInformation.insert("chat_list_type", receivedInformation.value("chat_list").toMap().value("@type"));
chatCountInformation.insert("marked_as_unread_count", receivedInformation.value("marked_as_unread_count"));
chatCountInformation.insert("marked_as_unread_unmuted_count", receivedInformation.value("marked_as_unread_unmuted_count"));
chatCountInformation.insert("total_count", receivedInformation.value("total_count"));
chatCountInformation.insert("unread_count", receivedInformation.value("unread_count"));
chatCountInformation.insert("unread_unmuted_count", receivedInformation.value("unread_unmuted_count"));
qDebug() << "[TDLibReceiver] Unread chat count updated: " << chatCountInformation.value("chat_list_type").toString() << chatCountInformation.value("unread_count").toString();
emit unreadChatCountUpdated(chatCountInformation);
}

View file

@ -43,6 +43,8 @@ signals:
void userUpdated(const QVariantMap &userInformation);
void fileUpdated(const QVariantMap &fileInformation);
void newChatDiscovered(const QVariantMap &chatInformation);
void unreadMessageCountUpdated(const QVariantMap &messageCountInformation);
void unreadChatCountUpdated(const QVariantMap &chatCountInformation);
private:
void *tdLibClient;
@ -56,6 +58,8 @@ private:
void processUpdateUser(const QVariantMap &receivedInformation);
void processUpdateFile(const QVariantMap &receivedInformation);
void processUpdateNewChat(const QVariantMap &receivedInformation);
void processUpdateUnreadMessageCount(const QVariantMap &receivedInformation);
void processUpdateUnreadChatCount(const QVariantMap &receivedInformation);
};
#endif // TDLIBRECEIVER_H

View file

@ -43,6 +43,8 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(fileUpdated(QVariantMap)), this, SLOT(handleFileUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(newChatDiscovered(QVariantMap)), this, SLOT(handleNewChatDiscovered(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(unreadMessageCountUpdated(QVariantMap)), this, SLOT(handleUnreadMessageCountUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(unreadChatCountUpdated(QVariantMap)), this, SLOT(handleUnreadChatCountUpdated(QVariantMap)));
this->tdLibReceiver->start();
@ -136,6 +138,16 @@ QVariantMap TDLibWrapper::getUserInformation(const QString &userId)
return this->otherUsers.value(userId).toMap();
}
QVariantMap TDLibWrapper::getUnreadMessageInformation()
{
return this->unreadMessageInformation;
}
QVariantMap TDLibWrapper::getUnreadChatInformation()
{
return this->unreadChatInformation;
}
void TDLibWrapper::handleVersionDetected(const QString &version)
{
this->version = version;
@ -245,6 +257,18 @@ void TDLibWrapper::handleNewChatDiscovered(const QVariantMap &chatInformation)
emit newChatDiscovered(chatId, chatInformation);
}
void TDLibWrapper::handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation)
{
this->unreadMessageInformation = messageCountInformation;
emit unreadMessageCountUpdated(messageCountInformation);
}
void TDLibWrapper::handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation)
{
this->unreadChatInformation = chatCountInformation;
emit unreadChatCountUpdated(chatCountInformation);
}
void TDLibWrapper::setInitialParameters()
{
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";

View file

@ -63,6 +63,8 @@ public:
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
Q_INVOKABLE QVariantMap getUserInformation();
Q_INVOKABLE QVariantMap getUserInformation(const QString &userId);
Q_INVOKABLE QVariantMap getUnreadMessageInformation();
Q_INVOKABLE QVariantMap getUnreadChatInformation();
// Direct TDLib functions
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
@ -76,8 +78,10 @@ signals:
void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState);
void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState);
void fileUpdated(const int fileId, const QVariantMap fileInformation);
void newChatDiscovered(const QString chatId, const QVariantMap chatInformation);
void fileUpdated(const int fileId, const QVariantMap &fileInformation);
void newChatDiscovered(const QString chatId, const QVariantMap &chatInformation);
void unreadMessageCountUpdated(const QVariantMap &messageCountInformation);
void unreadChatCountUpdated(const QVariantMap &chatCountInformation);
public slots:
void handleVersionDetected(const QString &version);
@ -87,6 +91,8 @@ public slots:
void handleUserUpdated(const QVariantMap &userInformation);
void handleFileUpdated(const QVariantMap &fileInformation);
void handleNewChatDiscovered(const QVariantMap &chatInformation);
void handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation);
void handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation);
private:
void *tdLibClient;
@ -98,6 +104,8 @@ private:
QVariantMap userInformation;
QVariantMap otherUsers;
QVariantMap chats;
QVariantMap unreadMessageInformation;
QVariantMap unreadChatInformation;
void setInitialParameters();
void setEncryptionKey();

View file

@ -76,6 +76,49 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
<source>unread message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>unread messages</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>in</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for network...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Updating content...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chats</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>InitializationPage</name>
<message>

View file

@ -76,6 +76,49 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
<source>unread message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>unread messages</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>in</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for network...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Updating content...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>chats</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>InitializationPage</name>
<message>