Merge lp:~renatofilho/address-book-service/demo-app-with-fetch-hint into lp:~phablet-team/address-book-service/contact-demo-app

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Renato Araujo Oliveira Filho
Approved revision: 17
Merged at revision: 9
Proposed branch: lp:~renatofilho/address-book-service/demo-app-with-fetch-hint
Merge into: lp:~phablet-team/address-book-service/contact-demo-app
Prerequisite: lp:~renatofilho/address-book-service/fetch-hint
Diff against target: 347 lines (+200/-35)
4 files modified
ContactEditor.qml (+7/-8)
ContactList.js (+35/-0)
ContactList.qml (+157/-27)
debian/contacts-demo-app.install (+1/-0)
To merge this branch: bzr merge lp:~renatofilho/address-book-service/demo-app-with-fetch-hint
Reviewer Review Type Date Requested Status
Bill Filler (community) Approve
Review via email: mp+171630@code.launchpad.net

Commit message

Used fetcHint on contact model to fetch only contact name and phone.

To post a comment you must log in.
Revision history for this message
Bill Filler (bfiller) wrote :

not working right.
- I can't select an item from the list
- double clicking only sometimes works and only ever shows the first contact in the list as that's the one that is selected
- we shouldn't use double click to get into edit mode, single click should do that like in the past
- in fact, single click should just take you into view of contact detail mode. Editing is then done from there not from the main screen.

review: Needs Fixing
16. By Renato Araujo Oliveira Filho

Merged "lp:~renatofilho/address-book-service/demo-app-with-section"

17. By Renato Araujo Oliveira Filho

Fixed contact edit action

Revision history for this message
Bill Filler (bfiller) wrote :

approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ContactEditor.qml'
--- ContactEditor.qml 2013-06-23 00:19:40 +0000
+++ ContactEditor.qml 2013-06-27 17:17:26 +0000
@@ -73,14 +73,13 @@
73 }73 }
74 ListItem.ThinDivider {}74 ListItem.ThinDivider {}
75 }75 }
76 76
77 function setContactDetails(contact) {77 function setContactDetails(contact) {
78 contact.name.firstName = contactFirstName.text78 contact.name.firstName = contactFirstName.text
79 contact.name.middleName = contactMiddleName.text79 contact.name.middleName = contactMiddleName.text
80 contact.name.lastName = contactLastName.text80 contact.name.lastName = contactLastName.text
81 contact.email.emailAddress = contactEmail.text81 contact.email.emailAddress = contactEmail.text
82 contact.phoneNumber.number = contactPhone.text82 contact.phoneNumber.number = contactPhone.text
83 console.debug("Update contact number:" + contactPhone.text)
84 }83 }
8584
86 function updateContact() {85 function updateContact() {
@@ -90,14 +89,14 @@
90 newContact.save()89 newContact.save()
91 contactEditor.model.saveContact(newContact)90 contactEditor.model.saveContact(newContact)
9291
93 } else if ((contactFirstName.text != contactEditor.contact.name.firstName) ||92 } else if ((contactFirstName.text !== contactEditor.contact.name.firstName) ||
94 (contactMiddleName.text != contactEditor.contact.name.middleName) ||93 (contactMiddleName.text !== contactEditor.contact.name.middleName) ||
95 (contactLastName.text != contactEditor.contact.name.lastName) ||94 (contactLastName.text !== contactEditor.contact.name.lastName) ||
96 (contactEmail.text != contactEditor.contact.email.emailAddress) ||95 (contactEmail.text !== contactEditor.contact.email.emailAddress) ||
97 (contactPhone.text != contactEditor.contact.phoneNumber.number)) {96 (contactPhone.text !== contactEditor.contact.phoneNumber.number)) {
98 // update existing contact97 // update existing contact
99 setContactDetails(contactEditor.contact)98 setContactDetails(contactEditor.contact)
100 contactEditor.contact.save()99 contact.save()
101 }100 }
102 }101 }
103102
104103
=== added file 'ContactList.js'
--- ContactList.js 1970-01-01 00:00:00 +0000
+++ ContactList.js 2013-06-27 17:17:26 +0000
@@ -0,0 +1,35 @@
1/****************************************************************************
2**
3** Copyright (C) 2013 Canonical Ltd
4**
5****************************************************************************/
6
7var sectionData = [];
8var _sections = [];
9
10function initSectionData(list) {
11 if (!list || !list.model) {
12 return;
13 }
14
15 sectionData = [];
16 _sections = [];
17
18 var current = "",
19 prop = list.section.property,
20 item;
21
22 for (var i = 0, count = list.model.contacts.length; i < count; i++) {
23 item = list.sectionValueForContact(list.model.contacts[i])
24 if (item !== current) {
25 current = item;
26 _sections.push(current);
27 sectionData.push({ index: i, header: current });
28 }
29 }
30}
31
32function getIndexFor(sectionName) {
33 var val = sectionData[_sections.indexOf(sectionName)].index;
34 return val === 0 || val > 0 ? val : -1;
35}
036
=== modified file 'ContactList.qml'
--- ContactList.qml 2013-06-23 00:19:40 +0000
+++ ContactList.qml 2013-06-27 17:17:26 +0000
@@ -8,6 +8,8 @@
8import Ubuntu.Components 0.18import Ubuntu.Components 0.1
9import Ubuntu.Components.ListItems 0.1 as ListItem9import Ubuntu.Components.ListItems 0.1 as ListItem
1010
11import "ContactList.js" as Sections
12
11Page {13Page {
12 id: mainPage14 id: mainPage
1315
@@ -32,6 +34,13 @@
32 direction: Qt.AscendingOrder34 direction: Qt.AscendingOrder
33 }35 }
34 ]36 ]
37
38 fetchHint: FetchHint {
39 detailTypesHint: [ContactDetail.Avatar,
40 ContactDetail.Name,
41 ContactDetail.PhoneNumber]
42 }
43
35 Component.onCompleted: {44 Component.onCompleted: {
36 if (manager == "memory")45 if (manager == "memory")
37 contactsModel.importContacts(Qt.resolvedUrl("example.vcf"))46 contactsModel.importContacts(Qt.resolvedUrl("example.vcf"))
@@ -41,9 +50,7 @@
41 var fullValue = ""50 var fullValue = ""
4251
43 if (contact) {52 if (contact) {
44 console.debug("FieldNames:" + fieldNames)
45 var fieldNameList = fieldNames.split(",")53 var fieldNameList = fieldNames.split(",")
46 console.debug("FieldNameList:" + fieldNameList)
47 for (var fieldNameIndex in fieldNameList) {54 for (var fieldNameIndex in fieldNameList) {
48 var fieldName = fieldNameList[fieldNameIndex]55 var fieldName = fieldNameList[fieldNameIndex]
49 var value = "";56 var value = "";
@@ -73,52 +80,137 @@
73 }80 }
74 }81 }
7582
7683 ListView {
7784 id: alphabetView
78 ListView {85
79 id: listView86 property string selectedLetter: contactListView.contentY > 0 ? contactListView.itemAt(0, contactListView.contentY).sectionName : "A"
87
88 anchors {
89 top: parent.top
90 left: parent.left
91 right: parent.right
92 }
93 focus: true
94 height: units.gu(4)
95 orientation: ListView.Horizontal
96
97 model: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ]
98 delegate: Label {
99 text: modelData
100 font.bold: alphabetView.selectedLetter == text
101 horizontalAlignment: Text.AlignHCenter
102 fontSize: "large"
103 width: units.gu(3)
104
105 MouseArea {
106 anchors.fill: parent
107 onClicked: {
108 contactListView.scroolToSection(modelData)
109 }
110 }
111
112 }
113 }
114
115 ListView {
116 id: contactListView
80117
81 property string title118 property string title
82119
83 anchors.fill: parent120 clip: true
121 snapMode: ListView.NoSnap
122 section {
123 property: "contact.name.firstName"
124 criteria: ViewSection.FirstCharacter
125 delegate: ListItem.Header {
126 id: listHeader
127 //text: section
128 visible: false
129 height: 0
130 }
131 }
132
133 anchors {
134 top: alphabetView.bottom
135 left: parent.left
136 right: parent.right
137 bottom: parent.bottom
138 }
84 model: contactsModel139 model: contactsModel
85 header: ListItem.Header {140 header: ListItem.Header {
86 id: listHeader141 text: contactListView.title
87
88 text: listView.title
89 }142 }
90143
91 onCountChanged: {144 onCountChanged: {
145 dirtyTimer.restart()
92 if (mainPage.startTime) {146 if (mainPage.startTime) {
93 var currentTime = new Date();147 var currentTime = new Date();
94 var elapsed = currentTime.getTime() - mainPage.startTime.getTime()148 var elapsed = currentTime.getTime() - mainPage.startTime.getTime()
95 listView.title = "Elapsed time to load " + count + " contacts: " + (elapsed/1000) + " secs"149 contactListView.title = "Elapsed time to load " + count + " contacts: " + (elapsed/1000) + " secs"
96 }150 }
97 }151 }
98152
99 delegate: ListItem.Subtitled {153 delegate: ListItem.Subtitled {
100 property variant contactObject: contact154 property variant contactObject: contact
101 property string contactId: contact.contactId155 property string contactId: contact.contactId
156 property string sectionName: ListView.section
102157
103 icon: Qt.resolvedUrl("avatar.png")158 icon: contact && contact.avatar && (contact.avatar.imageUrl != "") ? Qt.resolvedUrl(contact.avatar.imageUrl) : Qt.resolvedUrl("avatar.png")
104 text: contactsModel.titleField ? contactsModel.getContactDetails(contact, contactsModel.titleField) : ""159 text: contactsModel.titleField ? contactsModel.getContactDetails(contact, contactsModel.titleField) : ""
105 subText: contactsModel.subTitleField ? contactsModel.getContactDetails(contact, contactsModel.subTitleField) : ""160 subText: contactsModel.subTitleField ? contactsModel.getContactDetails(contact, contactsModel.subTitleField) : ""
106 selected: listView.currentIndex === index161 selected: contactListView.currentIndex === index
107162
108 onClicked: {163 MouseArea {
109 listView.currentIndex = index164 anchors.fill: parent
110 pageStack.push(Qt.resolvedUrl("ContactEditor.qml"), {model: contactsModel, contact: listView.currentItem.contactObject})165 onClicked: {
111 }166 contactListView.currentIndex = index
167 }
168 onDoubleClicked: {
169 editContactPriv.contactId = contactListView.currentItem.contactObject.contactId
170 }
171 }
172 }
173
174 UbuntuNumberAnimation { id: scroolToSectionAnimation; target: contactListView; property: "contentY"; }
175 function scroolToSection(targetSection) {
176 scroolToSectionAnimation.from = contactListView.contentY
177 contactListView.positionViewAtIndex(Sections.getIndexFor(targetSection), ListView.Beginning)
178 scroolToSectionAnimation.to = contactListView.contentY
179 scroolToSectionAnimation.running = true
180 }
181
182 // function used to build the section cache by "ContactList.js"
183 function sectionValueForContact(contact) {
184 if (contact) {
185 return contact.name && contact.name.firstName ? contact.name.firstName[0] : ""
186 } else {
187 return null
188 }
189 }
190 }
191
192 Timer {
193 id: dirtyTimer
194
195 interval: 2000
196 running: false
197 repeat: false
198 onTriggered: {
199 Sections.initSectionData(contactListView)
112 }200 }
113 }201 }
114202
115 ActivityIndicator {203 ActivityIndicator {
116 running: listView.count == 0204 id: busyIndicator
205
206 property bool pageIsBusy: false
207
208 running: contactListView.count == 0 || pageIsBusy
117 visible: running209 visible: running
118 anchors.centerIn: listView210 anchors.centerIn: contactListView
119 }211 }
120212
121 tools: ToolbarItems {213 tools: ToolbarActions {
122 Action {214 Action {
123 text: i18n.tr("Settings")215 text: i18n.tr("Settings")
124 iconSource: Qt.resolvedUrl("settings.png")216 iconSource: Qt.resolvedUrl("settings.png")
@@ -128,7 +220,9 @@
128 Action {220 Action {
129 text: i18n.tr("Edit")221 text: i18n.tr("Edit")
130 iconSource: Qt.resolvedUrl("edit.png")222 iconSource: Qt.resolvedUrl("edit.png")
131 onTriggered: pageStack.push(Qt.resolvedUrl("ContactEditor.qml"), {model: contactsModel, contact: listView.currentItem.contactObject})223 onTriggered: {
224 editContactPriv.contactId = contactListView.currentItem.contactObject.contactId
225 }
132 }226 }
133 Action {227 Action {
134 text: i18n.tr("New")228 text: i18n.tr("New")
@@ -139,9 +233,45 @@
139 text: i18n.tr("Delete")233 text: i18n.tr("Delete")
140 iconSource: Qt.resolvedUrl("delete.png")234 iconSource: Qt.resolvedUrl("delete.png")
141 onTriggered: {235 onTriggered: {
142 console.debug("Delete: " + listView.currentItem.contactId)236 contactsModel.removeContact(contactListView.currentItem.contactId);
143 contactsModel.removeContact(listView.currentItem.contactId);237 }
144 }238 }
145 }239 }
146 }240
241 Item {
242 id: editContactPriv
243
244 property string contactId
245 property int currentQueryId: -1
246
247 visible: false
248 Connections {
249 target: contactsModel
250 onContactsFetched: {
251 if (requestId == editContactPriv.currentQueryId) {
252 editContactPriv.currentQueryId = -1
253 busyIndicator.pageIsBusy = false
254 pageStack.push(Qt.resolvedUrl("ContactEditor.qml"),
255 {model: contactsModel, contact: fetchedContacts[0]})
256 }
257 }
258 }
259
260 onContactIdChanged: {
261 if (!contactId || (currentQueryId != -1)) {
262 return
263 }
264
265 busyIndicator.pageIsBusy = true
266
267 currentQueryId = contactsModel.fetchContacts([contactId])
268 if (currentQueryId == -1) {
269 busyIndicator.pageIsBusy = false
270 }
271 }
272
273
274 }
275
276
147}277}
148278
=== modified file 'debian/contacts-demo-app.install'
--- debian/contacts-demo-app.install 2013-06-07 19:19:01 +0000
+++ debian/contacts-demo-app.install 2013-06-27 17:17:26 +0000
@@ -1,5 +1,6 @@
1contacts-demo-app usr/bin/1contacts-demo-app usr/bin/
2contacts-demo-app.desktop usr/share/applications/2contacts-demo-app.desktop usr/share/applications/
3*.qml usr/share/contacts-demo-app/3*.qml usr/share/contacts-demo-app/
4*.js usr/share/contacts-demo-app/
4*.png usr/share/contacts-demo-app/5*.png usr/share/contacts-demo-app/
5*.vcf usr/share/contacts-demo-app/6*.vcf usr/share/contacts-demo-app/

Subscribers

People subscribed via source and target branches