2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Pims.Contacts
22 /// A list of records with the same type
24 /// <since_tizen> 4 </since_tizen>
25 public class ContactsList:IDisposable
27 private Int64 _memoryPressure = 20;
28 internal IntPtr _listHandle;
29 internal ContactsList(IntPtr handle)
34 int error = Interop.List.ContactsListGetCount(_listHandle, out count);
35 if ((int)ContactsError.None != error)
37 Log.Error(Globals.LogTag, "ContactsList Failed with error " + error);
38 throw ContactsErrorFactory.CheckAndCreateException(error);
40 _memoryPressure += count * ContactsViews.Record.AverageSize;
41 GC.AddMemoryPressure(_memoryPressure);
45 /// Creates a contacts record list.
47 /// <feature>http://tizen.org/feature/contact</feature>
48 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
49 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
50 /// <since_tizen> 4 </since_tizen>
53 int error = Interop.List.ContactsListCreate(out _listHandle);
54 if ((int)ContactsError.None != error)
56 Log.Error(Globals.LogTag, "ContactsList Failed with error " + error);
57 throw ContactsErrorFactory.CheckAndCreateException(error);
59 GC.AddMemoryPressure(_memoryPressure);
65 /// <since_tizen> 4 </since_tizen>
72 /// The count of contact entity.
74 /// <value>The count of contact entity.</value>
75 /// <since_tizen> 4 </since_tizen>
81 int error = Interop.List.ContactsListGetCount(_listHandle, out count);
82 if ((int)ContactsError.None != error)
84 Log.Error(Globals.LogTag, "ContactsList Count Failed with error " + error);
90 #region IDisposable Support
91 private bool disposedValue = false; // To detect redundant calls
94 /// Releases all resources used by the ContactsList.
96 /// <param name="disposing">Disposing by User</param>
97 /// <since_tizen> 4 </since_tizen>
98 protected virtual void Dispose(bool disposing)
103 //Release your own managed resources here.
104 //You should release all of your own disposable objects here
109 int error = Interop.List.ContactsListDestroy(_listHandle, true);
110 if ((int)ContactsError.None != error)
112 Log.Error(Globals.LogTag, "ContactsListDestroy Failed with error " + error);
115 disposedValue = true;
116 GC.RemoveMemoryPressure(_memoryPressure);
121 /// Releases all resources used by the ContactsList.
122 /// It should be called after finished using of the object.
124 /// <since_tizen> 4 </since_tizen>
125 public void Dispose()
128 GC.SuppressFinalize(this);
133 /// Adds a record to the contacts list.
135 /// <param name="record">The record to add</param>
136 /// <feature>http://tizen.org/feature/contact</feature>
137 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
138 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
139 /// <since_tizen> 4 </since_tizen>
140 public void AddRecord(ContactsRecord record)
142 int error = Interop.List.ContactsListAdd(_listHandle, record._recordHandle);
143 if ((int)ContactsError.None != error)
145 Log.Error(Globals.LogTag, "AddRecord Failed with error " + error);
146 throw ContactsErrorFactory.CheckAndCreateException(error);
148 record._disposedValue = true;
149 _memoryPressure += ContactsViews.Record.AverageSize;
153 /// Removes a record from the contacts list.
155 /// <param name="record">The record to remove</param>
156 /// <feature>http://tizen.org/feature/contact</feature>
157 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
158 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
159 /// <since_tizen> 4 </since_tizen>
160 public void RemoveRecord(ContactsRecord record)
162 int error = Interop.List.ContactsListRemove(_listHandle, record._recordHandle);
163 if ((int)ContactsError.None != error)
165 Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error);
166 throw ContactsErrorFactory.CheckAndCreateException(error);
168 record._disposedValue = false;
169 _memoryPressure -= ContactsViews.Record.AverageSize;
173 /// Retrieves a record from the contacts list.
178 /// <feature>http://tizen.org/feature/contact</feature>
179 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
180 /// <since_tizen> 4 </since_tizen>
181 public ContactsRecord GetCurrentRecord()
184 int error = Interop.List.ContactsListGetCurrentRecordP(_listHandle, out handle);
185 if ((int)ContactsError.None != error)
187 Log.Error(Globals.LogTag, "GetCurrentRecord Failed with error " + error);
188 throw ContactsErrorFactory.CheckAndCreateException(error);
190 return new ContactsRecord(handle, true);
194 /// Moves a contacts list to the previous position.
197 /// When the cursor is already at the first position, it returns false.
199 /// <feature>http://tizen.org/feature/contact</feature>
200 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
201 /// <since_tizen> 4 </since_tizen>
202 public bool MovePrevious()
204 int error = Interop.List.ContactsListPrev(_listHandle);
206 if ((int)ContactsError.None == error)
210 else if (Count > 0 && (int)ContactsError.NoData == error)
212 Log.Debug(Globals.LogTag, "Nodata MovePrevious" + error);
217 Log.Error(Globals.LogTag, "MovePrevious Failed with error " + error);
218 throw ContactsErrorFactory.CheckAndCreateException(error);
223 /// Moves a contacts list to the next position.
226 /// When the cursor is already at the last position, it returns false.
228 /// <feature>http://tizen.org/feature/contact</feature>
229 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
230 /// <since_tizen> 4 </since_tizen>
231 public bool MoveNext()
233 int error = Interop.List.ContactsListNext(_listHandle);
235 if ((int)ContactsError.None == error)
239 else if (Count > 0 && (int)ContactsError.NoData == error)
241 Log.Debug(Globals.LogTag, "Nodata MoveNext" + error);
246 Log.Error(Globals.LogTag, "MoveNext Failed with error " + error);
247 throw ContactsErrorFactory.CheckAndCreateException(error);
252 /// Moves a contacts list to the first position.
254 /// <feature>http://tizen.org/feature/contact</feature>
255 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
256 /// <since_tizen> 4 </since_tizen>
257 public void MoveFirst()
259 int error = Interop.List.ContactsListFirst(_listHandle);
260 if ((int)ContactsError.None != error)
262 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
263 throw ContactsErrorFactory.CheckAndCreateException(error);
268 /// Moves a contacts list to the last position.
270 /// <feature>http://tizen.org/feature/contact</feature>
271 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
272 /// <since_tizen> 4 </since_tizen>
273 public void MoveLast()
275 int error = Interop.List.ContactsListLast(_listHandle);
276 if ((int)ContactsError.None != error)
278 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
279 throw ContactsErrorFactory.CheckAndCreateException(error);