blob: 4a6901200b90df24d0087c3bf549492d52a15035 [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
alision84813a12013-05-27 17:40:39 -0400158 public CallContact buildUnknownContact(String to) {
159 phones = new ArrayList<Phone>();
160 phones.add(new Phone(to, 0));
161
162 return new CallContact(-1, to, 0, phones, new ArrayList<CallContact.Phone>(), "");
163 }
164
alisiond8c83882013-05-17 17:00:42 -0400165 }
alisiond295ec22013-05-17 10:12:13 -0400166
alisiond8c83882013-05-17 17:00:42 -0400167 @Override
168 public int describeContents() {
169 return 0;
170 }
alisiond295ec22013-05-17 10:12:13 -0400171
alisiond8c83882013-05-17 17:00:42 -0400172 @Override
173 public void writeToParcel(Parcel dest, int flags) {
174 dest.writeLong(id);
175 dest.writeString(mDisplayName);
176 dest.writeLong(photo_id);
177 dest.writeTypedList(phones);
alisiond295ec22013-05-17 10:12:13 -0400178
alisiond8c83882013-05-17 17:00:42 -0400179 dest.writeTypedList(sip_phones);
180
181 dest.writeString(mEmail);
182
alisiond295ec22013-05-17 10:12:13 -0400183
alisiond8c83882013-05-17 17:00:42 -0400184 }
alisiond295ec22013-05-17 10:12:13 -0400185
alisiond8c83882013-05-17 17:00:42 -0400186 private void readFromParcel(Parcel in) {
alisiond295ec22013-05-17 10:12:13 -0400187
alisiond8c83882013-05-17 17:00:42 -0400188 id = in.readLong();
189 mDisplayName = in.readString();
190 photo_id = in.readLong();
191 phones = new ArrayList<CallContact.Phone>();
192 sip_phones = new ArrayList<CallContact.Phone>();
193 in.readTypedList(phones, Phone.CREATOR);
194 in.readTypedList(sip_phones, Phone.CREATOR);
195 mEmail = in.readString();
196 }
alisiond295ec22013-05-17 10:12:13 -0400197
alisiond8c83882013-05-17 17:00:42 -0400198 public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
199 @Override
200 public CallContact createFromParcel(Parcel in) {
201 return new CallContact(in);
202 }
alisiond295ec22013-05-17 10:12:13 -0400203
alisiond8c83882013-05-17 17:00:42 -0400204 @Override
205 public CallContact[] newArray(int size) {
206 return new CallContact[size];
207 }
208 };
alisiond295ec22013-05-17 10:12:13 -0400209
alisiond8c83882013-05-17 17:00:42 -0400210 public static class Phone implements Parcelable {
alisiond295ec22013-05-17 10:12:13 -0400211
alisiond8c83882013-05-17 17:00:42 -0400212 int type;
213 String number;
alisiond295ec22013-05-17 10:12:13 -0400214
alisiond8c83882013-05-17 17:00:42 -0400215 public Phone(String num, int ty) {
216 type = ty;
217 number = num;
218 }
alisiond295ec22013-05-17 10:12:13 -0400219
alisiond8c83882013-05-17 17:00:42 -0400220 public Phone(Parcel in) {
221 readFromParcel(in);
222 }
alisiond295ec22013-05-17 10:12:13 -0400223
alisiond8c83882013-05-17 17:00:42 -0400224 @Override
225 public int describeContents() {
226 return 0;
227 }
alisiond295ec22013-05-17 10:12:13 -0400228
alisiond8c83882013-05-17 17:00:42 -0400229 @Override
230 public void writeToParcel(Parcel dest, int arg1) {
231 dest.writeInt(type);
232 dest.writeString(number);
233 }
alisiond295ec22013-05-17 10:12:13 -0400234
alisiond8c83882013-05-17 17:00:42 -0400235 private void readFromParcel(Parcel in) {
236 type = in.readInt();
237 number = in.readString();
238 }
alisiond295ec22013-05-17 10:12:13 -0400239
alisiond8c83882013-05-17 17:00:42 -0400240 public static final Parcelable.Creator<Phone> CREATOR = new Parcelable.Creator() {
241 @Override
242 public Phone createFromParcel(Parcel in) {
243 return new Phone(in);
244 }
alisiond295ec22013-05-17 10:12:13 -0400245
alisiond8c83882013-05-17 17:00:42 -0400246 @Override
247 public Phone[] newArray(int size) {
248 return new Phone[size];
249 }
250 };
alisiond295ec22013-05-17 10:12:13 -0400251
alisiond8c83882013-05-17 17:00:42 -0400252 public int getType() {
253 return type;
254 }
255
256 public void setType(int type) {
257 this.type = type;
258 }
259
260 public String getNumber() {
261 return number;
262 }
263
264 public void setNumber(String number) {
265 this.number = number;
266 }
267
268 }
alisiond295ec22013-05-17 10:12:13 -0400269
Alexandre Savard166dbb62012-09-18 09:37:27 -0400270}