diff --git a/qml/js/functions.js b/qml/js/functions.js index 9610f65..89bf729 100644 --- a/qml/js/functions.js +++ b/qml/js/functions.js @@ -93,6 +93,15 @@ function getMessageText(message, simple) { } return qsTr("Unsupported message: %1").arg(message.content['@type'].substring(7)); } +function getShortenedCount(count) { + if (count >= 1000000) { + return qsTr("%1M").arg((count / 1000000).toLocaleString(Qt.locale(), 'f', 0)); + } else if (count >= 1000 ) { + return qsTr("%1K").arg((count / 1000).toLocaleString(Qt.locale(), 'f', 0)); + } else { + return count; + } +} function getDateTimeElapsed(timestamp) { return Format.formatDate(new Date(timestamp * 1000), Formatter.DurationElapsed); diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index ad7a1da..73fe642 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -41,16 +41,6 @@ Page { property variant chatGroupInformation; property int chatOnlineMemberCount: 0; - function getShortenedCount(count) { - if (count >= 1000000) { - return qsTr("%1M").arg((count / 1000000).toLocaleString(Qt.locale(), 'f', 0)); - } else if (count >= 1000 ) { - return qsTr("%1K").arg((count / 1000).toLocaleString(Qt.locale(), 'f', 0)); - } else { - return count; - } - } - function updateChatPartnerStatusText() { if (chatPartnerInformation.status['@type'] === "userStatusEmpty" ) { chatStatusText.text = qsTr("was never online"); @@ -74,12 +64,12 @@ Page { function updateGroupStatusText() { if (chatOnlineMemberCount > 0) { - chatStatusText.text = qsTr("%1 members, %2 online").arg(getShortenedCount(chatGroupInformation.member_count)).arg(getShortenedCount(chatOnlineMemberCount)); + chatStatusText.text = qsTr("%1 members, %2 online").arg(Functions.getShortenedCount(chatGroupInformation.member_count)).arg(Functions.getShortenedCount(chatOnlineMemberCount)); } else { if (isChannel) { - chatStatusText.text = qsTr("%1 subscribers").arg(getShortenedCount(chatGroupInformation.member_count)); + chatStatusText.text = qsTr("%1 subscribers").arg(Functions.getShortenedCount(chatGroupInformation.member_count)); } else { - chatStatusText.text = qsTr("%1 members").arg(getShortenedCount(chatGroupInformation.member_count)); + chatStatusText.text = qsTr("%1 members").arg(Functions.getShortenedCount(chatGroupInformation.member_count)); } } } diff --git a/qml/pages/CoverPage.qml b/qml/pages/CoverPage.qml index eb4ae6d..210661f 100644 --- a/qml/pages/CoverPage.qml +++ b/qml/pages/CoverPage.qml @@ -19,6 +19,7 @@ import QtQuick 2.5 import Sailfish.Silica 1.0 import WerkWolf.Fernschreiber 1.0 +import "../js/functions.js" as Functions CoverBackground { @@ -118,7 +119,7 @@ CoverBackground { id: unreadMessagesCountText font.pixelSize: Theme.fontSizeHuge color: Theme.primaryColor - text: coverPage.unreadMessages + text: Functions.getShortenedCount(coverPage.unreadMessages) } Text { id: unreadMessagesText @@ -147,13 +148,13 @@ CoverBackground { id: unreadChatsCountText font.pixelSize: Theme.fontSizeHuge color: Theme.primaryColor - text: coverPage.unreadChats + text: Functions.getShortenedCount(coverPage.unreadChats) } Text { id: unreadChatsText font.pixelSize: Theme.fontSizeSmall color: Theme.primaryColor - width: parent.width - unreadMessagesCountText.width - inText.width - ( 2 * Theme.paddingMedium ) + width: parent.width - unreadChatsCountText.width - inText.width - ( 2 * Theme.paddingMedium ) wrapMode: Text.Wrap anchors.verticalCenter: unreadChatsCountText.verticalCenter }