Try to use recycler on entrylistdelegate

This commit is contained in:
Bart De Vries 2021-04-06 12:46:01 +02:00
parent 8506068b1f
commit ddb64c5f42
2 changed files with 25 additions and 17 deletions

View File

@ -16,7 +16,7 @@ Kirigami.SwipeListItem {
contentItem: RowLayout { contentItem: RowLayout {
Kirigami.Icon { Kirigami.Icon {
source: model.entry.image === "" ? "rss" : Fetcher.image(model.entry.image) source: entry.image === "" ? "rss" : Fetcher.image(entry.image)
height: parent.height height: parent.height
width: height width: height
} }
@ -25,10 +25,10 @@ Kirigami.SwipeListItem {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Controls.Label { Controls.Label {
text: model.entry.title text: entry.title
Layout.fillWidth: true Layout.fillWidth: true
elide: Text.ElideRight elide: Text.ElideRight
font.weight: model.entry.read ? Font.Normal : Font.Bold font.weight: entry.read ? Font.Normal : Font.Bold
opacity: 1 opacity: 1
} }
Loader { Loader {
@ -37,11 +37,11 @@ Kirigami.SwipeListItem {
Component { Component {
id: subtitle id: subtitle
Controls.Label { Controls.Label {
text: model.entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (model.entry.authors.length === 0 ? "" : " " + i18nc("by <author(s)>", "by") + " " + model.entry.authors[0].name) text: entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (entry.authors.length === 0 ? "" : " " + i18nc("by <author(s)>", "by") + " " + entry.authors[0].name)
Layout.fillWidth: true Layout.fillWidth: true
elide: Text.ElideRight elide: Text.ElideRight
font: Kirigami.Theme.smallFont font: Kirigami.Theme.smallFont
opacity: model.entry.read ? 0.7 : 0.9 opacity: entry.read ? 0.7 : 0.9
visible: !downloadProgress.visible visible: !downloadProgress.visible
} }
} }
@ -50,8 +50,8 @@ Kirigami.SwipeListItem {
Controls.ProgressBar { Controls.ProgressBar {
from: 0 from: 0
to: 100 to: 100
value: model.entry.enclosure.downloadProgress value: entry.enclosure.downloadProgress
visible: model.entry.enclosure && model.entry.enclosure.status === Enclosure.Downloading visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloading
Layout.fillWidth: true Layout.fillWidth: true
} }
} }
@ -60,28 +60,28 @@ Kirigami.SwipeListItem {
} }
onClicked: { onClicked: {
model.entry.read = true entry.read = true
pageStack.push("qrc:/EntryPage.qml", {"entry": model.entry}) pageStack.push("qrc:/EntryPage.qml", {"entry": entry})
} }
actions: [ actions: [
Kirigami.Action { Kirigami.Action {
text: i18n("Download") text: i18n("Download")
icon.name: "download" icon.name: "download"
onTriggered: model.entry.enclosure.download() onTriggered: entry.enclosure.download()
visible: model.entry.enclosure && model.entry.enclosure.status === Enclosure.Downloadable visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloadable
}, },
Kirigami.Action { Kirigami.Action {
text: i18n("Cancel download") text: i18n("Cancel download")
icon.name: "edit-delete-remove" icon.name: "edit-delete-remove"
onTriggered: model.entry.enclosure.cancelDownload() onTriggered: entry.enclosure.cancelDownload()
visible: model.entry.enclosure && model.entry.enclosure.status === Enclosure.Downloading visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloading
}, },
Kirigami.Action { Kirigami.Action {
text: i18n("Delete download") text: i18n("Delete download")
icon.name: "delete" icon.name: "delete"
onTriggered: model.entry.enclosure.deleteFile() onTriggered: entry.enclosure.deleteFile()
visible: model.entry.enclosure && model.entry.enclosure.status === Enclosure.Downloaded visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloaded
} }
] ]
} }

View File

@ -62,11 +62,21 @@ Kirigami.ScrollablePage {
icon.name: feed.errorId === 0 ? "" : "data-error" icon.name: feed.errorId === 0 ? "" : "data-error"
} }
Component {
id: entryListDelegate
EntryListDelegate { }
}
ListView { ListView {
id: entryList id: entryList
visible: count !== 0 visible: count !== 0
model: page.feed.entries model: page.feed.entries
delegate: Kirigami.DelegateRecycler {
width: entryList.width
sourceComponent: entryListDelegate
}
onOriginYChanged: contentY = originY onOriginYChanged: contentY = originY
header: ColumnLayout { header: ColumnLayout {
@ -112,7 +122,5 @@ Kirigami.ScrollablePage {
} }
} }
} }
delegate: EntryListDelegate { }
} }
} }