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 width: 330
color: "#FFFFFF" color: "#FFFFFF"
function updateTweets() {
tabView.twitter.item.updateTweets()
}
TabView { TabView {
id: tabView id: tabView
anchors.left: parent.left anchors.left: parent.left
@ -45,12 +50,18 @@ Rectangle {
anchors.leftMargin: 14 anchors.leftMargin: 14
anchors.rightMargin: 14 anchors.rightMargin: 14
anchors.topMargin: 40 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: "News" }
Tab { title: "Help" } Tab { title: "Help" }
Tab { title: "About" } Tab { title: "About" }
style: TabViewStyle { style: TabViewStyle {
frameOverlap: 0 frameOverlap: 0
tabOverlap: 0 tabOverlap: 0

View file

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

View file

@ -56,13 +56,9 @@ Item {
function reload() { function reload() {
tweets.clear() tweets.clear()
if (from == "" && phrase == "") if (from == "" && phrase == "")
return; return;
//! [requesting]
if (appWindow.rightPanelExpanded) {
//! [requesting]
var req = new XMLHttpRequest; var req = new XMLHttpRequest;
req.open("GET", "https://api.twitter.com/1.1/search/tweets.json?from=" + from + req.open("GET", "https://api.twitter.com/1.1/search/tweets.json?from=" + from +
"&count=" + tweetsMaxCount + "&q=" + encodePhrase(phrase)); "&count=" + tweetsMaxCount + "&q=" + encodePhrase(phrase));
@ -85,10 +81,8 @@ Item {
wasLoading = (status === XMLHttpRequest.LOADING); wasLoading = (status === XMLHttpRequest.LOADING);
} }
req.send(); req.send();
//! [requesting] //! [requesting]
} }
}
Component.onCompleted: { Component.onCompleted: {
if (consumerKey === "" || consumerSecret == "") { if (consumerKey === "" || consumerSecret == "") {
@ -96,7 +90,7 @@ Item {
bearerToken = encodeURIComponent(Helper.demoToken()) bearerToken = encodeURIComponent(Helper.demoToken())
tweetsModel.phrase = "" tweetsModel.phrase = ""
tweetsModel.from = "@monerocurrency" tweetsModel.from = "@monerocurrency"
reload() // reload()
return; return;
} }

View file

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