replace delegate with EventHandler<T> 09/147709/1
authorJongkyu Koo <jk.koo@samsung.com>
Tue, 5 Sep 2017 09:36:06 +0000 (18:36 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Tue, 5 Sep 2017 09:36:06 +0000 (18:36 +0900)
Change-Id: I738d921c7ef4a3241402cc140b8b8bdc5362be71
Signed-off-by: Jongkyu Koo <jk.koo@samsung.com>
src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsDatabase.cs
src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsVcard.cs
src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/DBChangedEventArgs.cs [new file with mode: 0644]
src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/DBStatusChangedEventArgs.cs
src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/NameDisplayOrderChangedEventArgs.cs
src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/NameSortingOrderChangedEventArgs.cs

index c868c56..c1a4043 100644 (file)
@@ -21,15 +21,6 @@ using System.Runtime.InteropServices;
 
 namespace Tizen.Pims.Contacts
 {
-    /// <summary>
-    /// Delegate for detecting the contacts database changes
-    /// </summary>
-    /// <param name="uri">The contacts view URI</param>
-    /// <remarks>
-    /// The delegate must be registered using AddDBChangedDelegate.
-    /// It's invoked when the designated view changes.
-    /// </remarks>
-    public delegate void ContactsDBChanged(string uri);
 
     /// <summary>
     /// ContactsDatabase provides methods to manage contacts information from/to the database.
@@ -42,7 +33,7 @@ namespace Tizen.Pims.Contacts
         private Object thisLock = new Object();
         private Interop.Database.ContactsDBStatusChangedCallback _contactsDBStatusChangedCallback;
         private EventHandler<DBStatusChangedEventArgs> _dbStatusChanged;
-        private Dictionary<string, ContactsDBChanged> _delegateMap = new Dictionary<string, ContactsDBChanged>();
+        private Dictionary<string, EventHandler<DBChangedEventArgs>> _delegateMap = new Dictionary<string, EventHandler<DBChangedEventArgs>>();
         private Dictionary<string, Interop.Database.ContactsDBChangedCallback> _callbackMap = new Dictionary<string, Interop.Database.ContactsDBChangedCallback>();
         private Interop.Database.ContactsDBChangedCallback _dbChangedDelegate;
 
@@ -721,15 +712,16 @@ namespace Tizen.Pims.Contacts
         /// Registers a callback function to be invoked when a record changes.
         /// </summary>
         /// <param name="viewUri">The view URI of records whose changes are monitored</param>
-        /// <param name="callback">The callback function to register</param>
+        /// <param name="DBChanged">The EventHandler to register</param>
         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
-        public void AddDBChangedDelegate(string viewUri, ContactsDBChanged callback)
+        public void AddDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
         {
             if (_callbackMap[viewUri] == null)
             {
                 _callbackMap[viewUri] = (string uri, IntPtr userData) =>
                 {
-                    _delegateMap[uri](uri);
+                    DBChangedEventArgs args = new DBChangedEventArgs(uri);
+                    _delegateMap[uri]?.Invoke(this, args);
                 };
 
                 int error = Interop.Database.AddChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero);
@@ -740,18 +732,18 @@ namespace Tizen.Pims.Contacts
                 }
             }
 
-            _delegateMap[viewUri] += callback;
+            _delegateMap[viewUri] += DBChanged;
         }
 
         /// <summary>
         /// Deregisters a callback function.
         /// </summary>
         /// <param name="viewUri">The view URI of records whose changes are monitored</param>
-        /// <param name="callback">The callback function to register</param>
+        /// <param name="DBChanged">The EventHandler to deregister</param>
         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
-        public void RemoveDBChangedDelegate(string viewUri, ContactsDBChanged callback)
+        public void RemoveDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
         {
-            _delegateMap[viewUri] -= callback;
+            _delegateMap[viewUri] -= DBChanged;
 
             if (_delegateMap[viewUri] == null)
             {
index 3273a9d..8a7b7c0 100644 (file)
@@ -24,7 +24,7 @@ namespace Tizen.Pims.Contacts
     /// Delegate for getting a record parsed from a vCard file
     /// </summary>
     /// <param name="record">The contacts record</param>
-    /// <returns></returns>
+    /// <returns> true to continue with the next iteration of the loop, otherwise false to break out of the loop</returns>
     public delegate bool ParseCallback(ContactsRecord record);
 
     /// <summary>
diff --git a/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/DBChangedEventArgs.cs b/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/DBChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..591c4a0
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+
+namespace Tizen.Pims.Contacts
+{
+    /// <summary>
+    /// Event arguments passed when contacts database is changed
+    /// </summary>
+    public class DBChangedEventArgs : EventArgs
+    {
+        internal DBChangedEventArgs(string viewUri)
+        {
+            ViewUri = viewUri;
+        }
+
+        /// <summary>
+        /// The contacts view URI changed.
+        /// </summary>
+        public string ViewUri
+        {
+            get;
+            internal set;
+        }
+    }
+}
index 0257c18..ca1a79b 100644 (file)
@@ -26,7 +26,7 @@ namespace Tizen.Pims.Contacts
     {
         internal DBStatusChangedEventArgs(DBStatus status)
         {
-            this.Status = status;
+            Status = status;
         }
 
         /// <summary>
index 8e5dc3d..228318c 100644 (file)
@@ -25,7 +25,7 @@ namespace Tizen.Pims.Contacts
     {
         internal NameDisplayOrderChangedEventArgs(ContactDisplayOrder displayOrder)
         {
-            this.NameDisplayOrder = displayOrder;
+            NameDisplayOrder = displayOrder;
         }
 
         /// <summary>
index e365204..152ef0b 100644 (file)
@@ -25,7 +25,7 @@ namespace Tizen.Pims.Contacts
     {
         internal NameSortingOrderChangedEventArgs(ContactSortingOrder SortingOrder)
         {
-            this.NameSortingOrder = SortingOrder;
+            NameSortingOrder = SortingOrder;
         }
 
         /// <summary>