feat(ui/modules/Linphone): load more entries dynamically

This commit is contained in:
Ronan Abhamon 2016-11-30 10:53:39 +01:00
parent a1fc6a6313
commit a9d43492b0
3 changed files with 31 additions and 9 deletions

View file

@ -1,5 +1,7 @@
#include "ChatProxyModel.hpp"
// ===================================================================
ChatModelFilter::ChatModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(&m_chat_model);
}
@ -30,7 +32,13 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent)
}
void ChatProxyModel::loadMoreEntries () {
// TODO.
int count = rowCount();
m_n_max_displayed_entries += ENTRIES_CHUNK_SIZE;
invalidateFilter();
if (count < rowCount())
emit moreEntriesLoaded();
}
void ChatProxyModel::removeEntry (int id) {

View file

@ -9,7 +9,7 @@
// Fetch the L last filtered chat entries.
// ===================================================================
// Cannot be used as a nested class by Qt and `Q_OBJECTY` macro
// Cannot be used as a nested class by Qt and `Q_OBJECT` macro
// must be used in header c++ file.
class ChatModelFilter : public QSortFilterProxyModel {
friend class ChatProxyModel;
@ -42,6 +42,7 @@ class ChatProxyModel : public QSortFilterProxyModel {
signals:
void sipAddressChanged (const QString &sipAddress);
void moreEntriesLoaded ();
public:
ChatProxyModel (QObject *parent = Q_NULLPTR);

View file

@ -14,6 +14,10 @@ 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: 1
// -----------------------------------------------------------------
spacing: 0
@ -21,16 +25,16 @@ ColumnLayout {
ScrollableListView {
id: chat
property bool _tryToLoadMoreEntries: false
property bool _tryToLoadMoreEntries: true
function _loadMoreEntries () {
if (chat.contentY > 500 || _tryToLoadMoreEntries) {
return
if (
chat.visibleArea.yPosition * chat.height <= _loadMoreEntriesAtPosition &&
!_tryToLoadMoreEntries
) {
_tryToLoadMoreEntries = true
proxyModel.loadMoreEntries()
}
_tryToLoadMoreEntries = true
proxyModel.loadMoreEntries()
}
Layout.fillHeight: true
@ -178,6 +182,15 @@ ColumnLayout {
}
onContentYChanged: _loadMoreEntries()
Component.onCompleted: {
positionViewAtEnd()
_tryToLoadMoreEntries = false
proxyModel.moreEntriesLoaded.connect(function () {
_tryToLoadMoreEntries = false
})
}
}
// -----------------------------------------------------------------