harbour-tooter/qml/pages/components/MyList.qml

190 lines
4.9 KiB
QML
Raw Normal View History

import QtQuick 2.2
import Sailfish.Silica 1.0
import "../../lib/API.js" as Logic
import "."
SilicaListView {
id: myList
2020-06-04 12:17:06 +03:00
property string type
property string title
property string vwPlaceholderText: qsTr("Loading")
2018-05-24 16:00:10 +03:00
property string vwPlaceholderHint: qsTr("please wait...")
property string description
property ListModel mdl: []
property variant params: []
property var locale: Qt.locale()
property bool autoLoadMore: true
property bool loadStarted: false
property int scrollOffset
property string action: ""
property variant vars
property variant conf
property bool notifier: false
2020-06-04 20:44:12 +03:00
model: mdl
2020-06-04 12:17:06 +03:00
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)
}
header: PageHeader {
title: myList.title
description: myList.description
}
BusyIndicator {
size: BusyIndicatorSize.Large
running: myList.model.count === 0 && !viewPlaceHolder.visible
anchors.centerIn: parent
}
ViewPlaceholder {
id: viewPlaceHolder
enabled: model.count === 0
text: vwPlaceholderText
hintText: vwPlaceholderHint
}
PullDownMenu {
MenuItem {
2017-07-20 13:14:16 +03:00
text: qsTr("Settings")
onClicked: {
pageStack.push(Qt.resolvedUrl("../SettingsPage.qml"), {})
}
}
MenuItem {
text: qsTr("New Toot")
onClicked: {
pageStack.push(Qt.resolvedUrl("../ConversationPage.qml"), {
2020-06-15 11:42:10 +03:00
headerTitle: qsTr("New Toot"),
type: "new"
})
}
}
MenuItem {
text: qsTr("Load more")
onClicked: {
loadData("prepend")
}
}
}
2020-06-15 11:42:10 +03:00
delegate: VisualContainer {}
add: Transition {
NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 800 }
NumberAnimation { property: "x"; duration: 800; easing.type: Easing.InOutBack }
}
remove: Transition {
NumberAnimation { properties: "x,y"; duration: 800; easing.type: Easing.InOutBack }
}
onCountChanged: {
loadStarted = false
2017-06-16 17:45:04 +03:00
/*contentY = scrollOffset
console.log("CountChanged!")*/
}
2017-10-26 00:45:15 +03:00
2017-06-16 17:45:04 +03:00
footer: Item{
visible: autoLoadMore
2017-06-16 17:45:04 +03:00
width: parent.width
height: Theme.itemSizeLarge
Button {
anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: Theme.paddingSmall
anchors.bottomMargin: Theme.paddingLarge
visible: false
onClicked: {
loadData("append")
2017-10-25 01:37:33 +03:00
}
2017-06-16 17:45:04 +03:00
}
2020-06-04 12:17:06 +03:00
2017-06-16 17:45:04 +03:00
BusyIndicator {
size: BusyIndicatorSize.Small
running: loadStarted;
anchors.verticalCenter: parent.verticalCenter
2017-06-16 17:45:04 +03:00
anchors.horizontalCenter: parent.horizontalCenter
}
}
2020-06-04 12:17:06 +03:00
onContentYChanged: {
if (Math.abs(contentY - scrollOffset) > Theme.itemSizeMedium) {
openDrawer(contentY - scrollOffset > 0 ? false : true )
scrollOffset = contentY
}
if(contentY+height > footerItem.y && !loadStarted && autoLoadMore){
2017-06-16 17:45:04 +03:00
loadData("append")
loadStarted = true
2017-06-16 17:45:04 +03:00
}
}
VerticalScrollDecorator {}
WorkerScript {
id: worker
source: "../../lib/Worker.js"
onMessage: {
if (messageObject.error){
console.log(JSON.stringify(messageObject))
}
if (messageObject.fireNotification && notifier){
2017-10-26 00:45:15 +03:00
Logic.notifier(messageObject.data)
}
}
}
Component.onCompleted: {
loadData("prepend")
}
Timer {
triggeredOnStart: false; interval: 5*60*1000; running: true; repeat: true
onTriggered: {
console.log(title + ' ' +Date().toString())
loadData("prepend")
}
}
2020-06-04 12:17:06 +03:00
function loadData(mode){
var p = []
2017-10-27 17:44:35 +03:00
if (params.length)
for(var i = 0; i<params.length; i++)
p.push(params[i])
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
};
2018-05-24 12:14:02 +03:00
console.log(JSON.stringify(msg))
if (type !== "")
worker.sendMessage(msg)
}
2017-10-25 17:30:23 +03:00
}