Merge lp:~nik90/unav/improve-favorite-page into lp:unav

Proposed by Nekhelesh Ramananthan
Status: Merged
Merged at revision: 7
Proposed branch: lp:~nik90/unav/improve-favorite-page
Merge into: lp:unav
Diff against target: 438 lines (+167/-170)
4 files modified
qml/FavoritesPage.qml (+164/-167)
qml/Main.qml (+1/-1)
qml/PoiListPage.qml (+1/-1)
qml/js/utils.js (+1/-1)
To merge this branch: bzr merge lp:~nik90/unav/improve-favorite-page
Reviewer Review Type Date Requested Status
Nekhelesh Ramananthan Needs Information
JkB Needs Fixing
Review via email: mp+290205@code.launchpad.net

Commit message

- Migrated Favorite page to PageHeaders
- Replaced all uses of old listitems with new listitem
- Removed excessive calls of the initialize() function
- Simplified the logic of the empty state component

Description of the change

----------- Merge for uNav 0.58! -----------------

This MP improves the favorite page code wise only. Visuals are unchanged.

To post a comment you must log in.
Revision history for this message
JkB (joergberroth) wrote :

Most alright; one thing

1. The header
Should hide when scrolling.
Right now it is fix, transparent and ListItem is visible underneath.

review: Needs Fixing
Revision history for this message
costales (costales) wrote :

Good improvement!

I would propose this improvement: Sort a new favorite.
https://code.launchpad.net/~costales/unav/improve-favorite-page

A hug :)

Revision history for this message
JkB (joergberroth) wrote :

Hey,

if there is more time for improvements:
A trailing action to edit the favorite name would also be a nice feature

Best Joerg

Am 2016-03-28 um 20:41 schrieb costales:
> Good improvement!
>
> I would propose this improvement: Sort a new favorite.
> https://code.launchpad.net/~costales/unav/improve-favorite-page
>
> A hug :)
>

lp:~nik90/unav/improve-favorite-page updated
14. By Nekhelesh Ramananthan

Scroll header automatically when scrolling listview

15. By Nekhelesh Ramananthan

merged lp:~costales/unav/improve-favorite-page

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

> Most alright; one thing
>
> 1. The header
> Should hide when scrolling.
> Right now it is fix, transparent and ListItem is visible underneath.

Fixed in commit rev 14.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

> Good improvement!
>
> I would propose this improvement: Sort a new favorite.
> https://code.launchpad.net/~costales/unav/improve-favorite-page
>
> A hug :)

Merged in rev 15. Thnx for the code.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

> Hey,
>
> if there is more time for improvements:
> A trailing action to edit the favorite name would also be a nice feature
>
> Best Joerg

Hi Joerg, that would be an excellent addition. I would like to do that in a new MP if you don't mind. But I will implement it :). Thanks for the idea!

Revision history for this message
JkB (joergberroth) wrote :

now, the header actions seem to be gone.

Best Joerg

Am 2016-03-28 um 21:07 schrieb Nekhelesh Ramananthan:
>> Most alright; one thing
>>
>> 1. The header
>> Should hide when scrolling.
>> Right now it is fix, transparent and ListItem is visible underneath.
>
> Fixed in commit rev 14.
>

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

What header actions? I can see the "+" header action and click it to add favorites.

review: Needs Information
Revision history for this message
JkB (joergberroth) wrote :

Am 2016-03-28 um 21:31 schrieb Nekhelesh Ramananthan:
> Review: Needs Information
>
> What header actions? I can see the "+" header action and click it to add favorites.
>
strange, on my install the back and add action do not work anymore. what
are you on? rc-prop or stable?

I will investigate.

Revision history for this message
costales (costales) wrote :

After a few more tests I found this (only on phone):
1. Center pos.
2. Click on Route > Favorites > +
3. Go back. Nothing happen.
4. Click clear field. Nothing happen.
Best regards!

Revision history for this message
JkB (joergberroth) wrote :

exactly same for me, yes.

Am 2016-03-28 um 22:19 schrieb costales:
> After a few more tests I found this (only on phone):
> 1. Center pos.
> 2. Click on Route > Favorites > +
> 3. Go back. Nothing happen.
> 4. Click clear field. Nothing happen.
> Best regards!
>

Revision history for this message
JkB (joergberroth) wrote :

It seems that somethings lays itself over the header.

The
z: 500
property would solve the problem.

(i am on krillin rc-proposed)

Best Joerg

Am 2016-03-28 um 22:27 schrieb JkB:
> exactly same for me, yes.
>
> Am 2016-03-28 um 22:19 schrieb costales:
>> After a few more tests I found this (only on phone):
>> 1. Center pos.
>> 2. Click on Route > Favorites > +
>> 3. Go back. Nothing happen.
>> 4. Click clear field. Nothing happen.
>> Best regards!
>>
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qml/FavoritesPage.qml'
2--- qml/FavoritesPage.qml 2016-03-26 18:53:17 +0000
3+++ qml/FavoritesPage.qml 2016-03-28 19:06:40 +0000
4@@ -16,9 +16,7 @@
5 */
6
7 import QtQuick 2.4
8-import QtQuick.Layouts 1.1
9 import Ubuntu.Components 1.3
10-import Ubuntu.Components.ListItems 1.3 as ListItems
11 import Ubuntu.Components.Popups 1.3
12 import QtQuick.LocalStorage 2.0
13 import "js/utils.js" as QmlJs
14@@ -30,146 +28,92 @@
15 property string lat
16 property string lng
17 property string favName
18-
19- title: i18n.tr("Favorites")
20+ property bool isAddedFromPopup: false
21+
22+ Component.onCompleted: {
23+ if (isAddedFromPopup) {
24+ addPOIFromPopup()
25+ }
26+ }
27+
28+ header: standardHeader
29 anchors.fill: parent
30
31- state: "default"
32- states: [
33- PageHeadState {
34- name: "default"
35- head: favoritesPage.head
36-
37- backAction: Action {
38- iconName: "back"
39- text: i18n.tr("Back")
40- onTriggered: {
41- mainPageStack.pop(favoritesPage)
42- mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"))
43- }
44- }
45- actions: Action {
46- iconName: "add"
47- text: i18n.tr("Add Favorite")
48- onTriggered: {
49- addActionList.show();
50- }
51- }
52- },
53-
54- PageHeadState {
55- name: "adding"
56- head: favoritesPage.head
57-
58- Component.onCompleted: favNameField.forceActiveFocus();
59-
60- backAction: Action {
61- iconName: "back"
62- text: i18n.tr("Back")
63- onTriggered: {
64- mainPageStack.pop(favoritesPage)
65- mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"))
66- }
67- }
68-
69- contents: TextField {
70- id: favNameField
71- anchors {
72- rightMargin: units.gu(2)
73- }
74- width: parent ? parent.width - units.gu(2) : undefined
75-
76- inputMethodHints: Qt.ImhNoPredictiveText
77- hasClearButton: true
78- placeholderText: i18n.tr("Insert a favorite name")
79- text: (favoritesPage.favName !== "" && favoritesPage.favName !== i18n.tr("Current Position")) ? favoritesPage.favName : ""
80- onTriggered: {
81- if (text.length > 0 && favNameField.text !== "") {
82- var exist_fav = UnavDB.getFavorite(favNameField.text);
83- if (exist_fav[0] === null || exist_fav[1] === null) {
84- UnavDB.saveFavorite(favNameField.text, favoritesPage.lat, favoritesPage.lng);
85- favoritesModel.initialize();
86- favoritesPage.state = "default";
87- }
88- else {
89- PopupUtils.open(confirmOverwrite)
90- }
91+ function addPOIFromPopup() {
92+ if (favoritesPage.favName) {
93+ var exist_fav = UnavDB.getFavorite(favoritesPage.favName);
94+ if (exist_fav[0] === null || exist_fav[1] === null) {
95+ UnavDB.saveFavorite(favoritesPage.favName, favoritesPage.lat, favoritesPage.lng)
96+ favoritesModel.initialize()
97+ }
98+ else {
99+ header = addHeader
100+ favNameField.text = favoritesPage.favName
101+ PopupUtils.open(confirmOverwrite);
102+ }
103+ }
104+ favoritesPage.isAddedFromPopup = false
105+ }
106+
107+ PageHeader {
108+ id: standardHeader
109+ title: i18n.tr("Favorites")
110+ visible: header === standardHeader
111+ flickable: favoritesListView
112+ leadingActionBar.actions: Action {
113+ iconName: "back"
114+ text: i18n.tr("Back")
115+ shortcut: "Escape"
116+ enabled: header === standardHeader
117+ onTriggered: {
118+ mainPageStack.pop(favoritesPage)
119+ mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"))
120+ }
121+ }
122+ trailingActionBar.actions: Action {
123+ id: actionButton
124+ iconName: "add"
125+ shortcut: "Ctrl+N"
126+ text: i18n.tr("Add Favorite")
127+ onTriggered: {
128+ addActionList.show()
129+ }
130+ }
131+ }
132+
133+ PageHeader {
134+ id: addHeader
135+ visible: header === addHeader
136+ flickable: favoritesListView
137+ leadingActionBar.actions:Action {
138+ iconName: "back"
139+ text: i18n.tr("Back")
140+ shortcut: "Escape"
141+ enabled: header === addHeader
142+ onTriggered: {
143+ header = standardHeader
144+ favNameField.text = ""
145+ }
146+ }
147+ contents: TextField {
148+ id: favNameField
149+ width: parent.width
150+ anchors.verticalCenter: parent.verticalCenter
151+ inputMethodHints: Qt.ImhNoPredictiveText
152+ hasClearButton: true
153+ placeholderText: i18n.tr("Insert a favorite name")
154+ text: (favoritesPage.favName !== "" && favoritesPage.favName !== i18n.tr("Current Position")) ? favoritesPage.favName : ""
155+ onTriggered: {
156+ if (text.length > 0 && favNameField.text !== "") {
157+ var exist_fav = UnavDB.getFavorite(favNameField.text);
158+ if (exist_fav[0] === null || exist_fav[1] === null) {
159+ UnavDB.saveFavorite(favNameField.text, favoritesPage.lat, favoritesPage.lng)
160+ favoritesModel.initialize()
161+ favoritesPage.header = standardHeader
162 } else {
163- favNameField.text = "";
164- }
165- }
166- }
167- },
168-
169- PageHeadState {
170- name: "addingFromPopup"
171- head: favoritesPage.head
172-
173- Component.onCompleted: {
174- if (favoritesPage.favName) {
175- var exist_fav = UnavDB.getFavorite(favoritesPage.favName);
176- if (exist_fav[0] === null || exist_fav[1] === null) {
177- UnavDB.saveFavorite(favoritesPage.favName, favoritesPage.lat, favoritesPage.lng);
178- favoritesModel.initialize();
179- favoritesPage.state = "default";
180- }
181- else {
182- favNameField.text = favoritesPage.favName;
183- PopupUtils.open(confirmOverwrite);
184- }
185- }
186- }
187-
188- backAction: Action {
189- iconName: "back"
190- text: i18n.tr("Back")
191- onTriggered: {
192- mainPageStack.pop(favoritesPage);
193- }
194- }
195- }
196- ]
197-
198- ActionSelectionPopover {
199- id: addActionList
200- z: 100
201- width: units.gu(25)
202- anchors {
203- top: parent.top
204- right: parent.right
205- topMargin: units.gu (7.5)
206- }
207-
208- delegate: ListItems.Standard {
209- text: action.text
210- }
211- actions: ActionList {
212- Action {
213- text: i18n.tr("Add Current Position")
214- enabled: (mainPageStack.center_onpos !== 0 && mainPageStack.currentLat !== "null" && mainPageStack.currentLng !== "null")
215- onTriggered: {
216- favoritesPage.lat = mainPageStack.currentLat;
217- favoritesPage.lng = mainPageStack.currentLng;
218- favoritesPage.state = "adding";
219- addActionList.hide();
220- favNameField.forceActiveFocus();
221- }
222- }
223- Action {
224- text: i18n.tr("Add Current Destination")
225- enabled: (mainPageStack.routeState !== 'no')
226- onTriggered: {
227- favoritesPage.lat = mainPageStack.endLat;
228- favoritesPage.lng = mainPageStack.endLng;
229- favoritesPage.state = "adding";
230- addActionList.hide();
231- favNameField.forceActiveFocus();
232- }
233-
234- }
235- Action {
236- text: i18n.tr("Add From Map")
237- onTriggered: mainPageStack.pop(favoritesPage);
238+ PopupUtils.open(confirmOverwrite)
239+ }
240+ }
241 }
242 }
243 }
244@@ -177,9 +121,7 @@
245 Label {
246 id: statusLabel
247 anchors.centerIn: parent
248- anchors.horizontalCenter: parent.horizontalCenter
249- anchors.verticalCenter: parent.verticalCenter
250- visible: false
251+ visible: favoritesModel.count === 0
252 text: i18n.tr("No favorites yet")
253 }
254
255@@ -189,16 +131,11 @@
256 function initialize() {
257 favoritesModel.clear();
258 var res = UnavDB.getFavorites();
259- var len = res.rows.length;
260- if (len === 0) {
261- statusLabel.visible = true;
262- } else {
263- statusLabel.visible = false;
264- for (var i = 0; i < len; ++i) {
265- favoritesModel.append({ name: res.rows.item(i).key,
266- lat: res.rows.item(i).lat,
267- lng: res.rows.item(i).lng });
268- }
269+ for (var i = 0; i < res.rows.length; ++i) {
270+ favoritesModel.append({ name: res.rows.item(i).key,
271+ lat: res.rows.item(i).lat,
272+ lng: res.rows.item(i).lng
273+ });
274 }
275 }
276 }
277@@ -208,6 +145,7 @@
278
279 model: favoritesModel
280 anchors.fill: parent
281+ interactive: contentHeight > height
282
283 delegate: ListItem {
284 id: delegate
285@@ -219,13 +157,13 @@
286 iconName: "delete"
287 onTriggered: {
288 UnavDB.removeFavorite(model.name);
289- favoritesModel.initialize();
290+ favoritesModel.remove(index, 1)
291 }
292 }
293 ]
294 }
295
296- trailingActions: ListItemActions {
297+ trailingActions: ListItemActions {
298 actions: [
299 Action {
300 iconName: "send"
301@@ -262,26 +200,85 @@
302 }
303 }
304
305+ ActionSelectionPopover {
306+ id: addActionList
307+
308+ width: units.gu(25)
309+ anchors {
310+ top: parent.top
311+ right: parent.right
312+ rightMargin: units.gu(0.5)
313+ topMargin: favoritesPage.header.height
314+ }
315+
316+ delegate: ListItem {
317+ Label {
318+ text: action.text
319+ elide: Text.ElideMiddle
320+ opacity: action.enabled ? 1.0 : 0.5
321+ anchors { left: parent.left; right: parent.right; margins: units.gu(2); verticalCenter: parent.verticalCenter }
322+ }
323+ }
324+
325+ actions: ActionList {
326+ Action {
327+ text: i18n.tr("Add Current Position")
328+ enabled: (mainPageStack.center_onpos !== 0 && mainPageStack.currentLat !== "null" && mainPageStack.currentLng !== "null")
329+ onTriggered: {
330+ favoritesPage.lat = mainPageStack.currentLat;
331+ favoritesPage.lng = mainPageStack.currentLng;
332+ favoritesPage.header = addHeader
333+ addActionList.hide();
334+ favNameField.forceActiveFocus();
335+ }
336+ }
337+ Action {
338+ text: i18n.tr("Add Current Destination")
339+ enabled: (mainPageStack.routeState !== 'no')
340+ onTriggered: {
341+ favoritesPage.lat = mainPageStack.endLat;
342+ favoritesPage.lng = mainPageStack.endLng;
343+ favoritesPage.header = addHeader
344+ addActionList.hide();
345+ favNameField.forceActiveFocus();
346+ }
347+
348+ }
349+ Action {
350+ text: i18n.tr("Add From Map")
351+ onTriggered: mainPageStack.pop(favoritesPage);
352+ }
353+ }
354+ }
355+
356+
357 Component {
358 id: confirmOverwrite
359 Dialog {
360 id: dialogue
361 title: i18n.tr("Overwrite Favorite")
362- text: i18n.tr("There is a favorite with that name")
363- Button {
364- text: i18n.tr("Overwrite")
365- color: UbuntuColors.red
366- onClicked: {
367- UnavDB.saveFavorite(favNameField.text, favoritesPage.lat, favoritesPage.lng);
368- favoritesModel.initialize();
369- favoritesPage.state = "default";
370- PopupUtils.close(dialogue);
371+ text: i18n.tr("There is already a favorite with that name. Do you want to overwrite it?")
372+ Column {
373+ width: parent.width
374+ Row {
375+ anchors.horizontalCenter: parent.horizontalCenter
376+ spacing: units.gu(2)
377+ Button {
378+ text: i18n.tr("Overwrite")
379+ color: UbuntuColors.red
380+ onClicked: {
381+ UnavDB.saveFavorite(favNameField.text, favoritesPage.lat, favoritesPage.lng);
382+ favoritesModel.initialize()
383+ favoritesPage.header = standardHeader
384+ PopupUtils.close(dialogue)
385+ }
386+ }
387+ Button {
388+ text: i18n.tr("Cancel")
389+ onClicked: PopupUtils.close(dialogue)
390+ }
391 }
392 }
393- Button {
394- text: i18n.tr("Cancel")
395- onClicked: PopupUtils.close(dialogue);
396- }
397 }
398 }
399 }
400
401=== modified file 'qml/Main.qml'
402--- qml/Main.qml 2016-03-28 17:31:47 +0000
403+++ qml/Main.qml 2016-03-28 19:06:40 +0000
404@@ -643,7 +643,7 @@
405 onTriggered: {
406 if (text.length > 0) {
407 goThereActionPopover.hide();
408- mainPageStack.push(Qt.resolvedUrl("FavoritesPage.qml"), {state: "addingFromPopup", lat: mainPageStack.clickedLat, lng: mainPageStack.clickedLng, favName: favNamePopup.text});
409+ mainPageStack.push(Qt.resolvedUrl("FavoritesPage.qml"), {isAddedFromPopup: true, lat: mainPageStack.clickedLat, lng: mainPageStack.clickedLng, favName: favNamePopup.text});
410 }
411 }
412 }
413
414=== modified file 'qml/PoiListPage.qml'
415--- qml/PoiListPage.qml 2016-03-26 21:16:49 +0000
416+++ qml/PoiListPage.qml 2016-03-28 19:06:40 +0000
417@@ -271,7 +271,7 @@
418 onTriggered: {
419 mainPageStack.pop(poiListPage.fromPage)
420 mainPageStack.pop(poiListPage)
421- mainPageStack.push(Qt.resolvedUrl("FavoritesPage.qml"), {state:"adding", lat: model.lat, lng: model.lng, favName: model.name})
422+ mainPageStack.push(Qt.resolvedUrl("FavoritesPage.qml"), {isAddedFromPopup: true, lat: model.lat, lng: model.lng, favName: model.name})
423 }
424 },
425 Action {
426
427=== modified file 'qml/js/utils.js'
428--- qml/js/utils.js 2016-03-26 18:53:17 +0000
429+++ qml/js/utils.js 2016-03-28 19:06:40 +0000
430@@ -49,7 +49,7 @@
431 var distance = dist < 1000 ? parseInt(dist) + " m" : parseInt(dist * m2km) + "+ km" ;
432
433 if (distance === '0 m' || distance === '0 yd')
434- return '';
435+ return i18n.tr("Current Location");
436 else
437 return distance;
438 }

Subscribers

People subscribed via source and target branches