Commit 742a6405 authored by Andrea Scarpino's avatar Andrea Scarpino

Support Best stories

parent 0dc53762
......@@ -25,6 +25,7 @@ OTHER_FILES += \
qml/pages/CommentsPage.qml \
qml/pages/ItemDelegate.qml \
qml/pages/AskStoriesPage.qml \
qml/pages/BestStoriesPage.qml \
qml/pages/JobStoriesPage.qml \
qml/pages/NewStoriesPage.qml \
qml/pages/RepliesPage.qml \
......
/*
The MIT License (MIT)
Copyright (c) 2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
import harbour.sailhn 1.0
Page {
property bool storiesLoadedOnce: false
allowedOrientations: Orientation.All
StoriesListView {
id: listView
anchors.fill: parent
pageTitle: "Best"
onRefreshClicked: loadStories()
}
onStatusChanged: {
if (status === PageStatus.Activating) {
if (!storiesLoadedOnce) {
loadStories();
}
listView.submitEnabled = manager.isAuthenticated();
} else if (status === PageStatus.Deactivating) {
storiesLoadedOnce = true;
}
}
function loadStories() {
listView.stories.loadBestStories();
}
}
......@@ -46,6 +46,8 @@ Page {
loadStories();
}
listView.submitEnabled = manager.isAuthenticated();
} else if (status === PageStatus.Active) {
pageStack.pushAttached(Qt.resolvedUrl("BestStoriesPage.qml"));
} else if (status === PageStatus.Deactivating) {
storiesLoadedOnce = true;
}
......
......@@ -3,6 +3,7 @@
- Fix new comments non visible when refreshing
- Show logged user details in the settings
- Save the username
- Support Best stories
* Thu Mar 03 2016 Andrea Scarpino <me@andreascarpino.it> 0.8-1
- Implement authentication
......
......@@ -77,6 +77,7 @@ void HackerNewsAPI::getStories(Stories kind)
QString path;
switch (kind) {
case Ask: path = QStringLiteral("/askstories.json"); break;
case Best: path = QStringLiteral("/beststories.json"); break;
case Job: path = QStringLiteral("/jobstories.json"); break;
case New: path = QStringLiteral("/newstories.json"); break;
case Show: path = QStringLiteral("/showstories.json"); break;
......
......@@ -37,7 +37,7 @@ class HackerNewsAPI : public QObject
Q_OBJECT
public:
enum Stories {
New, Top, Show, Ask, Job
New, Top, Show, Ask, Job, Best
};
explicit HackerNewsAPI(QObject *parent = 0);
......
......@@ -73,6 +73,13 @@ void NewsModel::loadAskStories()
api->getStories(HackerNewsAPI::Ask);
}
void NewsModel::loadBestStories()
{
reset();
api->getStories(HackerNewsAPI::Best);
}
void NewsModel::loadNewStories()
{
reset();
......
......@@ -57,6 +57,7 @@ public:
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE void loadAskStories();
Q_INVOKABLE void loadBestStories();
Q_INVOKABLE void loadNewStories();
Q_INVOKABLE void loadJobStories();
Q_INVOKABLE void loadShowStories();
......
......@@ -119,7 +119,7 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="177"/>
<location filename="../qml/pages/Settings.qml" line="178"/>
<source>Logged</source>
<translation>Connesso</translation>
</message>
......@@ -129,7 +129,7 @@
<translation>Esci</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="111"/>
<location filename="../qml/pages/Settings.qml" line="112"/>
<source>Login failed</source>
<translation>Login fallito</translation>
</message>
......@@ -144,33 +144,33 @@
<translation>Username</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="89"/>
<location filename="../qml/pages/Settings.qml" line="90"/>
<source>Password</source>
<translation>Password</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="95"/>
<location filename="../qml/pages/Settings.qml" line="179"/>
<location filename="../qml/pages/Settings.qml" line="96"/>
<location filename="../qml/pages/Settings.qml" line="180"/>
<source>Login</source>
<translation>Entra</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="128"/>
<location filename="../qml/pages/Settings.qml" line="129"/>
<source>User details</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="134"/>
<location filename="../qml/pages/Settings.qml" line="135"/>
<source>created</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="140"/>
<location filename="../qml/pages/Settings.qml" line="141"/>
<source>karma</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="146"/>
<location filename="../qml/pages/Settings.qml" line="147"/>
<source>About</source>
<translation type="unfinished"></translation>
</message>
......
......@@ -119,7 +119,7 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="177"/>
<location filename="../qml/pages/Settings.qml" line="178"/>
<source>Logged</source>
<translation type="unfinished"></translation>
</message>
......@@ -129,7 +129,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="111"/>
<location filename="../qml/pages/Settings.qml" line="112"/>
<source>Login failed</source>
<translation type="unfinished"></translation>
</message>
......@@ -144,33 +144,33 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="89"/>
<location filename="../qml/pages/Settings.qml" line="90"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="95"/>
<location filename="../qml/pages/Settings.qml" line="179"/>
<location filename="../qml/pages/Settings.qml" line="96"/>
<location filename="../qml/pages/Settings.qml" line="180"/>
<source>Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="128"/>
<location filename="../qml/pages/Settings.qml" line="129"/>
<source>User details</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="134"/>
<location filename="../qml/pages/Settings.qml" line="135"/>
<source>created</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="140"/>
<location filename="../qml/pages/Settings.qml" line="141"/>
<source>karma</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="146"/>
<location filename="../qml/pages/Settings.qml" line="147"/>
<source>About</source>
<translation type="unfinished"></translation>
</message>
......
......@@ -119,7 +119,7 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="177"/>
<location filename="../qml/pages/Settings.qml" line="178"/>
<source>Logged</source>
<translation type="unfinished"></translation>
</message>
......@@ -129,7 +129,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="111"/>
<location filename="../qml/pages/Settings.qml" line="112"/>
<source>Login failed</source>
<translation type="unfinished"></translation>
</message>
......@@ -144,33 +144,33 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="89"/>
<location filename="../qml/pages/Settings.qml" line="90"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="95"/>
<location filename="../qml/pages/Settings.qml" line="179"/>
<location filename="../qml/pages/Settings.qml" line="96"/>
<location filename="../qml/pages/Settings.qml" line="180"/>
<source>Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="128"/>
<location filename="../qml/pages/Settings.qml" line="129"/>
<source>User details</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="134"/>
<location filename="../qml/pages/Settings.qml" line="135"/>
<source>created</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="140"/>
<location filename="../qml/pages/Settings.qml" line="141"/>
<source>karma</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="146"/>
<location filename="../qml/pages/Settings.qml" line="147"/>
<source>About</source>
<translation type="unfinished"></translation>
</message>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment