From 1149e9ad8f1f1900fbd75e81a00f6f15845336a9 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 30 Nov 2016 15:34:42 +0100 Subject: [PATCH] fix(ui/modules/Linphone/Chat/Chat): block at each scroll --- tests/src/components/chat/ChatProxyModel.cpp | 8 ++++--- tests/src/components/chat/ChatProxyModel.hpp | 2 +- tests/ui/modules/Linphone/Chat/Chat.qml | 25 +++++--------------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tests/src/components/chat/ChatProxyModel.cpp b/tests/src/components/chat/ChatProxyModel.cpp index 20faed1bd..e8c213d66 100644 --- a/tests/src/components/chat/ChatProxyModel.cpp +++ b/tests/src/components/chat/ChatProxyModel.cpp @@ -25,7 +25,7 @@ void ChatModelFilter::setEntryTypeFilter (ChatModel::EntryType type) { // =================================================================== -const unsigned int ChatProxyModel::ENTRIES_CHUNK_SIZE = 25; +const unsigned int ChatProxyModel::ENTRIES_CHUNK_SIZE = 50; ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { setSourceModel(&m_chat_model_filter); @@ -43,8 +43,10 @@ void ChatProxyModel::loadMoreEntries () { invalidateFilter(); - if (count < rowCount()) - emit moreEntriesLoaded(); + count = rowCount() - count; + + if (count > 0) + emit moreEntriesLoaded(count); } } diff --git a/tests/src/components/chat/ChatProxyModel.hpp b/tests/src/components/chat/ChatProxyModel.hpp index c1d3951f7..6079d0445 100644 --- a/tests/src/components/chat/ChatProxyModel.hpp +++ b/tests/src/components/chat/ChatProxyModel.hpp @@ -42,7 +42,7 @@ class ChatProxyModel : public QSortFilterProxyModel { signals: void sipAddressChanged (const QString &sipAddress); - void moreEntriesLoaded (); + void moreEntriesLoaded (int n); void entryTypeFilterChanged (ChatModel::EntryType type); public: diff --git a/tests/ui/modules/Linphone/Chat/Chat.qml b/tests/ui/modules/Linphone/Chat/Chat.qml index f2052e9e8..c7169a98d 100644 --- a/tests/ui/modules/Linphone/Chat/Chat.qml +++ b/tests/ui/modules/Linphone/Chat/Chat.qml @@ -15,10 +15,6 @@ ColumnLayout { // Can be a model or a proxy chat model. property alias proxyModel: chat.model - // Set the offset position to load more entries. - // Not a style property. - property int _loadMoreEntriesAtPosition: 25 - // ----------------------------------------------------------------- spacing: 0 @@ -28,12 +24,10 @@ ColumnLayout { property bool _tryToLoadMoreEntries: true - function _loadMoreEntries (force) { - if (( - chat.visibleArea.yPosition * chat.height <= _loadMoreEntriesAtPosition && - !_tryToLoadMoreEntries - ) || force) { + function _loadMoreEntries () { + if (atYBeginning && !_tryToLoadMoreEntries) { _tryToLoadMoreEntries = true + positionViewAtIndex(0, ListView.Beginning) proxyModel.loadMoreEntries() } } @@ -189,16 +183,9 @@ ColumnLayout { } // Received only if more entries was loaded. - proxyModel.moreEntriesLoaded.connect(function () { - if (ScrollBar.vertical.pressed && atYBeginning) { - // Use a timeout to not increase call stack. - Utils.setTimeout(chat, 0, function () { - _loadMoreEntries(true) - positionViewAtIndex(1, ListView.Beginning) - }) - } else { - _tryToLoadMoreEntries = false - } + proxyModel.moreEntriesLoaded.connect(function (n) { + positionViewAtIndex(n - 1, ListView.Beginning) + _tryToLoadMoreEntries = false }) // When the view is changed (for example `Calls` -> `Messages`),