cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [10/12] wp7 commit: fixes Contacts Api tests
Date Wed, 31 Oct 2012 23:34:18 GMT
fixes Contacts Api tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/997d7cb2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/997d7cb2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/997d7cb2

Branch: refs/heads/master
Commit: 997d7cb2ccc3d42d727fbf520cf3c75008a2e795
Parents: 5da07d6
Author: sgrebnov <sergei.grebnov@gmail.com>
Authored: Tue Oct 16 01:04:11 2012 +0400
Committer: sgrebnov <sergei.grebnov@gmail.com>
Committed: Tue Oct 16 01:04:11 2012 +0400

----------------------------------------------------------------------
 .../standalone/cordovalib/Commands/Contacts.cs     |   80 +++++++-------
 1 files changed, 40 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/997d7cb2/templates/standalone/cordovalib/Commands/Contacts.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/Contacts.cs b/templates/standalone/cordovalib/Commands/Contacts.cs
index 8428ea5..f299fe0 100644
--- a/templates/standalone/cordovalib/Commands/Contacts.cs
+++ b/templates/standalone/cordovalib/Commands/Contacts.cs
@@ -12,24 +12,16 @@
 	limitations under the License.
 */
 
-using System;
-using System.Net;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Documents;
-using System.Windows.Ink;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Animation;
-using System.Windows.Shapes;
 using Microsoft.Phone.Tasks;
 using Microsoft.Phone.UserData;
+using System;
 using System.Collections;
 using System.Collections.Generic;
-using System.Runtime.Serialization;
-using DeviceContacts = Microsoft.Phone.UserData.Contacts;
 using System.Diagnostics;
 using System.Linq;
+using System.Runtime.Serialization;
+using System.Windows;
+using DeviceContacts = Microsoft.Phone.UserData.Contacts;
 
 
 namespace WP7CordovaClassLib.Cordova.Commands
@@ -176,23 +168,6 @@ namespace WP7CordovaClassLib.Cordova.Commands
 
         }
 
-        private void saveContactTask_Completed(object sender, SaveContactResult e)
-        {
-            switch (e.TaskResult)
-            {
-                case TaskResult.OK:
-                    // successful save
-                    MessageBoxResult res = MessageBox.Show("contact saved", "Alert", MessageBoxButton.OK);
-                    break;
-                case TaskResult.Cancel:
-                    // user cancelled
-                    break;
-                case TaskResult.None:
-                    // no info about result is available
-                    break;
-            }
-        }
-
         // refer here for contact properties we can access: http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.savecontacttask_members%28v=VS.92%29.aspx
         public void save(string jsonContact)
         {
@@ -265,13 +240,28 @@ namespace WP7CordovaClassLib.Cordova.Commands
             #endregion
 
             #region contact.emails
+
             if (contact.emails != null && contact.emails.Length > 0)
             {
+
+                // set up different email types if they are not explicitly defined
+                foreach (string type in new string[] { "personal", "work", "other" })
+                {
+                    foreach (JSONContactField field in contact.emails)
+                    {
+                        if (field != null && String.IsNullOrEmpty(field.type))
+                        {
+                            field.type = type;
+                            break;
+                        }
+                    }
+                }
+
                 foreach (JSONContactField field in contact.emails)
                 {
                     if (field != null)
                     {
-                        if (field.type != null)
+                        if (field.type != null && field.type != "other")
                         {
                             string fieldType = field.type.ToLower();
                             if (fieldType == "work")
@@ -334,25 +324,32 @@ namespace WP7CordovaClassLib.Cordova.Commands
             #endregion
 
 
-            contactTask.Completed += new EventHandler<SaveContactResult>(contactTask_Completed);
+            contactTask.Completed += new EventHandler<SaveContactResult>(ContactSaveTaskCompleted);
             contactTask.Show();
-
-            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, new string[] {
}));
         }
 
-        void contactTask_Completed(object sender, SaveContactResult e)
+        void ContactSaveTaskCompleted(object sender, SaveContactResult e)
         {
             SaveContactTask task = sender as SaveContactTask;
 
             if (e.TaskResult == TaskResult.OK)
             {
-                DeviceContacts deviceContacts = new DeviceContacts();
-                deviceContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(postAdd_SearchCompleted);
-                deviceContacts.SearchAsync(task.FirstName + " " + task.LastName, FilterKind.DisplayName,
task);
+
+                Deployment.Current.Dispatcher.BeginInvoke(() =>
+                {
+                    DeviceContacts deviceContacts = new DeviceContacts();
+                    deviceContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(postAdd_SearchCompleted);
+
+                    string displayName = String.Format("{0}{2}{1}", task.FirstName, task.LastName,
String.IsNullOrEmpty(task.FirstName) ? "" : " ");
+
+                    deviceContacts.SearchAsync(displayName, FilterKind.DisplayName, task);
+                });
+                
+
             }
             else if (e.TaskResult == TaskResult.Cancel)
             {
-
+                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Operation
cancelled."));
             }
         }
 
@@ -637,7 +634,9 @@ namespace WP7CordovaClassLib.Cordova.Commands
                                       "\"addresses\":[{5}]," +
                                       "\"urls\":[{6}]," +
                                       "\"name\":{7}," +
-                                      "\"note\":\"{8}\"";
+                                      "\"note\":\"{8}\"," +
+                                      "\"birthday\":\"{9}\"";
+
 
             string jsonContact = String.Format(contactFormatStr,
                                                con.GetHashCode(),
@@ -648,7 +647,8 @@ namespace WP7CordovaClassLib.Cordova.Commands
                                                FormatJSONAddresses(con),
                                                FormatJSONWebsites(con),
                                                FormatJSONName(con),
-                                               con.Notes.FirstOrDefault());
+                                               con.Notes.FirstOrDefault(),
+                                               con.Birthdays.FirstOrDefault());
 
             //Debug.WriteLine("jsonContact = " + jsonContact);
             // JSON requires new line characters be escaped


Mime
View raw message