Optimize image loading (partially) and improve QueueDelegate

This commit is contained in:
Bart De Vries 2021-04-06 23:01:26 +02:00
parent ddb64c5f42
commit 5efd4f85f8
4 changed files with 73 additions and 55 deletions

View File

@ -32,7 +32,7 @@ QVariant EntriesModel::data(const QModelIndex &index, int role) const
{
if (role != 0)
return QVariant();
qDebug() << "fetching item" << index.row();
//qDebug() << "fetching item" << index.row();
return QVariant::fromValue(DataManager::instance().getEntry(m_feed, index.row()));
}

View File

@ -15,49 +15,54 @@ import org.kde.alligator 1.0
Kirigami.SwipeListItem {
contentItem: RowLayout {
Kirigami.Icon {
source: entry.image === "" ? "rss" : Fetcher.image(entry.image)
height: parent.height
width: height
Image {
asynchronous: true
source: entry.image === "" ? "rss" : "file://"+Fetcher.image(entry.image)
fillMode: Image.PreserveAspectFit
property int size: Kirigami.Units.iconSizes.medium
Layout.maximumHeight: size
Layout.maximumWidth: size
sourceSize.width: size
sourceSize.height: size
}
ColumnLayout {
spacing: 0
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
Controls.Label {
text: entry.title
ColumnLayout {
spacing: 0
Layout.fillWidth: true
elide: Text.ElideRight
font.weight: entry.read ? Font.Normal : Font.Bold
opacity: 1
}
Loader {
sourceComponent: entry.enclosure && entry.enclosure.status === Enclosure.Downloading ? downloadProgress : subtitle
Layout.fillWidth: true
Component {
id: subtitle
Controls.Label {
text: entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (entry.authors.length === 0 ? "" : " " + i18nc("by <author(s)>", "by") + " " + entry.authors[0].name)
Layout.fillWidth: true
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: entry.read ? 0.7 : 0.9
visible: !downloadProgress.visible
}
Layout.alignment: Qt.AlignVCenter
Controls.Label {
text: entry.title
Layout.fillWidth: true
elide: Text.ElideRight
font.weight: entry.read ? Font.Normal : Font.Bold
opacity: 1
}
Component {
id: downloadProgress
Controls.ProgressBar {
from: 0
to: 100
value: entry.enclosure.downloadProgress
visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloading
Layout.fillWidth: true
Loader {
sourceComponent: entry.enclosure && entry.enclosure.status === Enclosure.Downloading ? downloadProgress : subtitle
Layout.fillWidth: true
Component {
id: subtitle
Controls.Label {
text: entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (entry.authors.length === 0 ? "" : " " + i18nc("by <author(s)>", "by") + " " + entry.authors[0].name)
Layout.fillWidth: true
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: entry.read ? 0.7 : 0.9
visible: !downloadProgress.visible
}
}
Component {
id: downloadProgress
Controls.ProgressBar {
from: 0
to: 100
value: entry.enclosure.downloadProgress
visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloading
Layout.fillWidth: true
}
}
}
}
}
}
onClicked: {
entry.read = true

View File

@ -20,15 +20,15 @@ Kirigami.SwipeListItem {
contentItem: Kirigami.BasicListItem {
anchors.top: parent.top
anchors.bottom: parent.bottom
text: model.feed.name
icon: model.feed.refreshing ? "view-refresh" : model.feed.image === "" ? "rss" : Fetcher.image(model.feed.image)
iconSize: Kirigami.Units.iconSizes.large
subtitle: i18np("%1 unread entry", "%1 unread entries", model.feed.unreadEntryCount)
text: feed.name
icon: feed.refreshing ? "view-refresh" : feed.image === "" ? "rss" : Fetcher.image(feed.image)
iconSize: Kirigami.Units.iconSizes.medium
subtitle: i18np("%1 unread entry", "%1 unread entries", feed.unreadEntryCount)
onClicked: {
lastFeed = model.feed.url
lastFeed = feed.url
pageStack.push("qrc:/EntryListPage.qml", {"feed": model.feed})
pageStack.push("qrc:/EntryListPage.qml", {"feed": feed})
}
}
@ -36,7 +36,7 @@ Kirigami.SwipeListItem {
Kirigami.Action {
icon.name: "delete"
onTriggered: {
if(pageStack.depth > 1 && model.feed.url === lastFeed)
if(pageStack.depth > 1 && feed.url === lastFeed)
while(pageStack.depth > 1)
pageStack.pop()
feedsModel.removeFeed(index)

View File

@ -22,21 +22,33 @@ Kirigami.SwipeListItem {
listView: queueList
onMoveRequested: DataManager.moveQueueItem(oldIndex, newIndex)
}
Kirigami.Icon {
source: entry.image === "" ? "rss" : Fetcher.image(entry.image)
property int size: Kirigami.Units.iconSizes.medium
Layout.minimumHeight: size
Layout.minimumWidth: size
Image {
asynchronous: true
source: entry.image === "" ? "rss" : "file://"+Fetcher.image(entry.image)
fillMode: Image.PreserveAspectFit
property int size: Kirigami.Units.gridUnit * 3
sourceSize.width: size
sourceSize.height: size
Layout.maximumHeight: size
Layout.maximumWidth: size
Layout.rightMargin:Kirigami.Units.smallSpacing
}
ColumnLayout {
spacing: 0
spacing: Kirigami.Units.smallSpacing
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
Controls.Label {
text: entry.updated.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + (entry.enclosure ? " · " + Math.floor(entry.enclosure.size/(1024*1024)) + "MB" : "")
Layout.fillWidth: true
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: 0.7
}
Controls.Label {
text: entry.title
Layout.fillWidth: true
elide: Text.ElideRight
font.weight: entry.read ? Font.Normal : Font.Bold
font.weight: Font.Normal
opacity: 1
}
Loader {
@ -45,11 +57,11 @@ Kirigami.SwipeListItem {
Component {
id: subtitle
Controls.Label {
text: entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (entry.authors.length === 0 ? "" : " " + i18nc("by <author(s)>", "by") + " " + entry.authors[0].name)
text: (Math.floor(entry.enclosure.duration/3600) < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/3600) + ":" + (Math.floor(entry.enclosure.duration/60) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/60) % 60 + ":" + (Math.floor(entry.enclosure.duration) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration) % 60
Layout.fillWidth: true
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: entry.read ? 0.7 : 0.9
opacity: 0.7
visible: !downloadProgress.visible
}
}
@ -77,9 +89,10 @@ Kirigami.SwipeListItem {
iconName: "media-playback-start"
text: "Play"
onTriggered: {
audio.entry = entry
audio.play()
audio.entry = entry
audio.play()
}
visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloaded
},
Kirigami.Action {
text: i18n("Download")