More work on EpisodeSwipePage

Implemented
- unread episodes (still looking for better name)
- mobile and non-mobile tab-views
- i18n and messages when lists are empty
This commit is contained in:
Bart De Vries 2021-04-18 10:44:36 +02:00
parent 29d625e810
commit 6ae1bf5f87
3 changed files with 60 additions and 21 deletions

View File

@ -141,10 +141,13 @@ Entry* DataManager::getEntry(QString id) const
Entry* DataManager::getEntry(const EpisodeModel::Type type, const int entry_index) const Entry* DataManager::getEntry(const EpisodeModel::Type type, const int entry_index) const
{ {
QSqlQuery entryQuery; QSqlQuery entryQuery;
if (type == EpisodeModel::All || type == EpisodeModel::New) { if (type == EpisodeModel::All || type == EpisodeModel::New || type == EpisodeModel::Unread) {
if (type == EpisodeModel::New) { if (type == EpisodeModel::New) {
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE new=:new ORDER BY updated DESC LIMIT 1 OFFSET :index;")); entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE new=:new ORDER BY updated DESC LIMIT 1 OFFSET :index;"));
entryQuery.bindValue(QStringLiteral(":new"), true); entryQuery.bindValue(QStringLiteral(":new"), true);
} else if (type == EpisodeModel::Unread) {
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE read=:read ORDER BY updated DESC LIMIT 1 OFFSET :index;"));
entryQuery.bindValue(QStringLiteral(":read"), false);
} else { // i.e. EpisodeModel::All } else { // i.e. EpisodeModel::All
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries ORDER BY updated DESC LIMIT 1 OFFSET :index;")); entryQuery.prepare(QStringLiteral("SELECT * FROM Entries ORDER BY updated DESC LIMIT 1 OFFSET :index;"));
} }
@ -178,10 +181,13 @@ int DataManager::entryCount(const Feed* feed) const
int DataManager::entryCount(const EpisodeModel::Type type) const int DataManager::entryCount(const EpisodeModel::Type type) const
{ {
QSqlQuery query; QSqlQuery query;
if (type == EpisodeModel::All || type == EpisodeModel::New) { if (type == EpisodeModel::All || type == EpisodeModel::New || type == EpisodeModel::Unread) {
if (type == EpisodeModel::New) { if (type == EpisodeModel::New) {
query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries WHERE new=:new;")); query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries WHERE new=:new;"));
query.bindValue(QStringLiteral(":new"), true); query.bindValue(QStringLiteral(":new"), true);
} else if (type == EpisodeModel::Unread) {
query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries WHERE read=:read;"));
query.bindValue(QStringLiteral(":read"), false);
} else { // i.e. EpisodeModel::All } else { // i.e. EpisodeModel::All
query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries;")); query.prepare(QStringLiteral("SELECT COUNT (id) FROM Entries;"));
} }

View File

@ -18,7 +18,6 @@ import org.kde.alligator 1.0
Kirigami.ScrollablePage { Kirigami.ScrollablePage {
//anchors.fill: parent //anchors.fill: parent
title: i18n("New Episodes")
property var episodeType: EpisodeModel.All property var episodeType: EpisodeModel.All
supportsRefreshing: true supportsRefreshing: true
@ -35,7 +34,10 @@ Kirigami.ScrollablePage {
width: Kirigami.Units.gridUnit * 20 width: Kirigami.Units.gridUnit * 20
anchors.centerIn: parent anchors.centerIn: parent
text: i18n("No Entries available") text: i18n("No %1 available", episodeType === EpisodeModel.All ? i18n("episodes")
: episodeType === EpisodeModel.New ? i18n("new episodes")
: episodeType === EpisodeModel.Unread ? i18n("unread episodes")
: i18n("episodes"))
} }
Component { Component {
id: episodeListDelegate id: episodeListDelegate
@ -50,8 +52,14 @@ Kirigami.ScrollablePage {
model: EpisodeModel { type: episodeType } model: EpisodeModel { type: episodeType }
delegate: Kirigami.DelegateRecycler { delegate: Kirigami.DelegateRecycler {
width: episodeList.width width: episodeList.width
sourceComponent: episodeListDelegate sourceComponent: episodeListDelegate
} }
} }
actions.main: Kirigami.Action {
text: i18n("Refresh all feeds")
iconName: "view-refresh"
onTriggered: refreshing = true
visible: !Kirigami.Settings.isMobile
}
} }

View File

@ -20,38 +20,63 @@ Kirigami.Page {
title: i18n("Episode List") title: i18n("Episode List")
padding: 0 padding: 0
header: Controls.TabBar { header: Loader {
id: tabBar id: headerLoader
currentIndex: swipeView.currentIndex active: !Kirigami.Settings.isMobile
sourceComponent: tabBarComponent
property var swipeViewItem: swipeView
}
Controls.TabButton { footer: Loader {
text: "New Episodes" id: footerLoader
} active: Kirigami.Settings.isMobile
Controls.TabButton { sourceComponent: tabBarComponent
text: "All Episodes" property var swipeViewItem: swipeView
}
Component {
id: tabBarComponent
Controls.TabBar {
id: tabBar
position: Controls.TabBar.Footer
currentIndex: swipeViewItem.currentIndex
Controls.TabButton {
width: parent.parent.width/parent.count
height: Kirigami.Units.gridUnit * 2
text: i18n("New Episodes")
}
Controls.TabButton {
width: parent.parent.width/parent.count
height: Kirigami.Units.gridUnit * 2
text: i18n("Unread Episodes")
}
Controls.TabButton {
width: parent.parent.width/parent.count
height: Kirigami.Units.gridUnit * 2
text: i18n("All Episodes")
}
} }
} }
Controls.SwipeView { Controls.SwipeView {
id: swipeView id: swipeView
anchors.fill: parent anchors.fill: parent
currentIndex: tabBar.currentIndex currentIndex: Kirigami.Settings.isMobile ? footerLoader.item.currentIndex : headerLoader.item.currentIndex
EpisodeListPage { EpisodeListPage {
title: i18n("New Episodes") title: i18n("New Episodes")
episodeType: EpisodeModel.New episodeType: EpisodeModel.New
} }
EpisodeListPage {
title: i18n("Unread Episodes")
episodeType: EpisodeModel.Unread
}
EpisodeListPage { EpisodeListPage {
title: i18n("All Episodes") title: i18n("All Episodes")
episodeType: EpisodeModel.All episodeType: EpisodeModel.All
} }
} }
/*actions.main: Kirigami.Action {
text: i18n("Refresh all feeds")
iconName: "view-refresh"
onTriggered: refreshing = true
visible: !Kirigami.Settings.isMobile
}*/
} }