blob: a77f3a33308412aaa4382e5ea351ba3f3ab72baa [file] [log] [blame]
Alexandre Lisionb4e60612014-01-14 17:47:23 -05001/*
2 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@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 */
31
32
Alexandre Lisionaad014e2014-01-14 17:45:49 -050033package org.sflphone.history;
34
Alexandre Lisionb4e60612014-01-14 17:47:23 -050035import android.os.Parcel;
36import android.os.Parcelable;
37import com.j256.ormlite.field.DatabaseField;
Alexandre Lision945e4612014-01-15 17:40:31 -050038import org.sflphone.model.SipCall;
Alexandre Lisionb4e60612014-01-14 17:47:23 -050039import org.sflphone.service.ServiceConstants;
40
41import java.sql.Timestamp;
42import java.text.SimpleDateFormat;
43import java.util.Date;
44import java.util.HashMap;
45import java.util.Locale;
46import java.util.TimeZone;
47
48public class HistoryCall implements Parcelable {
49
50 public long getCallStart() {
51 return call_start;
52 }
53
54 @DatabaseField(index = true)
55 long call_start;
56 @DatabaseField
57 long call_end;
58 @DatabaseField
59 String number;
60 @DatabaseField
61 boolean missed;
62 @DatabaseField
63 String direction;
64 @DatabaseField
65 String recordPath;
Alexandre Lisionb4e60612014-01-14 17:47:23 -050066
67 public String getAccountID() {
68 return accountID;
69 }
70
71 @DatabaseField
72 String accountID;
73
74 public long getContactID() {
75 return contactID;
76 }
77
78 @DatabaseField
79 long contactID;
80 @DatabaseField
81 long callID;
82
Alexandre Lision945e4612014-01-15 17:40:31 -050083 public HistoryCall(SipCall call) {
84 call_start = call.getTimestampStart_();
85 call_end = call.getTimestampEnd_();
86 number = call.getContact().getPhones().get(0).getNumber();
87 missed = call.isRinging();
88 direction = call.getCallTypeString();
89 recordPath = call.getRecordPath();
90 }
91
Alexandre Lisionb4e60612014-01-14 17:47:23 -050092 /* Needed by ORMLite */
93 public HistoryCall() {
94 }
95
96 public String getDirection() {
97 return direction;
98 }
99
100 public String getDate() {
Alexandre Lision945e4612014-01-15 17:40:31 -0500101 return HistoryTimeModel.timeToHistoryConst(call_start);
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500102 }
103
104 public String getStartString(String format) {
105 Timestamp stamp = new Timestamp(call_start * 1000); // in milliseconds
106 Date date = new Date(stamp.getTime());
107 SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
108 sdf.setTimeZone(TimeZone.getDefault());
109 String formattedDate = sdf.format(date);
110 return formattedDate;
111
112 }
113
114 public String getDurationString() {
115
116 long duration = call_end - call_start;
117 if (duration < 60)
118 return String.format(Locale.getDefault(), "%02d secs", duration);
119
120 if (duration < 3600)
121 return String.format(Locale.getDefault(), "%02d mins %02d secs", (duration % 3600) / 60, (duration % 60));
122
123 return String.format(Locale.getDefault(), "%d h %02d mins %02d secs", duration / 3600, (duration % 3600) / 60, (duration % 60));
124
125 }
126
127 public long getDuration() {
128 return call_end - call_start;
129 }
130
131 public String getRecordPath() {
132 return recordPath;
133 }
134
135 public String getNumber() {
136 return number;
137 }
138
139 @Override
140 public int describeContents() {
141 return 0;
142 }
143
144 @Override
145 public void writeToParcel(Parcel dest, int flags) {
146 dest.writeLong(call_start);
147 dest.writeLong(call_end);
148 dest.writeString(accountID);
149 dest.writeString(number);
150 dest.writeByte((byte) (missed ? 1 : 0));
151 dest.writeString(direction);
152 dest.writeString(recordPath);
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500153 dest.writeLong(contactID);
154 dest.writeLong(callID);
155 }
156
157 public static final Parcelable.Creator<HistoryCall> CREATOR = new Parcelable.Creator<HistoryCall>() {
158 public HistoryCall createFromParcel(Parcel in) {
159 return new HistoryCall(in);
160 }
161
162 public HistoryCall[] newArray(int size) {
163 return new HistoryCall[size];
164 }
165 };
166
167 private HistoryCall(Parcel in) {
168 call_start = in.readLong();
169 call_end = in.readLong();
170 accountID = in.readString();
171 number = in.readString();
172 missed = in.readByte() == 1 ? true : false;
173 direction = in.readString();
174 recordPath = in.readString();
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500175 contactID = in.readLong();
176 callID = in.readLong();
177 }
178
179 public boolean hasRecord() {
180 return recordPath.length() > 0;
181 }
182
183 public boolean isIncoming() {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500184 return true;
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500185 }
186
187 public boolean isMissed() {
188 return missed;
189 }
190
Alexandre Lisionaad014e2014-01-14 17:45:49 -0500191}