Commit 97c22779 authored by Andrea Scarpino's avatar Andrea Scarpino

Refactoring: re-use common logic

parent e85afc89
......@@ -33,6 +33,7 @@ OTHER_FILES += \
qml/pages/Settings.qml \
qml/pages/Submit.qml \
qml/pages/ShowStoriesPage.qml \
qml/pages/StoriesListView.qml \
qml/pages/TopStoriesPage.qml \
harbour-sailhn.desktop \
rpm/harbour-sailhn.changes \
......
......@@ -32,47 +32,12 @@ Page {
allowedOrientations: Orientation.All
SilicaListView {
StoriesListView {
id: listView
anchors.fill: parent
pageTitle: "Ask"
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("Settings.qml"))
}
MenuItem {
id: submit
text: qsTr("Submit")
onClicked: pageStack.push(Qt.resolvedUrl("Submit.qml"))
}
MenuItem {
text: qsTr("Refresh")
onClicked: loadStories()
}
}
PushUpMenu {
MenuItem {
text: qsTr("Load more")
onClicked: model.nextItems()
}
}
model: NewsModel {
id: model
}
header: PageHeader {
title: "Ask"
}
delegate: ItemDelegate {}
VerticalScrollDecorator {}
onRefreshClicked: loadStories()
}
onStatusChanged: {
......@@ -80,7 +45,7 @@ Page {
if (!storiesLoadedOnce) {
loadStories();
}
submit.enabled = manager.isAuthenticated();
listView.submitEnabled = manager.isAuthenticated();
} else if (status === PageStatus.Active) {
pageStack.pushAttached(Qt.resolvedUrl("JobStoriesPage.qml"));
} else if (status === PageStatus.Deactivating) {
......@@ -89,6 +54,6 @@ Page {
}
function loadStories() {
model.loadAskStories();
listView.stories.loadAskStories();
}
}
......@@ -32,47 +32,12 @@ Page {
allowedOrientations: Orientation.All
SilicaListView {
StoriesListView {
id: listView
anchors.fill: parent
pageTitle: "Job"
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("Settings.qml"))
}
MenuItem {
id: submit
text: qsTr("Submit")
onClicked: pageStack.push(Qt.resolvedUrl("Submit.qml"))
}
MenuItem {
text: qsTr("Refresh")
onClicked: loadStories()
}
}
PushUpMenu {
MenuItem {
text: qsTr("Load more")
onClicked: model.nextItems()
}
}
model: NewsModel {
id: model
}
header: PageHeader {
title: "Job"
}
delegate: ItemDelegate {}
VerticalScrollDecorator {}
onRefreshClicked: loadStories()
}
onStatusChanged: {
......@@ -80,13 +45,13 @@ Page {
if (!storiesLoadedOnce) {
loadStories();
}
submit.enabled = manager.isAuthenticated();
listView.submitEnabled = manager.isAuthenticated();
} else if (status === PageStatus.Deactivating) {
storiesLoadedOnce = true;
}
}
function loadStories() {
model.loadJobStories();
listView.stories.loadJobStories();
}
}
......@@ -32,47 +32,12 @@ Page {
allowedOrientations: Orientation.All
SilicaListView {
StoriesListView {
id: listView
anchors.fill: parent
pageTitle: "Newest"
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("Settings.qml"))
}
MenuItem {
id: submit
text: qsTr("Submit")
onClicked: pageStack.push(Qt.resolvedUrl("Submit.qml"))
}
MenuItem {
text: qsTr("Refresh")
onClicked: loadStories()
}
}
PushUpMenu {
MenuItem {
text: qsTr("Load more")
onClicked: model.nextItems()
}
}
model: NewsModel {
id: model
}
header: PageHeader {
title: "Newest"
}
delegate: ItemDelegate {}
VerticalScrollDecorator {}
onRefreshClicked: loadStories()
}
onStatusChanged: {
......@@ -80,7 +45,7 @@ Page {
if (!storiesLoadedOnce) {
loadStories();
}
submit.enabled = manager.isAuthenticated();
listView.submitEnabled = manager.isAuthenticated();
} else if (status === PageStatus.Active) {
pageStack.pushAttached(Qt.resolvedUrl("ShowStoriesPage.qml"));
} else if (status === PageStatus.Deactivating) {
......@@ -89,6 +54,6 @@ Page {
}
function loadStories() {
model.loadNewStories();
listView.stories.loadNewStories();
}
}
......@@ -32,47 +32,12 @@ Page {
allowedOrientations: Orientation.All
SilicaListView {
StoriesListView {
id: listView
anchors.fill: parent
pageTitle: "Show"
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("Settings.qml"))
}
MenuItem {
id: submit
text: qsTr("Submit")
onClicked: pageStack.push(Qt.resolvedUrl("Submit.qml"))
}
MenuItem {
text: qsTr("Refresh")
onClicked: loadStories()
}
}
PushUpMenu {
MenuItem {
text: qsTr("Load more")
onClicked: model.nextItems()
}
}
model: NewsModel {
id: model
}
header: PageHeader {
title: "Show"
}
delegate: ItemDelegate {}
VerticalScrollDecorator {}
onRefreshClicked: loadStories()
}
onStatusChanged: {
......@@ -80,7 +45,7 @@ Page {
if (!storiesLoadedOnce) {
loadStories();
}
submit.enabled = manager.isAuthenticated();
listView.submitEnabled = manager.isAuthenticated();
} else if (status === PageStatus.Active) {
pageStack.pushAttached(Qt.resolvedUrl("AskStoriesPage.qml"));
} else if (status === PageStatus.Deactivating) {
......@@ -89,6 +54,6 @@ Page {
}
function loadStories() {
model.loadShowStories();
listView.stories.loadShowStories();
}
}
/*
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
SilicaListView {
id: listView
property string pageTitle
property bool submitEnabled
property alias stories: model
signal refreshClicked
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("Settings.qml"))
}
MenuItem {
text: qsTr("Submit")
enabled: submitEnabled
onClicked: pageStack.push(Qt.resolvedUrl("Submit.qml"))
}
MenuItem {
text: qsTr("Refresh")
onClicked: listView.refreshClicked()
}
}
PushUpMenu {
MenuItem {
text: qsTr("Load more")
onClicked: model.nextItems()
}
}
model: NewsModel {
id: model
}
header: PageHeader {
title: pageTitle
}
delegate: ItemDelegate {}
VerticalScrollDecorator {}
}
......@@ -32,47 +32,12 @@ Page {
allowedOrientations: Orientation.All
SilicaListView {
StoriesListView {
id: listView
anchors.fill: parent
pageTitle: "Top"
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("Settings.qml"))
}
MenuItem {
id: submit
text: qsTr("Submit")
onClicked: pageStack.push(Qt.resolvedUrl("Submit.qml"))
}
MenuItem {
text: qsTr("Refresh")
onClicked: loadStories()
}
}
PushUpMenu {
MenuItem {
text: qsTr("Load more")
onClicked: model.nextItems()
}
}
model: NewsModel {
id: model
}
header: PageHeader {
title: "Top"
}
delegate: ItemDelegate {}
VerticalScrollDecorator {}
onRefreshClicked: loadStories()
}
onStatusChanged: {
......@@ -80,7 +45,7 @@ Page {
if (!storiesLoadedOnce) {
loadStories();
}
submit.enabled = manager.isAuthenticated();
listView.submitEnabled = manager.isAuthenticated();
} else if (status === PageStatus.Active) {
pageStack.pushAttached(Qt.resolvedUrl("NewStoriesPage.qml"));
} else if (status === PageStatus.Deactivating) {
......@@ -89,6 +54,6 @@ Page {
}
function loadStories() {
model.loadTopStories();
listView.stories.loadTopStories();
}
}
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="it">
<context>
<name>AskStoriesPage</name>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation>Invia</translation>
</message>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Aggiorna</translation>
</message>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Carica altro</translation>
</message>
</context>
<context>
<name>CommentsPage</name>
<message>
......@@ -75,52 +52,6 @@
<translation>Apri URL esterno</translation>
</message>
</context>
<context>
<name>JobStoriesPage</name>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation>Invia</translation>
</message>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Aggiorna</translation>
</message>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Carica altro</translation>
</message>
</context>
<context>
<name>NewStoriesPage</name>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation>Invia</translation>
</message>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Aggiorna</translation>
</message>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Carica altro</translation>
</message>
</context>
<context>
<name>RepliesPage</name>
<message>
......@@ -245,26 +176,26 @@
</message>
</context>
<context>
<name>ShowStoriesPage</name>
<name>StoriesListView</name>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="41"/>
<location filename="../qml/pages/StoriesListView.qml" line="41"/>
<source>Settings</source>
<translation>Impostazioni</translation>
<translation type="unfinished">Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="47"/>
<location filename="../qml/pages/StoriesListView.qml" line="47"/>
<source>Submit</source>
<translation>Invia</translation>
<translation type="unfinished">Invia</translation>
</message>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="52"/>
<location filename="../qml/pages/StoriesListView.qml" line="54"/>
<source>Refresh</source>
<translation>Aggiorna</translation>
<translation type="unfinished">Aggiorna</translation>
</message>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="60"/>
<location filename="../qml/pages/StoriesListView.qml" line="63"/>
<source>Load more</source>
<translation>Carica altro</translation>
<translation type="unfinished">Carica altro</translation>
</message>
</context>
<context>
......@@ -306,27 +237,4 @@
<translation>Errore nell&apos;invio</translation>
</message>
</context>
<context>
<name>TopStoriesPage</name>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation>Invia</translation>
</message>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Aggiorna</translation>
</message>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Carica altro</translation>
</message>
</context>
</TS>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="tr">
<context>
<name>AskStoriesPage</name>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Yenile</translation>
</message>
<message>
<location filename="../qml/pages/AskStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Daha fazla yükle</translation>
</message>
</context>
<context>
<name>CommentsPage</name>
<message>
......@@ -75,52 +52,6 @@
<translation>Dış akış aç</translation>
</message>
</context>
<context>
<name>JobStoriesPage</name>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Yenile</translation>
</message>
<message>
<location filename="../qml/pages/JobStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Daha fazla yükle</translation>
</message>
</context>
<context>
<name>NewStoriesPage</name>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Yenile</translation>
</message>
<message>
<location filename="../qml/pages/NewStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Daha fazla yükle</translation>
</message>
</context>
<context>
<name>RepliesPage</name>
<message>
......@@ -245,26 +176,26 @@
</message>
</context>
<context>
<name>ShowStoriesPage</name>
<name>StoriesListView</name>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="41"/>
<location filename="../qml/pages/StoriesListView.qml" line="41"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="47"/>
<location filename="../qml/pages/StoriesListView.qml" line="47"/>
<source>Submit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="52"/>
<location filename="../qml/pages/StoriesListView.qml" line="54"/>
<source>Refresh</source>
<translation>Yenile</translation>
<translation type="unfinished">Yenile</translation>
</message>
<message>
<location filename="../qml/pages/ShowStoriesPage.qml" line="60"/>
<location filename="../qml/pages/StoriesListView.qml" line="63"/>
<source>Load more</source>
<translation>Daha fazla yükle</translation>
<translation type="unfinished">Daha fazla yükle</translation>
</message>
</context>
<context>
......@@ -306,27 +237,4 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>TopStoriesPage</name>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="41"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="47"/>
<source>Submit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="52"/>
<source>Refresh</source>
<translation>Yenile</translation>
</message>
<message>
<location filename="../qml/pages/TopStoriesPage.qml" line="60"/>
<source>Load more</source>
<translation>Daha fazla yükle</translation>
</message>
</context>
</TS>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">