2017-06-07 08:56:42 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import "../../lib/API.js" as Logic
|
|
|
|
import "."
|
|
|
|
|
|
|
|
|
|
|
|
SilicaListView {
|
|
|
|
id: myList
|
|
|
|
property string type;
|
|
|
|
property string title
|
|
|
|
property string description
|
|
|
|
property ListModel mdl: []
|
|
|
|
property variant params: []
|
|
|
|
property var locale: Qt.locale()
|
|
|
|
property bool loadStarted : false;
|
|
|
|
property int scrollOffset;
|
|
|
|
property string action: ""
|
|
|
|
property variant vars
|
|
|
|
property variant conf
|
2017-06-14 17:42:28 +03:00
|
|
|
property bool notifier : false;
|
2017-06-07 08:56:42 +03:00
|
|
|
model: mdl
|
|
|
|
signal notify (string what, int num)
|
|
|
|
onNotify: {
|
|
|
|
console.log(what + " - " + num)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
signal openDrawer (bool setDrawer)
|
|
|
|
onOpenDrawer: {
|
|
|
|
//console.log("Open drawer: " + setDrawer)
|
|
|
|
}
|
|
|
|
signal send (string notice)
|
|
|
|
onSend: {
|
|
|
|
console.log("LIST send signal emitted with notice: " + notice)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BusyIndicator {
|
|
|
|
size: BusyIndicatorSize.Large
|
|
|
|
running: myList.model.count === 0 && !viewPlaceHolder.visible
|
|
|
|
anchors.centerIn: parent
|
|
|
|
}
|
|
|
|
|
|
|
|
header: PageHeader {
|
|
|
|
title: myList.title
|
|
|
|
description: myList.description
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ViewPlaceholder {
|
|
|
|
id: viewPlaceHolder
|
|
|
|
enabled: model.count === 0
|
|
|
|
text: ""
|
|
|
|
hintText: ""
|
|
|
|
}
|
|
|
|
|
|
|
|
PullDownMenu {
|
|
|
|
MenuItem {
|
|
|
|
text: Logic.conf['login'] ? qsTrId("Logout"): qsTrId("Login")
|
|
|
|
onClicked: {
|
|
|
|
if (Logic.conf['login']) {
|
|
|
|
Logic.conf['login'] = false
|
|
|
|
Logic.conf['instance'] = null;
|
|
|
|
Logic.conf['api_user_token'] = null;
|
|
|
|
Logic.conf['dysko'] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Load more")
|
|
|
|
onClicked: {
|
|
|
|
loadData("prepend")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-16 17:45:04 +03:00
|
|
|
/*PushUpMenu {
|
2017-06-07 08:56:42 +03:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Load more")
|
|
|
|
onClicked: {
|
|
|
|
loadData("append")
|
|
|
|
}
|
|
|
|
}
|
2017-06-16 17:45:04 +03:00
|
|
|
}*/
|
2017-06-07 08:56:42 +03:00
|
|
|
clip: true
|
|
|
|
section {
|
|
|
|
property: 'section'
|
|
|
|
delegate: SectionHeader {
|
2017-06-16 17:45:04 +03:00
|
|
|
height: Theme.itemSizeExtraSmall
|
|
|
|
text: Format.formatDate(section, Formatter.DateMedium)
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-13 17:45:52 +03:00
|
|
|
delegate: VisualContainer {} //Toot {}
|
2017-06-07 08:56:42 +03:00
|
|
|
|
|
|
|
add: Transition {
|
|
|
|
NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 800 }
|
|
|
|
NumberAnimation { property: "x"; duration: 800; easing.type: Easing.InOutBack }
|
|
|
|
}
|
|
|
|
|
|
|
|
displaced: Transition {
|
|
|
|
NumberAnimation { properties: "x,y"; duration: 800; easing.type: Easing.InOutBack }
|
|
|
|
}
|
|
|
|
|
|
|
|
onCountChanged: {
|
2017-06-16 17:45:04 +03:00
|
|
|
loadStarted = false;
|
|
|
|
/*contentY = scrollOffset
|
|
|
|
console.log("CountChanged!")*/
|
2017-06-07 08:56:42 +03:00
|
|
|
|
|
|
|
}
|
2017-06-16 17:45:04 +03:00
|
|
|
footer: Item{
|
|
|
|
width: parent.width
|
|
|
|
height: Theme.itemSizeLarge
|
|
|
|
Button {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.margins: Theme.paddingSmall
|
|
|
|
anchors.bottomMargin: Theme.paddingLarge
|
|
|
|
visible: false
|
|
|
|
onClicked: {
|
|
|
|
loadData("append")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BusyIndicator {
|
|
|
|
size: BusyIndicatorSize.Small
|
|
|
|
running: loadStarted;
|
|
|
|
//anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
}
|
2017-06-07 08:56:42 +03:00
|
|
|
onContentYChanged: {
|
|
|
|
|
|
|
|
if (contentY > scrollOffset) {
|
|
|
|
openDrawer(false)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
openDrawer(true)
|
|
|
|
}
|
2017-06-16 17:45:04 +03:00
|
|
|
|
|
|
|
if(contentY+height > footerItem.y && !loadStarted){
|
|
|
|
loadData("append")
|
|
|
|
loadStarted = true;
|
|
|
|
}
|
2017-06-07 08:56:42 +03:00
|
|
|
scrollOffset = contentY
|
|
|
|
}
|
|
|
|
VerticalScrollDecorator {}
|
|
|
|
|
|
|
|
WorkerScript {
|
|
|
|
id: worker
|
|
|
|
source: "../../lib/Worker.js"
|
|
|
|
onMessage: {
|
|
|
|
if (messageObject.error){
|
|
|
|
console.log(JSON.stringify(messageObject))
|
|
|
|
}
|
2017-06-14 17:42:28 +03:00
|
|
|
if (messageObject.fireNotification && notifier){
|
2017-06-15 01:48:53 +03:00
|
|
|
Logic.notifier(messageObject.data)
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2017-06-14 17:42:28 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
var msg = {
|
|
|
|
'action' : type,
|
|
|
|
'params' : [ ],
|
|
|
|
'model' : model,
|
|
|
|
'mode' : "append",
|
|
|
|
'conf' : Logic.conf
|
|
|
|
};
|
|
|
|
worker.sendMessage(msg);
|
|
|
|
}
|
2017-06-14 17:42:28 +03:00
|
|
|
|
|
|
|
Timer {
|
2017-06-15 01:48:53 +03:00
|
|
|
triggeredOnStart: false; interval: 5*60*1000; running: true; repeat: true
|
2017-06-14 17:42:28 +03:00
|
|
|
onTriggered: {
|
|
|
|
console.log(title + ' ' +Date().toString())
|
|
|
|
loadData("prepend")
|
|
|
|
}
|
|
|
|
}
|
2017-06-07 08:56:42 +03:00
|
|
|
function loadData(mode){
|
|
|
|
var p = [];
|
|
|
|
if (mode === "append" && model.count){
|
|
|
|
p.push({name: 'max_id', data: model.get(model.count-1).id});
|
|
|
|
}
|
|
|
|
if (mode === "prepend" && model.count){
|
|
|
|
p.push({name:'since_id', data: model.get(0).id});
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg = {
|
|
|
|
'action' : type,
|
|
|
|
'params' : p,
|
|
|
|
'model' : model,
|
|
|
|
'mode' : mode,
|
|
|
|
'conf' : Logic.conf
|
|
|
|
};
|
|
|
|
worker.sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|