blob: 0472bbba5c67b5000d17fb3c7d6b03cab6268b33 [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
alisiond295ec22013-05-17 10:12:13 -040033import java.util.ArrayList;
Alexandre Savard166dbb62012-09-18 09:37:27 -040034
alisiond295ec22013-05-17 10:12:13 -040035import android.os.Parcel;
36import android.os.Parcelable;
37
38public class CallContact implements Parcelable {
39
Adrien Béraud33268882013-05-18 03:41:15 +100040 private long id;
41 private String mDisplayName;
42 private long photo_id;
43 ArrayList<Phone> phones, sip_phones;
44 String mEmail;
alisiond295ec22013-05-17 10:12:13 -040045
Adrien Béraud33268882013-05-18 03:41:15 +100046 private CallContact(long cID, String displayName, long photoID, ArrayList<Phone> p, ArrayList<Phone> sip, String mail) {
47 id = cID;
48 mDisplayName = displayName;
49 phones = p;
50 sip_phones = sip;
51 mEmail = mail;
52 photo_id = photoID;
53 }
Alexandre Savard166dbb62012-09-18 09:37:27 -040054
Adrien Béraud33268882013-05-18 03:41:15 +100055 public CallContact(Parcel in) {
56 readFromParcel(in);
57 }
alisiond295ec22013-05-17 10:12:13 -040058
Adrien Béraud33268882013-05-18 03:41:15 +100059 public long getId() {
60 return id;
61 }
alisiond295ec22013-05-17 10:12:13 -040062
Adrien Béraud33268882013-05-18 03:41:15 +100063 public String getmDisplayName() {
64 return mDisplayName;
65 }
Alexandre Savard166dbb62012-09-18 09:37:27 -040066
Adrien Béraud33268882013-05-18 03:41:15 +100067 public void setmDisplayName(String mDisplayName) {
68 this.mDisplayName = mDisplayName;
69 }
Alexandre Savard166dbb62012-09-18 09:37:27 -040070
Adrien Béraud33268882013-05-18 03:41:15 +100071 public long getPhoto_id() {
72 return photo_id;
73 }
alisiond295ec22013-05-17 10:12:13 -040074
Adrien Béraud33268882013-05-18 03:41:15 +100075 public void setPhoto_id(long photo_id) {
76 this.photo_id = photo_id;
77 }
alisiond295ec22013-05-17 10:12:13 -040078
Adrien Béraud33268882013-05-18 03:41:15 +100079 public ArrayList<Phone> getPhones() {
80 return phones;
81 }
alisiond295ec22013-05-17 10:12:13 -040082
Adrien Béraud33268882013-05-18 03:41:15 +100083 public void setPhones(ArrayList<Phone> phones) {
84 this.phones = phones;
85 }
alisiond295ec22013-05-17 10:12:13 -040086
Adrien Béraud33268882013-05-18 03:41:15 +100087 public ArrayList<Phone> getSip_phones() {
88 return sip_phones;
89 }
alisiond295ec22013-05-17 10:12:13 -040090
Adrien Béraud33268882013-05-18 03:41:15 +100091 public void setSip_phones(ArrayList<Phone> sip_phones) {
92 this.sip_phones = sip_phones;
93 }
alisiond295ec22013-05-17 10:12:13 -040094
Adrien Béraud33268882013-05-18 03:41:15 +100095 public Phone getSipPhone() {
96 if(sip_phones.size() > 0) {
97 return sip_phones.get(0);
98 }
99 if(phones.size() > 0) {
100 return phones.get(0);
101 }
102 return null;
103 }
Alexandre Savard38d6a152012-09-18 13:33:02 -0400104
Adrien Béraud33268882013-05-18 03:41:15 +1000105 public String getmEmail() {
106 return mEmail;
107 }
alisiond295ec22013-05-17 10:12:13 -0400108
Adrien Béraud33268882013-05-18 03:41:15 +1000109 public void setmEmail(String mEmail) {
110 this.mEmail = mEmail;
111 }
alisiond295ec22013-05-17 10:12:13 -0400112
Adrien Béraud33268882013-05-18 03:41:15 +1000113 @Override
114 public String toString() {
115 return mDisplayName;
116 }
alisiond295ec22013-05-17 10:12:13 -0400117
Adrien Béraud33268882013-05-18 03:41:15 +1000118 public static class ContactBuilder {
alisiond295ec22013-05-17 10:12:13 -0400119
Adrien Béraud33268882013-05-18 03:41:15 +1000120 long contactID;
121 String contactName;
122 long contactPhoto;
123 ArrayList<Phone> phones;
124 ArrayList<Phone> sip;
125 String contactMail;
126 boolean hasPhoto;
alisiond295ec22013-05-17 10:12:13 -0400127
Adrien Béraud33268882013-05-18 03:41:15 +1000128 public ContactBuilder startNewContact(long id, String displayName, long photo_id) {
129 contactID = id;
130 contactName = displayName;
131 contactPhoto = photo_id;
132 phones = new ArrayList<Phone>();
133 sip = new ArrayList<Phone>();
134 return this;
135 }
alisiond295ec22013-05-17 10:12:13 -0400136
Adrien Béraud33268882013-05-18 03:41:15 +1000137 public ContactBuilder addPhoneNumber(String num, int type) {
138 phones.add(new Phone(num, type));
139 return this;
140 }
alisiond295ec22013-05-17 10:12:13 -0400141
Adrien Béraud33268882013-05-18 03:41:15 +1000142 public ContactBuilder addSipNumber(String num, int type){
143 sip.add(new Phone(num, type));
144 return this;
145 }
alisiond295ec22013-05-17 10:12:13 -0400146
Adrien Béraud33268882013-05-18 03:41:15 +1000147 public CallContact build() {
148 return new CallContact(contactID, contactName, contactPhoto, phones, sip, contactMail);
149 }
150
151 public static ContactBuilder getInstance() {
152 return new ContactBuilder();
153 }
alisiond295ec22013-05-17 10:12:13 -0400154
155
Adrien Béraud33268882013-05-18 03:41:15 +1000156 }
alisiond295ec22013-05-17 10:12:13 -0400157
Adrien Béraud33268882013-05-18 03:41:15 +1000158 @Override
159 public int describeContents() {
160 return 0;
161 }
alisiond295ec22013-05-17 10:12:13 -0400162
Adrien Béraud33268882013-05-18 03:41:15 +1000163 @Override
164 public void writeToParcel(Parcel dest, int flags) {
165 dest.writeLong(id);
166 Phone[] tmp = new Phone[phones.size()];
167 phones.toArray(tmp);
168 dest.writeParcelableArray(tmp, flags);
169 dest.writeLong(photo_id);
alisiond295ec22013-05-17 10:12:13 -0400170
Adrien Béraud33268882013-05-18 03:41:15 +1000171 }
alisiond295ec22013-05-17 10:12:13 -0400172
Adrien Béraud33268882013-05-18 03:41:15 +1000173 private void readFromParcel(Parcel in) {
alisiond295ec22013-05-17 10:12:13 -0400174
Adrien Béraud33268882013-05-18 03:41:15 +1000175 id = in.readLong();
176 mDisplayName = in.readString();
177 photo_id = in.readLong();
178 phones = in.readArrayList(Phone.class.getClassLoader());
179 sip_phones = in.readArrayList(Phone.class.getClassLoader());
180 mEmail = in.readString();
181 }
alisiond295ec22013-05-17 10:12:13 -0400182
Adrien Béraud33268882013-05-18 03:41:15 +1000183 public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
184 @Override
185 public CallContact createFromParcel(Parcel in) {
186 return new CallContact(in);
187 }
alisiond295ec22013-05-17 10:12:13 -0400188
Adrien Béraud33268882013-05-18 03:41:15 +1000189 @Override
190 public CallContact[] newArray(int size) {
191 return new CallContact[size];
192 }
193 };
alisiond295ec22013-05-17 10:12:13 -0400194
Adrien Béraud33268882013-05-18 03:41:15 +1000195 public static class Phone implements Parcelable {
alisiond295ec22013-05-17 10:12:13 -0400196
Adrien Béraud33268882013-05-18 03:41:15 +1000197 int type;
198 String number;
alisiond295ec22013-05-17 10:12:13 -0400199
Adrien Béraud33268882013-05-18 03:41:15 +1000200 public Phone(String num, int ty) {
201 type = ty;
202 number = num;
203 }
alisiond295ec22013-05-17 10:12:13 -0400204
Adrien Béraud33268882013-05-18 03:41:15 +1000205 public Phone(Parcel in) {
206 readFromParcel(in);
207 }
alisiond295ec22013-05-17 10:12:13 -0400208
Adrien Béraud33268882013-05-18 03:41:15 +1000209 @Override
210 public int describeContents() {
211 return 0;
212 }
alisiond295ec22013-05-17 10:12:13 -0400213
Adrien Béraud33268882013-05-18 03:41:15 +1000214 @Override
215 public void writeToParcel(Parcel dest, int arg1) {
216 dest.writeInt(type);
217 dest.writeString(number);
218 }
alisiond295ec22013-05-17 10:12:13 -0400219
Adrien Béraud33268882013-05-18 03:41:15 +1000220 private void readFromParcel(Parcel in) {
221 type = in.readInt();
222 number = in.readString();
223 }
alisiond295ec22013-05-17 10:12:13 -0400224
Adrien Béraud33268882013-05-18 03:41:15 +1000225 public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
226 @Override
227 public Phone createFromParcel(Parcel in) {
228 return new Phone(in);
229 }
alisiond295ec22013-05-17 10:12:13 -0400230
Adrien Béraud33268882013-05-18 03:41:15 +1000231 @Override
232 public Phone[] newArray(int size) {
233 return new Phone[size];
234 }
235 };
alisiond295ec22013-05-17 10:12:13 -0400236
Adrien Béraud33268882013-05-18 03:41:15 +1000237 }
alisiond295ec22013-05-17 10:12:13 -0400238
Alexandre Savard166dbb62012-09-18 09:37:27 -0400239}