blob: 05d35919f6f446caee908fcdf42130047a2caa67 [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;
38import org.sflphone.service.ServiceConstants;
39
40import java.sql.Timestamp;
41import java.text.SimpleDateFormat;
42import java.util.Date;
43import java.util.HashMap;
44import java.util.Locale;
45import java.util.TimeZone;
46
47public class HistoryCall implements Parcelable {
48
49 public long getCallStart() {
50 return call_start;
51 }
52
53 @DatabaseField(index = true)
54 long call_start;
55 @DatabaseField
56 long call_end;
57 @DatabaseField
58 String number;
59 @DatabaseField
60 boolean missed;
61 @DatabaseField
62 String direction;
63 @DatabaseField
64 String recordPath;
65 @DatabaseField
66 String timeFormatted;
67
68 public String getAccountID() {
69 return accountID;
70 }
71
72 @DatabaseField
73 String accountID;
74
75 public long getContactID() {
76 return contactID;
77 }
78
79 @DatabaseField
80 long contactID;
81 @DatabaseField
82 long callID;
83
Alexandre Lisionb4e60612014-01-14 17:47:23 -050084 /* Needed by ORMLite */
85 public HistoryCall() {
86 }
87
88 public String getDirection() {
89 return direction;
90 }
91
92 public String getDate() {
93 return timeFormatted;
94 }
95
96 public String getStartString(String format) {
97 Timestamp stamp = new Timestamp(call_start * 1000); // in milliseconds
98 Date date = new Date(stamp.getTime());
99 SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
100 sdf.setTimeZone(TimeZone.getDefault());
101 String formattedDate = sdf.format(date);
102 return formattedDate;
103
104 }
105
106 public String getDurationString() {
107
108 long duration = call_end - call_start;
109 if (duration < 60)
110 return String.format(Locale.getDefault(), "%02d secs", duration);
111
112 if (duration < 3600)
113 return String.format(Locale.getDefault(), "%02d mins %02d secs", (duration % 3600) / 60, (duration % 60));
114
115 return String.format(Locale.getDefault(), "%d h %02d mins %02d secs", duration / 3600, (duration % 3600) / 60, (duration % 60));
116
117 }
118
119 public long getDuration() {
120 return call_end - call_start;
121 }
122
123 public String getRecordPath() {
124 return recordPath;
125 }
126
127 public String getNumber() {
128 return number;
129 }
130
131 @Override
132 public int describeContents() {
133 return 0;
134 }
135
136 @Override
137 public void writeToParcel(Parcel dest, int flags) {
138 dest.writeLong(call_start);
139 dest.writeLong(call_end);
140 dest.writeString(accountID);
141 dest.writeString(number);
142 dest.writeByte((byte) (missed ? 1 : 0));
143 dest.writeString(direction);
144 dest.writeString(recordPath);
145 dest.writeString(timeFormatted);
146 dest.writeLong(contactID);
147 dest.writeLong(callID);
148 }
149
150 public static final Parcelable.Creator<HistoryCall> CREATOR = new Parcelable.Creator<HistoryCall>() {
151 public HistoryCall createFromParcel(Parcel in) {
152 return new HistoryCall(in);
153 }
154
155 public HistoryCall[] newArray(int size) {
156 return new HistoryCall[size];
157 }
158 };
159
160 private HistoryCall(Parcel in) {
161 call_start = in.readLong();
162 call_end = in.readLong();
163 accountID = in.readString();
164 number = in.readString();
165 missed = in.readByte() == 1 ? true : false;
166 direction = in.readString();
167 recordPath = in.readString();
168 timeFormatted = in.readString();
169 contactID = in.readLong();
170 callID = in.readLong();
171 }
172
173 public boolean hasRecord() {
174 return recordPath.length() > 0;
175 }
176
177 public boolean isIncoming() {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500178 return true;
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500179 }
180
181 public boolean isMissed() {
182 return missed;
183 }
184
Alexandre Lisionaad014e2014-01-14 17:45:49 -0500185}