alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 1 | /* |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 3 | * |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 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 | package com.savoirfairelinux.sflphone.fragments; |
| 32 | |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 33 | import java.text.SimpleDateFormat; |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 34 | import java.util.ArrayList; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 35 | import java.util.Date; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 36 | import java.util.HashMap; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 37 | import java.util.Locale; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 38 | import java.util.Observable; |
| 39 | import java.util.Observer; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 40 | import java.util.TimeZone; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 41 | |
| 42 | import android.app.Activity; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 43 | import android.app.Fragment; |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 44 | import android.content.Context; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 45 | import android.os.Bundle; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 46 | import android.os.Handler; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 47 | import android.os.RemoteException; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 48 | import android.os.SystemClock; |
| 49 | import android.text.format.DateFormat; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 50 | import android.util.Log; |
| 51 | import android.view.LayoutInflater; |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 52 | import android.view.Menu; |
| 53 | import android.view.MenuInflater; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 54 | import android.view.View; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 55 | import android.view.ViewGroup; |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 56 | import android.widget.AdapterView; |
| 57 | import android.widget.AdapterView.OnItemClickListener; |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 58 | import android.widget.BaseAdapter; |
Alexandre Lision | 573045c | 2013-09-11 17:20:25 -0400 | [diff] [blame] | 59 | import android.widget.ListView; |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 60 | import android.widget.TextView; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 61 | |
| 62 | import com.savoirfairelinux.sflphone.R; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.model.CallTimer; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 64 | import com.savoirfairelinux.sflphone.model.Conference; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 65 | import com.savoirfairelinux.sflphone.model.SipCall; |
| 66 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 67 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 68 | public class HomeFragment extends Fragment { |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 69 | private static final String TAG = HomeFragment.class.getSimpleName(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 70 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 71 | private Callbacks mCallbacks = sDummyCallbacks; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 72 | // Button access_calls; |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 73 | TextView nb_calls, nb_confs; |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 74 | CallListAdapter confs_adapter; |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 75 | CallTimer timer; |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 76 | |
| 77 | private CallListAdapter calls_adapter; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 78 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 79 | /** |
| 80 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 81 | */ |
| 82 | private static Callbacks sDummyCallbacks = new Callbacks() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 83 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 84 | @Override |
| 85 | public ISipService getService() { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 86 | Log.i(TAG, "I'm a dummy"); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 87 | return null; |
| 88 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 89 | |
| 90 | @Override |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 91 | public void selectedCall(Conference c) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 92 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 93 | }; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 94 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 95 | /** |
| 96 | * The Activity calling this fragment has to implement this interface |
| 97 | * |
| 98 | */ |
| 99 | public interface Callbacks { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 100 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 101 | public ISipService getService(); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 102 | |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 103 | public void selectedCall(Conference c); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 104 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 105 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 106 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 107 | @Override |
| 108 | public void onAttach(Activity activity) { |
| 109 | super.onAttach(activity); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 110 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 111 | if (!(activity instanceof Callbacks)) { |
| 112 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 113 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 114 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 115 | mCallbacks = (Callbacks) activity; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 116 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 117 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 118 | |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 119 | private Runnable mUpdateTimeTask = new Runnable() { |
| 120 | public void run() { |
| 121 | final long start = SystemClock.uptimeMillis(); |
| 122 | long millis = SystemClock.uptimeMillis() - start; |
| 123 | int seconds = (int) (millis / 1000); |
| 124 | int minutes = seconds / 60; |
| 125 | seconds = seconds % 60; |
| 126 | |
| 127 | calls_adapter.notifyDataSetChanged(); |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 128 | confs_adapter.notifyDataSetChanged(); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 129 | mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000)); |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | private Handler mHandler = new Handler(); |
| 134 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 135 | @Override |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 136 | public void onResume() { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 137 | super.onResume(); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 138 | if (mCallbacks.getService() != null) { |
| 139 | try { |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 140 | updateLists(); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 141 | if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) { |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 142 | mHandler.postDelayed(mUpdateTimeTask, 0); |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 143 | } |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 144 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 145 | } catch (RemoteException e) { |
| 146 | Log.e(TAG, e.toString()); |
| 147 | } |
| 148 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 149 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 150 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 151 | |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 152 | public void updateLists() throws RemoteException { |
| 153 | HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); |
| 154 | HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); |
| 155 | |
| 156 | updateCallList(calls); |
| 157 | updateConferenceList(confs); |
| 158 | } |
| 159 | |
Alexandre Lision | 573045c | 2013-09-11 17:20:25 -0400 | [diff] [blame] | 160 | private void updateConferenceList(HashMap<String, Conference> confs) { |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 161 | nb_confs.setText("" + confs.size()); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 162 | confs_adapter.updateDataset(new ArrayList<Conference>(confs.values())); |
Alexandre Lision | 573045c | 2013-09-11 17:20:25 -0400 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | private void updateCallList(HashMap<String, SipCall> calls) { |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 166 | nb_calls.setText("" + calls.size()); |
| 167 | ArrayList<Conference> conferences = new ArrayList<Conference>(); |
| 168 | for (SipCall call : calls.values()) { |
| 169 | Log.w(TAG, "SimpleCall:" + call.getCallId()); |
| 170 | Conference confOne = new Conference("-1"); |
| 171 | confOne.getParticipants().add(call); |
| 172 | conferences.add(confOne); |
| 173 | } |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 174 | |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 175 | calls_adapter.updateDataset(conferences); |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 176 | |
Alexandre Lision | 573045c | 2013-09-11 17:20:25 -0400 | [diff] [blame] | 177 | } |
| 178 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 179 | @Override |
| 180 | public void onDetach() { |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 181 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 182 | super.onDetach(); |
| 183 | mCallbacks = sDummyCallbacks; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 184 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 185 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 186 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 187 | @Override |
| 188 | public void onCreate(Bundle savedInstanceState) { |
| 189 | super.onCreate(savedInstanceState); |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public void onPause(){ |
| 194 | super.onPause(); |
| 195 | mHandler.removeCallbacks(mUpdateTimeTask); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 196 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 197 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 198 | @Override |
| 199 | public void onActivityCreated(Bundle savedInstanceState) { |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 200 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 201 | super.onActivityCreated(savedInstanceState); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 202 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 203 | // Give some text to display if there is no data. In a real |
| 204 | // application this would come from a resource. |
| 205 | // setEmptyText("No phone numbers"); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 206 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 207 | // We have a menu item to show in action bar. |
| 208 | setHasOptionsMenu(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 209 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 210 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 211 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 212 | @Override |
| 213 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 214 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 215 | inflater.inflate(R.menu.call_element_menu, menu); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 216 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 217 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 218 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 219 | @Override |
| 220 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 221 | Log.i(TAG, "onCreateView"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 222 | View inflatedView = inflater.inflate(R.layout.frag_home, container, false); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 223 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 224 | nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter); |
| 225 | nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter); |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 226 | |
| 227 | confs_adapter = new CallListAdapter(getActivity()); |
| 228 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 229 | |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 230 | calls_adapter = new CallListAdapter(getActivity()); |
| 231 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 232 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener); |
| 233 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 234 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 235 | return inflatedView; |
| 236 | } |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 237 | |
| 238 | OnItemClickListener callClickListener = new OnItemClickListener() { |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 239 | |
| 240 | @Override |
| 241 | public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) { |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 242 | mCallbacks.selectedCall((Conference) v.getTag()); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 243 | } |
| 244 | }; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 245 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 246 | public class CallListAdapter extends BaseAdapter implements Observer { |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 247 | |
| 248 | private ArrayList<Conference> calls; |
| 249 | |
| 250 | private Context mContext; |
| 251 | |
| 252 | public CallListAdapter(Context act) { |
| 253 | super(); |
| 254 | mContext = act; |
| 255 | calls = new ArrayList<Conference>(); |
| 256 | |
| 257 | } |
| 258 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 259 | public ArrayList<Conference> getDataset() { |
| 260 | return calls; |
| 261 | } |
| 262 | |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 263 | public void remove(Conference transfer) { |
| 264 | |
| 265 | } |
| 266 | |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 267 | public void updateDataset(ArrayList<Conference> list) { |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 268 | calls.clear(); |
| 269 | calls.addAll(list); |
| 270 | notifyDataSetChanged(); |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public int getCount() { |
| 275 | return calls.size(); |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public Conference getItem(int position) { |
| 280 | return calls.get(position); |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | public long getItemId(int position) { |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | @Override |
| 289 | public View getView(int position, View convertView, ViewGroup parent) { |
| 290 | if (convertView == null) |
| 291 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null); |
| 292 | |
| 293 | Conference call = calls.get(position); |
| 294 | if (call.getParticipants().size() == 1) { |
| 295 | ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName()); |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 296 | |
| 297 | long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start()); |
| 298 | |
| 299 | ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration/3600, (duration%3600)/60, (duration%60))); |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 300 | } else { |
| 301 | String tmp = "Conference with " + call.getParticipants().size() + " participants"; |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 302 | ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp); |
| 303 | } |
| 304 | // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size()); |
| 305 | ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState()); |
| 306 | |
| 307 | convertView.setTag(call); |
| 308 | return convertView; |
| 309 | } |
| 310 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 311 | @Override |
| 312 | public void update(Observable observable, Object data) { |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 313 | Log.i(TAG, "Updating views..."); |
| 314 | notifyDataSetChanged(); |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 317 | } |
| 318 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 319 | } |