blob: bc1c0de060c368ef1e3a4bb14109564d1203982f [file] [log] [blame]
alision2ec64f92013-06-17 17:28:58 -04001package com.savoirfairelinux.sflphone.model;
2
3import java.text.SimpleDateFormat;
4import java.util.ArrayList;
5import java.util.Calendar;
6import java.util.Locale;
7import java.util.NavigableMap;
8import java.util.TimeZone;
9import java.util.TreeMap;
10
alision907bde72013-06-20 14:40:37 -040011import com.savoirfairelinux.sflphone.service.ServiceConstants;
12
alision2ec64f92013-06-17 17:28:58 -040013public class HistoryEntry {
14
15 private CallContact contact;
16 private NavigableMap<Long, HistoryCall> calls;
17 private String accountID;
alision907bde72013-06-20 14:40:37 -040018 int missed_sum;
19 int outgoing_sum;
20 int incoming_sum;
alision2ec64f92013-06-17 17:28:58 -040021
alision907bde72013-06-20 14:40:37 -040022
23
24 public HistoryEntry(String account, CallContact c) {
25 contact = c;
26 calls = new TreeMap<Long, HistoryEntry.HistoryCall>();
27 accountID = account;
28 missed_sum = outgoing_sum = incoming_sum = 0;
29 }
30
alision2ec64f92013-06-17 17:28:58 -040031 public String getAccountID() {
32 return accountID;
33 }
34
35 public void setAccountID(String accountID) {
36 this.accountID = accountID;
37 }
38
39 public NavigableMap<Long, HistoryCall> getCalls() {
40 return calls;
41 }
42
alision2ec64f92013-06-17 17:28:58 -040043 public static class HistoryCall {
44 long call_start;
45 long call_end;
46 String number;
alision907bde72013-06-20 14:40:37 -040047 String state;
alision50fa0722013-06-25 17:29:44 -040048 String recordPath;
alision2ec64f92013-06-17 17:28:58 -040049
alision907bde72013-06-20 14:40:37 -040050 public String getState() {
51 return state;
52 }
53
alision50fa0722013-06-25 17:29:44 -040054 public HistoryCall(long start, long end, String n, String s, String path) {
alision2ec64f92013-06-17 17:28:58 -040055 call_start = start;
56 call_end = end;
57 number = n;
alision907bde72013-06-20 14:40:37 -040058 state = s;
alision50fa0722013-06-25 17:29:44 -040059 recordPath = path;
alision2ec64f92013-06-17 17:28:58 -040060 }
61
62 public String getDate(String format) {
63 Calendar cal = Calendar.getInstance();
64 TimeZone tz = cal.getTimeZone();
65 SimpleDateFormat objFormatter = new SimpleDateFormat(format, Locale.CANADA);
66 objFormatter.setTimeZone(tz);
67
68 Calendar objCalendar = Calendar.getInstance(tz);
69 objCalendar.setTimeInMillis(call_start * 1000);
70 String result = objFormatter.format(objCalendar.getTime());
71 objCalendar.clear();
72 return result;
73 }
74
75 public String getDurationString() {
76 long duration = call_end - call_start;
77 if (duration < 60)
78 return duration + "s";
79
80 return duration / 60 + "min";
81
82 }
83
84 public long getDuration() {
85 return call_end - call_start;
86
87 }
88
alision50fa0722013-06-25 17:29:44 -040089 public String getRecordPath() {
90 return recordPath;
91 }
92
93 public void setRecordPath(String recordPath) {
94 this.recordPath = recordPath;
95 }
96
alision2ec64f92013-06-17 17:28:58 -040097 }
98
99 public CallContact getContact() {
100 return contact;
101 }
102
103 public void setContact(CallContact contact) {
104 this.contact = contact;
105 }
106
107 public void addHistoryCall(HistoryCall historyCall) {
108 calls.put(historyCall.call_start, historyCall);
Alexandre Lision6711ab22013-09-16 15:15:38 -0400109 if(historyCall.getState().contentEquals(ServiceConstants.history.MISSED_STRING)){
alision907bde72013-06-20 14:40:37 -0400110 ++missed_sum;
Alexandre Lision6711ab22013-09-16 15:15:38 -0400111 } else if(historyCall.getState().contentEquals(ServiceConstants.history.INCOMING_STRING)){
alision907bde72013-06-20 14:40:37 -0400112 ++incoming_sum;
113 } else {
114 ++outgoing_sum;
115 }
alision2ec64f92013-06-17 17:28:58 -0400116 }
117
118 public String getNumber() {
119 return calls.lastEntry().getValue().number;
120 }
121
122 public String getTotalDuration() {
123 int duration = 0;
124 ArrayList<HistoryCall> all_calls = new ArrayList<HistoryEntry.HistoryCall>(calls.values());
125 for(int i = 0 ; i < all_calls.size() ; ++i){
126 duration += all_calls.get(i).getDuration();
127 }
128
129 if (duration < 60)
130 return duration + "s";
131
132 return duration / 60 + "min";
133 }
alision907bde72013-06-20 14:40:37 -0400134
135 public int getMissed_sum() {
136 return missed_sum;
137 }
138
139 public int getOutgoing_sum() {
140 return outgoing_sum;
141 }
142
143 public int getIncoming_sum() {
144 return incoming_sum;
145 }
alision2ec64f92013-06-17 17:28:58 -0400146}