Lazy loading for the tweets

This commit is contained in:
Ilya Kitaev 2016-06-21 11:58:06 +03:00
parent 417c9bf609
commit 88d9be953b
4 changed files with 47 additions and 28 deletions

View file

@ -36,6 +36,11 @@ Rectangle {
width: 330
color: "#FFFFFF"
function updateTweets() {
tabView.twitter.item.updateTweets()
}
TabView {
id: tabView
anchors.left: parent.left
@ -45,12 +50,18 @@ Rectangle {
anchors.leftMargin: 14
anchors.rightMargin: 14
anchors.topMargin: 40
property alias twitter: twitter
Tab { title: qsTr("Twitter"); source: "tabs/Twitter.qml" }
Tab { id: twitter; title: qsTr("Twitter"); source: "tabs/Twitter.qml" }
Tab { title: "News" }
Tab { title: "Help" }
Tab { title: "About" }
style: TabViewStyle {
frameOverlap: 0
tabOverlap: 0

View file

@ -210,6 +210,12 @@ ApplicationWindow {
}
}
onRightPanelExpandedChanged: {
if (rightPanelExpanded) {
rightPanel.updateTweets()
}
}
Settings {
id: persistentSettings
property string language

View file

@ -56,12 +56,8 @@ Item {
function reload() {
tweets.clear()
if (from == "" && phrase == "")
return;
if (appWindow.rightPanelExpanded) {
//! [requesting]
var req = new XMLHttpRequest;
req.open("GET", "https://api.twitter.com/1.1/search/tweets.json?from=" + from +
@ -87,8 +83,6 @@ Item {
req.send();
//! [requesting]
}
}
Component.onCompleted: {
if (consumerKey === "" || consumerSecret == "") {
@ -96,7 +90,7 @@ Item {
bearerToken = encodeURIComponent(Helper.demoToken())
tweetsModel.phrase = ""
tweetsModel.from = "@monerocurrency"
reload()
// reload()
return;
}

View file

@ -34,6 +34,8 @@ import "../components"
Item {
id: tab
ListModel {
id: testModel
ListElement { head: "Monero || #xmr"; foot: "<b>@btcplanet</b> Duis turpis arcu, varius nec rutrum in, adipiscing at enim. Donec quis consequat ipsum," }
@ -56,10 +58,16 @@ Item {
property var idx
property var ids
function updateTweets() {
tweetsModel.reload()
}
Component.onCompleted: {
ids = new Array()
}
function idInModel(id) {
for (var j = 0; j < ids.length; j++)
if (ids[j] === id)