blob: c658b8a33ddbed0c25fbcb06d1176bd2ff1c2ce3 [file] [log] [blame]
Alexandre Savard166dbb62012-09-18 09:37:27 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
alisionf76de3b2013-04-16 15:35:22 -040031package com.savoirfairelinux.sflphone.model;
Alexandre Savard166dbb62012-09-18 09:37:27 -040032
alisiond8c83882013-05-17 17:00:42 -040033import java.lang.reflect.Array;
alisiond295ec22013-05-17 10:12:13 -040034import java.util.ArrayList;
alisiond8c83882013-05-17 17:00:42 -040035import java.util.Arrays;
Alexandre Savard166dbb62012-09-18 09:37:27 -040036
alisiond295ec22013-05-17 10:12:13 -040037import android.os.Parcel;
38import android.os.Parcelable;
alisiond8c83882013-05-17 17:00:42 -040039import android.provider.Contacts.Phones;
alisiond295ec22013-05-17 10:12:13 -040040
41public class CallContact implements Parcelable {
42
alisiond8c83882013-05-17 17:00:42 -040043 private long id;
44 private String mDisplayName;
45 private long photo_id;
46 private ArrayList<Phone> phones, sip_phones;
47 private String mEmail;
alisiond295ec22013-05-17 10:12:13 -040048
alisiond8c83882013-05-17 17:00:42 -040049 private CallContact(long cID, String displayName, long photoID, ArrayList<Phone> p, ArrayList<Phone> sip, String mail) {
50 id = cID;
51 mDisplayName = displayName;
52 phones = p;
53 sip_phones = sip;
54 mEmail = mail;
55 photo_id = photoID;
56 }
Alexandre Savard166dbb62012-09-18 09:37:27 -040057
alisiond8c83882013-05-17 17:00:42 -040058 public CallContact(Parcel in) {
59 readFromParcel(in);
60 }
alisiond295ec22013-05-17 10:12:13 -040061
alisiond8c83882013-05-17 17:00:42 -040062 public long getId() {
63 return id;
64 }
alisiond295ec22013-05-17 10:12:13 -040065
alisiond8c83882013-05-17 17:00:42 -040066 public String getmDisplayName() {
67 return mDisplayName;
68 }
Alexandre Savard166dbb62012-09-18 09:37:27 -040069
alisiond8c83882013-05-17 17:00:42 -040070 public void setmDisplayName(String mDisplayName) {
71 this.mDisplayName = mDisplayName;
72 }
Alexandre Savard166dbb62012-09-18 09:37:27 -040073
alisiond8c83882013-05-17 17:00:42 -040074 public long getPhoto_id() {
75 return photo_id;
76 }
alisiond295ec22013-05-17 10:12:13 -040077
alisiond8c83882013-05-17 17:00:42 -040078 public void setPhoto_id(long photo_id) {
79 this.photo_id = photo_id;
80 }
alisiond295ec22013-05-17 10:12:13 -040081
alisiond8c83882013-05-17 17:00:42 -040082 public ArrayList<Phone> getPhones() {
83 return phones;
84 }
alisiond295ec22013-05-17 10:12:13 -040085
alisiond8c83882013-05-17 17:00:42 -040086 public void setPhones(ArrayList<Phone> phones) {
87 this.phones = phones;
88 }
alisiond295ec22013-05-17 10:12:13 -040089
alisiond8c83882013-05-17 17:00:42 -040090 public ArrayList<Phone> getSip_phones() {
91 return sip_phones;
92 }
alisiond295ec22013-05-17 10:12:13 -040093
alisiond8c83882013-05-17 17:00:42 -040094 public void setSip_phones(ArrayList<Phone> sip_phones) {
95 this.sip_phones = sip_phones;
96 }
alisiond295ec22013-05-17 10:12:13 -040097
alisiond8c83882013-05-17 17:00:42 -040098 public Phone getSipPhone() {
99 if (sip_phones.size() > 0) {
100 return sip_phones.get(0);
101 }
102 if (phones.size() > 0) {
103 return phones.get(0);
104 }
105 return null;
106 }
Alexandre Savard38d6a152012-09-18 13:33:02 -0400107
alisiond8c83882013-05-17 17:00:42 -0400108 public String getmEmail() {
109 return mEmail;
110 }
alisiond295ec22013-05-17 10:12:13 -0400111
alisiond8c83882013-05-17 17:00:42 -0400112 public void setmEmail(String mEmail) {
113 this.mEmail = mEmail;
114 }
alisiond295ec22013-05-17 10:12:13 -0400115
alisiond8c83882013-05-17 17:00:42 -0400116 @Override
117 public String toString() {
118 return mDisplayName;
119 }
alisiond295ec22013-05-17 10:12:13 -0400120
alisiond8c83882013-05-17 17:00:42 -0400121 public static class ContactBuilder {
alisiond295ec22013-05-17 10:12:13 -0400122
alisiond8c83882013-05-17 17:00:42 -0400123 long contactID;
124 String contactName;
125 long contactPhoto;
126 ArrayList<Phone> phones;
127 ArrayList<Phone> sip;
128 String contactMail;
129 boolean hasPhoto;
alisiond295ec22013-05-17 10:12:13 -0400130
alisiond8c83882013-05-17 17:00:42 -0400131 public ContactBuilder startNewContact(long id, String displayName, long photo_id) {
132 contactID = id;
133 contactName = displayName;
134 contactPhoto = photo_id;
135 phones = new ArrayList<Phone>();
136 sip = new ArrayList<Phone>();
137 return this;
138 }
alisiond295ec22013-05-17 10:12:13 -0400139
alisiond8c83882013-05-17 17:00:42 -0400140 public ContactBuilder addPhoneNumber(String num, int type) {
141 phones.add(new Phone(num, type));
142 return this;
143 }
alisiond295ec22013-05-17 10:12:13 -0400144
alisiond8c83882013-05-17 17:00:42 -0400145 public ContactBuilder addSipNumber(String num, int type) {
146 sip.add(new Phone(num, type));
147 return this;
148 }
alisiond295ec22013-05-17 10:12:13 -0400149
alisiond8c83882013-05-17 17:00:42 -0400150 public CallContact build() {
151 return new CallContact(contactID, contactName, contactPhoto, phones, sip, contactMail);
152 }
Adrien BĂ©raud33268882013-05-18 03:41:15 +1000153
alisiond8c83882013-05-17 17:00:42 -0400154 public static ContactBuilder getInstance() {
155 return new ContactBuilder();
156 }
alisiond295ec22013-05-17 10:12:13 -0400157
alisiond8c83882013-05-17 17:00:42 -0400158 }
alisiond295ec22013-05-17 10:12:13 -0400159
alisiond8c83882013-05-17 17:00:42 -0400160 @Override
161 public int describeContents() {
162 return 0;
163 }
alisiond295ec22013-05-17 10:12:13 -0400164
alisiond8c83882013-05-17 17:00:42 -0400165 @Override
166 public void writeToParcel(Parcel dest, int flags) {
167 dest.writeLong(id);
168 dest.writeString(mDisplayName);
169 dest.writeLong(photo_id);
170 dest.writeTypedList(phones);
alisiond295ec22013-05-17 10:12:13 -0400171
alisiond8c83882013-05-17 17:00:42 -0400172 dest.writeTypedList(sip_phones);
173
174 dest.writeString(mEmail);
175
alisiond295ec22013-05-17 10:12:13 -0400176
alisiond8c83882013-05-17 17:00:42 -0400177 }
alisiond295ec22013-05-17 10:12:13 -0400178
alisiond8c83882013-05-17 17:00:42 -0400179 private void readFromParcel(Parcel in) {
alisiond295ec22013-05-17 10:12:13 -0400180
alisiond8c83882013-05-17 17:00:42 -0400181 id = in.readLong();
182 mDisplayName = in.readString();
183 photo_id = in.readLong();
184 phones = new ArrayList<CallContact.Phone>();
185 sip_phones = new ArrayList<CallContact.Phone>();
186 in.readTypedList(phones, Phone.CREATOR);
187 in.readTypedList(sip_phones, Phone.CREATOR);
188 mEmail = in.readString();
189 }
alisiond295ec22013-05-17 10:12:13 -0400190
alisiond8c83882013-05-17 17:00:42 -0400191 public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
192 @Override
193 public CallContact createFromParcel(Parcel in) {
194 return new CallContact(in);
195 }
alisiond295ec22013-05-17 10:12:13 -0400196
alisiond8c83882013-05-17 17:00:42 -0400197 @Override
198 public CallContact[] newArray(int size) {
199 return new CallContact[size];
200 }
201 };
alisiond295ec22013-05-17 10:12:13 -0400202
alisiond8c83882013-05-17 17:00:42 -0400203 public static class Phone implements Parcelable {
alisiond295ec22013-05-17 10:12:13 -0400204
alisiond8c83882013-05-17 17:00:42 -0400205 int type;
206 String number;
alisiond295ec22013-05-17 10:12:13 -0400207
alisiond8c83882013-05-17 17:00:42 -0400208 public Phone(String num, int ty) {
209 type = ty;
210 number = num;
211 }
alisiond295ec22013-05-17 10:12:13 -0400212
alisiond8c83882013-05-17 17:00:42 -0400213 public Phone(Parcel in) {
214 readFromParcel(in);
215 }
alisiond295ec22013-05-17 10:12:13 -0400216
alisiond8c83882013-05-17 17:00:42 -0400217 @Override
218 public int describeContents() {
219 return 0;
220 }
alisiond295ec22013-05-17 10:12:13 -0400221
alisiond8c83882013-05-17 17:00:42 -0400222 @Override
223 public void writeToParcel(Parcel dest, int arg1) {
224 dest.writeInt(type);
225 dest.writeString(number);
226 }
alisiond295ec22013-05-17 10:12:13 -0400227
alisiond8c83882013-05-17 17:00:42 -0400228 private void readFromParcel(Parcel in) {
229 type = in.readInt();
230 number = in.readString();
231 }
alisiond295ec22013-05-17 10:12:13 -0400232
alisiond8c83882013-05-17 17:00:42 -0400233 public static final Parcelable.Creator<Phone> CREATOR = new Parcelable.Creator() {
234 @Override
235 public Phone createFromParcel(Parcel in) {
236 return new Phone(in);
237 }
alisiond295ec22013-05-17 10:12:13 -0400238
alisiond8c83882013-05-17 17:00:42 -0400239 @Override
240 public Phone[] newArray(int size) {
241 return new Phone[size];
242 }
243 };
alisiond295ec22013-05-17 10:12:13 -0400244
alisiond8c83882013-05-17 17:00:42 -0400245 public int getType() {
246 return type;
247 }
248
249 public void setType(int type) {
250 this.type = type;
251 }
252
253 public String getNumber() {
254 return number;
255 }
256
257 public void setNumber(String number) {
258 this.number = number;
259 }
260
261 }
alisiond295ec22013-05-17 10:12:13 -0400262
Alexandre Savard166dbb62012-09-18 09:37:27 -0400263}