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