harbour-nextcloudnotes/qml/pages/NotesPage.qml

170 lines
6 KiB
QML
Raw Normal View History

2018-10-16 18:50:58 +03:00
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
SilicaListView {
id: notesList
anchors.fill: parent
2018-10-21 02:44:23 +03:00
spacing: Theme.paddingLarge
2018-10-16 18:50:58 +03:00
PullDownMenu {
busy: notes.busy
MenuLabel {
visible: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
text: visible ? qsTr("Last update") + ": " + new Date(appSettings.accounts[appSettings.currentAccount].lastUpdate).toLocaleString(Qt.locale(), Locale.ShortFormat) : ""
}
MenuItem {
text: qsTr("Reload")
visible: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
onClicked: notes.getNotes()
}
2018-10-16 18:50:58 +03:00
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
2018-10-16 18:50:58 +03:00
}
MenuItem {
text: qsTr("Add note")
enabled: typeof(appSettings.accounts[appSettings.currentAccount]) !== 'undefined'
2018-10-16 18:50:58 +03:00
onClicked: console.log("Add note")
}
}
header: SearchField {
width: parent.width
placeholderText: qsTr("Nextcloud Notes")
onTextChanged: notes.search(text.toLowerCase())
2018-10-16 18:50:58 +03:00
EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false
enabled: false //notesList.count > 0 // TODO
2018-10-16 18:50:58 +03:00
}
currentIndex: -1
2018-10-21 02:44:23 +03:00
Component.onCompleted: {
if (appSettings.accounts.length > 0) {
2018-10-21 02:44:23 +03:00
notes.getNotes()
}
2018-10-21 02:44:23 +03:00
}
//Component.onCompleted: notes.getNotes()
//Component.onCompleted: notes.getNote("1212725")
//Component.onCompleted: notes.createNote("Hello World!", "Test")
//Component.onCompleted: notes.updateNote(1212725, "# Hello World!\nIs this working?", "Test")
//Component.onCompleted: notes.deleteNote(1212725)
2018-10-16 18:50:58 +03:00
model: notes.model
2018-10-16 18:50:58 +03:00
delegate: ListItem {
id: note
contentHeight: titleLabel.height + previewLabel.height + 2*Theme.paddingSmall
2018-10-16 18:50:58 +03:00
IconButton {
id: isFavoriteIcon
anchors.left: parent.left
2018-10-21 02:44:23 +03:00
anchors.leftMargin: Theme.paddingSmall
anchors.top: parent.top
2018-10-16 18:50:58 +03:00
width: Theme.iconSizeMedium
icon.source: (favorite ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: {
console.log("Toggle favorite")
favorite = !favorite
notes.updateNote(id, {'favorite': favorite} )
2018-10-16 18:50:58 +03:00
}
}
Label {
id: titleLabel
anchors.left: isFavoriteIcon.right
anchors.leftMargin: Theme.paddingSmall
anchors.right: parent.right
anchors.rightMargin: Theme.horizontalPageMargin
anchors.top: parent.top
2018-10-16 18:50:58 +03:00
text: title
truncationMode: TruncationMode.Fade
color: note.highlighted ? Theme.highlightColor : Theme.primaryColor
}
Label {
id: previewLabel
2018-10-16 18:50:58 +03:00
anchors.left: isFavoriteIcon.right
anchors.leftMargin: Theme.paddingSmall
anchors.right: parent.right
anchors.rightMargin: Theme.horizontalPageMargin
anchors.top: titleLabel.bottom
2018-10-21 02:44:23 +03:00
anchors.topMargin: Theme.paddingMedium
height: Theme.itemSizeExtraLarge
text: content
2018-10-16 18:50:58 +03:00
font.pixelSize: Theme.fontSizeExtraSmall
2018-10-21 02:44:23 +03:00
textFormat: Text.PlainText
wrapMode: Text.Wrap
elide: Text.ElideRight
color: note.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
2018-10-16 18:50:58 +03:00
}
onClicked: pageStack.push(Qt.resolvedUrl("NotePage.qml"), { note: notesList.model.get(index) } )
2018-10-16 18:50:58 +03:00
menu: ContextMenu {
Label {
id: modifiedLabel
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Modified") + ": " + new Date(modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
2018-10-16 18:50:58 +03:00
font.pixelSize: Theme.fontSizeSmall
color: Theme.highlightColor
2018-10-16 18:50:58 +03:00
}
MenuItem {
text: qsTr("Delete")
onClicked: console.log("Delete note")
}
}
}
section.property: "category"
section.criteria: ViewSection.FullString
section.labelPositioning: ViewSection.InlineLabels
section.delegate: SectionHeader {
text: section
2018-10-16 18:50:58 +03:00
}
BusyIndicator {
id: busyIndicator
anchors.centerIn: parent
size: BusyIndicatorSize.Large
visible: notesList.count === 0 && notes.busy
2018-10-16 18:50:58 +03:00
running: visible
}
ViewPlaceholder {
id: noLoginPlaceholder
enabled: (appSettings.accounts.length === 0)
text: qsTr("No accounts yet")
}
2018-10-21 02:44:23 +03:00
ViewPlaceholder {
enabled: notesList.count === 0 && !notes.busy && !noLoginPlaceholder.enabled
text: qsTr("No notes yet")
hintText: qsTr("Pull down to add a note")
2018-10-21 02:44:23 +03:00
}
2018-10-16 18:50:58 +03:00
VerticalScrollDecorator { flickable: notesList }
}
TouchInteractionHint {
id: addAccountHint
Component.onCompleted: if (appSettings.accounts.length === 0) restart()
interactionMode: TouchInteraction.Pull
direction: TouchInteraction.Down
}
InteractionHintLabel {
anchors.fill: parent
text: qsTr("Open the settings to add a new Nextcloud account")
opacity: addAccountHint.running ? 1.0 : 0.0
Behavior on opacity { FadeAnimation {} }
width: parent.width
}
2018-10-16 18:50:58 +03:00
}