fix(ui/modules/Linphone/Chat/Chat): block at each scroll

This commit is contained in:
Ronan Abhamon 2016-11-30 15:34:42 +01:00
parent ceef883d6f
commit 1149e9ad8f
3 changed files with 12 additions and 23 deletions

View file

@ -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);
}
}

View file

@ -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:

View file

@ -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`),