summaryrefslogtreecommitdiff
path: root/rockwork/qml/AppStorePage.qml
blob: 7e006dac9ae71e314ca66bff46ea698e33f167da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import QtQuick 2.0
import QtQml 2.1
import Sailfish.Silica 1.0
import RockPool 1.0

Page {
    id: root

    property var pebble: null
    property bool showWatchApps: false
    property bool showWatchFaces: false

    property string link: ""

    function fetchHome() {
        if (showWatchApps) {
            client.fetchHome(AppStoreClient.TypeWatchapp)
        } else {
            client.fetchHome(AppStoreClient.TypeWatchface)
        }
    }
    SilicaFlickable {
        id: flickable
        anchors.top: parent.top
        width: parent.width
        PageHeader {
            title: showWatchApps ? qsTr("Add new watchapp") : qsTr("Add new watchface")
        }
        PullDownMenu {
                MenuItem {
                    text: qsTr("Show search")
                    onClicked: {
                        if (searchField.shown) {
                            searchField.shown = false;
                            root.fetchHome();
                        } else {
                            searchField.shown = true;
                        }
                    }
                }
        }

        Component.onCompleted: {
            if (root.link) {
                client.fetchLink(link)
            } else {
                root.fetchHome()
            }
        }

        AppStoreClient {
            id: client
            hardwarePlatform: pebble.hardwarePlatform
        }

        Item {
            id: searchField
            anchors { left: parent.left; right: parent.right; top: parent.top }
            anchors.topMargin: shown ? 0 : -height
            Behavior on anchors.topMargin { NumberAnimation {} }
            opacity: shown ? 1 : 0
            Behavior on opacity { NumberAnimation {} }
            height: units.gu(6)

            property bool shown: false
            onShownChanged: {
                if (shown) {
                    searchTextField.focus = true;
                }
            }

            SearchField {
                id: searchTextField
                anchors.centerIn: parent
                width: parent.width - units.gu(2)
                onDisplayTextChanged: {
                    searchTimer.restart()
                }

                Timer {
                    id: searchTimer
                    interval: 300
                    onTriggered: {
                        client.search(searchTextField.displayText, root.showWatchApps ? AppStoreClient.TypeWatchapp : AppStoreClient.TypeWatchface);
                    }
                }
            }
        }

        Item {
            anchors { left: parent.left; top: searchField.bottom; right: parent.right; bottom: parent.bottom }
            ListView {
                anchors.fill: parent
                model: ApplicationsFilterModel {
                    id: appsFilterModel
                    model: client.model
                }
                clip: true
                section.property: "groupId"
                section.labelPositioning: ViewSection.CurrentLabelAtStart |
                                          ViewSection.InlineLabels
                section.delegate: ListItem {
                    height: section ? label.implicitHeight + units.gu(3) : 0

                    Rectangle {
                        anchors.fill: parent
                        color: "white"
                    }

                    Row {
                        anchors.fill: parent
                        anchors.margins: units.gu(1)
                        Label {
                            id: label
                            text: client.model.groupName(section)
                            font.pixelSize: Theme.fontSizeLarge
    //                        font.weight: Font.DemiBold
                            elide: Text.ElideRight
                            width: parent.width
                        }
                        Button {
                            implicitWidth: seeAllLabel.implicitWidth + height
                            Row {
                                anchors.verticalCenter: parent.verticalCenter
                                Label {
                                    id: seeAllLabel
                                    text: qsTr("See all")
                                }
                                IconButton {
                                    implicitHeight: parent.height
                                    implicitWidth: height
                                    icon.source: "image://theme/icon-m-forward"
                                }
                            }
                            onClicked: {
                                pageStack.push(Qt.resolvedUrl("AppStorePage.qml"), {pebble: root.pebble, link: client.model.groupLink(section), title: client.model.groupName(section)});
                            }
                        }
                    }
                }

                footer: Item {
                    height: client.model.links.length > 0 ? units.gu(6) : 0
                    width: parent.width

                    Row {
                        anchors {
                            fill: parent
                            margins: units.gu(1)
                        }
                        spacing: units.gu(1)

                        Repeater {
                            model: client.model.links
                            Button {
                                text: client.model.linkName(client.model.links[index])
                                onClicked: client.fetchLink(client.model.links[index]);
                                color: UbuntuColors.orange
                                width: parent.width
                            }
                        }
                    }
                }

                delegate: ListItem {
                    height: delegateColumn.height + units.gu(2)

                    Row {
                        id: delegateRow
                        anchors.fill: parent
                        anchors.margins: units.gu(1)
                        spacing: units.gu(1)

                        AnimatedImage {
                            source: model.icon
                            asynchronous: true
    //                        sourceSize.width: width
    //                        sourceSize.height: height
                        }

                        Column {
                            id: delegateColumn
                            width: parent.width
                            //Layout.fillHeight: true;
                            Label {
                                width: parent.width
                                text: model.name
                                font.weight: Font.DemiBold
                                elide: Text.ElideRight
                            }
                            Label {
                                width: parent.width
                                text: model.category
                            }
                            Row {
                                IconButton {
                                    icon.source: "image://theme/icon-m-back"
                                    id: like
                                    //Layout.preferredHeight: parent.height
                                    //Layout.preferredWidth: height
                                    implicitHeight: parent.height
                                }
                                Label {
                                    width: parent.width
                                    text: model.hearts
                                }
                                IconButton {
                                    id: tickIcon
                                    icon.source: "image://theme/icon-m-acknowledge"
                                    implicitHeight: parent.height
                                    //Layout.preferredWidth: height
                                    visible: root.pebble.installedApps.contains(model.storeId) || root.pebble.installedWatchfaces.contains(model.storeId)
                                    Connections {
                                        target: root.pebble.installedApps
                                        onTargetChanged: {
                                            tickIcon.visible = root.pebble.installedApps.contains(model.storeId) || root.pebble.installedWatchfaces.contains(model.storeId)
                                        }
                                    }

                                    Connections {
                                        target: root.pebble.installedWatchfaces
                                        onTargetChanged: {
                                            tickIcon.visible = root.pebble.installedApps.contains(model.storeId) || root.pebble.installedWatchfaces.contains(model.storeId)
                                        }
                                    }

                                }
                            }
                        }

                    }

                    onClicked: {
                        client.fetchAppDetails(model.storeId);
                        pageStack.push(Qt.resolvedUrl("AppStoreDetailsPage.qml"), {app: appsFilterModel.get(index), pebble: root.pebble})
                    }
                }
            }

    //        RowLayout {
    //            id: buttonRow
    //            anchors { left: parent.left; bottom: parent.bottom; right: parent.right; margins: units.gu(1) }
    //            spacing: units.gu(1)
    //            Button {
    //                text: qsTr("Previous")
    //                Layout.fillWidth: true
    //                enabled: client.offset > 0
    //                onClicked: {
    //                    client.previous()
    //                }
    //            }
    //            Button {
    //                text: qsTr("Next")
    //                Layout.fillWidth: true
    //                onClicked: {
    //                    client.next()
    //                }
    //            }
    //        }
        }

        BusyIndicator {
            anchors.centerIn: parent
            running: client.busy
        }
    }
}