Commit a9d43492 authored by Ronan's avatar Ronan
Browse files

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

parent a1fc6a63
#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) {
......
......@@ -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);
......
......@@ -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
})
}
}
// -----------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment