on xenial help sign in
Add pull-to-refresh functionality to scopes. Fixes: 1368336

Approved by: Albert Astals Cid

commit017714e07f85fbc044a0331d5e8c1bafa42feecb authorMichael Terry <michael.terry@canonical.com> dateMon 6 Oct 2014, 08:02 (12 years ago) parent0da63cd41a839f
6 files changed+153−4
po/unity8.pot+10−2 qml/Dash/GenericScopeView.qml+36−1 qml/Dash/PullToRefreshScopeStyle.qml+82 tests/mocks/Unity/fake_scope.cpp+1−1 tests/mocks/Unity/fake_scope.h+3 tests/qmltests/Dash/tst_GenericScopeView.qml+21
po/unity8.pot+10−2
@@ -8,7 +8,7 @@ msgid ""
88msgstr ""
99"Project-Id-Version: unity8\n"
1010"Report-Msgid-Bugs-To: \n"
11−"POT-Creation-Date: 2014-10-02 10:35+0200\n"
11+"POT-Creation-Date: 2014-10-03 08:13-0400\n"
1212"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -160,7 +160,7 @@ msgstr ""
160160msgid "OK"
161161msgstr ""
162162
163−#: qml/Dash/GenericScopeView.qml:411 qml/Dash/GenericScopeView.qml:533
163+#: qml/Dash/GenericScopeView.qml:411 qml/Dash/GenericScopeView.qml:568
164164msgid "See less"
165165msgstr ""
166166
@@ -205,6 +205,14 @@ msgstr ""
205205msgid "Send"
206206msgstr ""
207207
208+#: qml/Dash/PullToRefreshScopeStyle.qml:55
209+msgid "Pull to refresh…"
210+msgstr ""
211+
212+#: qml/Dash/PullToRefreshScopeStyle.qml:60
213+msgid "Release to refresh…"
214+msgstr ""
215+
208216#: qml/Dash/ScopesOverview.qml:206
209217msgid "Manage Scopes"
210218msgstr ""
qml/Dash/GenericScopeView.qml+36−1
@@ -15,7 +15,7 @@
1515 */
1616
1717import QtQuick 2.0
18−import Ubuntu.Components 0.1
18+import Ubuntu.Components 1.1
1919import Utils 0.1
2020import Unity 0.2
2121import Dash 0.1
@@ -519,6 +519,41 @@ FocusScope {
519519 }
520520 }
521521
522+ Item {
523+ id: pullToRefreshClippingItem
524+ anchors.left: parent.left
525+ anchors.right: parent.right
526+ anchors.bottom: parent.bottom
527+ height: parent.height - pullToRefresh.contentY + (pageHeaderLoader.item ? pageHeaderLoader.item.bottomItem[0].height - pageHeaderLoader.item.height : 0)
528+ clip: true
529+
530+ PullToRefresh {
531+ id: pullToRefresh
532+ objectName: "pullToRefresh"
533+ target: categoryView
534+
535+ readonly property real contentY: categoryView.contentY - categoryView.originY
536+ y: -contentY - units.gu(5)
537+
538+ onRefresh: {
539+ refreshing = true
540+ scopeView.scope.refresh()
541+ }
542+ anchors.left: parent.left
543+ anchors.right: parent.right
544+
545+ Connections {
546+ target: scopeView
547+ onProcessingChanged: if (!scopeView.processing) pullToRefresh.refreshing = false
548+ }
549+
550+ style: PullToRefreshScopeStyle {
551+ anchors.fill: parent
552+ activationThreshold: units.gu(14)
553+ }
554+ }
555+ }
556+
522557 AbstractButton {
523558 id: floatingSeeLess
524559 objectName: "floatingSeeLess"
qml/Dash/PullToRefreshScopeStyle.qmlnew file+82
@@ -0,0 +1,82 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.3
18+import Ubuntu.Components 1.1
19+import Ubuntu.Components.Styles 1.1
20+
21+/**
22+ * TODO: Once the SDK version of PullToRefreshStyle doesn't have bug 1375799
23+ * (https://launchpad.net/bugs/1375799) anymore, we should switch to using a
24+ * a subclass of the Ambiance version with a hidden ActivityIndicator.
25+ */
26+PullToRefreshStyle {
27+ releaseToRefresh: styledItem.target.originY - styledItem.target.contentY > activationThreshold
28+
29+ Connections {
30+ property bool willRefresh: false
31+
32+ target: styledItem.target
33+ onDraggingChanged: {
34+ if (!styledItem.target.dragging && releaseToRefresh) {
35+ willRefresh = true
36+ }
37+ }
38+ onContentYChanged: {
39+ if (styledItem.target.originY - styledItem.target.contentY == 0 && willRefresh) {
40+ styledItem.refresh()
41+ willRefresh = false
42+ }
43+ }
44+ }
45+
46+ Label {
47+ id: pullLabel
48+ anchors.horizontalCenter: parent.horizontalCenter
49+ horizontalAlignment: Text.AlignHCenter
50+ verticalAlignment: Text.AlignVCenter
51+ states: [
52+ State {
53+ name: "pulling"
54+ when: styledItem.target.dragging && !releaseToRefresh
55+ PropertyChanges { target: pullLabel; text: i18n.tr("Pull to refresh…") }
56+ },
57+ State {
58+ name: "releasable"
59+ when: styledItem.target.dragging && releaseToRefresh
60+ PropertyChanges { target: pullLabel; text: i18n.tr("Release to refresh…") }
61+ }
62+ ]
63+ transitions: Transition {
64+ SequentialAnimation {
65+ UbuntuNumberAnimation {
66+ target: pullLabel
67+ property: "opacity"
68+ to: 0.0
69+ }
70+ PropertyAction {
71+ target: pullLabel
72+ property: "text"
73+ }
74+ UbuntuNumberAnimation {
75+ target: pullLabel
76+ property: "opacity"
77+ to: 1.0
78+ }
79+ }
80+ }
81+ }
82+}
tests/mocks/Unity/fake_scope.cpp+1−1
@@ -266,7 +266,7 @@ QVariantMap Scope::customizations() const
266266
267267void Scope::refresh()
268268{
269− qDebug() << "Scope::refresh is currently not implmented in the fake scopes plugin";
269+ Q_EMIT refreshed();
270270}
271271
272272unity::shell::scopes::NavigationInterface* Scope::getNavigation(const QString& id)
tests/mocks/Unity/fake_scope.h+3
@@ -79,6 +79,9 @@ public:
7979
8080 Q_INVOKABLE void refresh() override;
8181
82+Q_SIGNALS:
83+ void refreshed(); // This is not in the Interface, here for testing benefits
84+
8285protected:
8386
8487 QString m_id;
tests/qmltests/Dash/tst_GenericScopeView.qml+21
@@ -582,6 +582,27 @@ Item {
582582
583583 genericScopeView.scope = !genericScopeView.scope;
584584 }
585+
586+ function test_pullToRefresh() {
587+ waitForRendering(genericScopeView)
588+
589+ mouseFlick(genericScopeView,
590+ genericScopeView.width/2, units.gu(10),
591+ genericScopeView.width/2, units.gu(80),
592+ true, false)
593+
594+ var pullToRefresh = findChild(genericScopeView, "pullToRefresh")
595+ tryCompare(pullToRefresh, "releaseToRefresh", true)
596+
597+ spy.target = genericScopeView.scope
598+ spy.signalName = "refreshed"
599+
600+ mouseRelease(genericScopeView)
601+ tryCompare(pullToRefresh, "releaseToRefresh", false)
602+
603+ spy.wait()
604+ compare(spy.count, 1)
605+ }
585606 }
586607 }
587608}