Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 1 | /* |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 5 | * Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | * |
| 21 | * Additional permission under GNU GPL version 3 section 7: |
| 22 | * |
| 23 | * If you modify this program, or any covered work, by linking or |
| 24 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 25 | * modified version of that library), containing parts covered by the |
| 26 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 27 | * grants you additional permission to convey the resulting work. |
| 28 | * Corresponding Source for a non-source form of such a combination |
| 29 | * shall include the source code for the parts of OpenSSL used as well |
| 30 | * as that of the covered work. |
| 31 | */ |
| 32 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 33 | package org.sflphone.fragments; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 34 | |
| 35 | import java.util.ArrayList; |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 36 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 37 | import org.sflphone.R; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 38 | import org.sflphone.account.AccountDetailAdvanced; |
| 39 | import org.sflphone.account.AccountDetailBasic; |
| 40 | import org.sflphone.account.AccountDetailSrtp; |
| 41 | import org.sflphone.account.AccountDetailTls; |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 42 | import org.sflphone.client.AccountEditionActivity; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 43 | import org.sflphone.client.AccountWizard; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 44 | import org.sflphone.interfaces.AccountsInterface; |
| 45 | import org.sflphone.loaders.AccountsLoader; |
| 46 | import org.sflphone.loaders.LoaderConstants; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 47 | import org.sflphone.model.Account; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 48 | import org.sflphone.receivers.AccountsReceiver; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 49 | import org.sflphone.service.ConfigurationManagerCallback; |
| 50 | import org.sflphone.service.ISipService; |
| 51 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 52 | import android.app.Activity; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 53 | import android.app.ListFragment; |
| 54 | import android.app.LoaderManager.LoaderCallbacks; |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 55 | import android.content.Context; |
Alexandre Savard | 53d2ddd | 2012-09-30 22:04:40 -0400 | [diff] [blame] | 56 | import android.content.Intent; |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 57 | import android.content.IntentFilter; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 58 | import android.content.Loader; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 59 | import android.os.Bundle; |
| 60 | import android.os.RemoteException; |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 61 | import android.util.Log; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 62 | import android.view.LayoutInflater; |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 63 | import android.view.Menu; |
| 64 | import android.view.MenuInflater; |
| 65 | import android.view.MenuItem; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 66 | import android.view.View; |
| 67 | import android.view.ViewGroup; |
| 68 | import android.widget.AdapterView; |
| 69 | import android.widget.AdapterView.OnItemClickListener; |
| 70 | import android.widget.BaseAdapter; |
| 71 | import android.widget.CheckBox; |
| 72 | import android.widget.CompoundButton; |
| 73 | import android.widget.CompoundButton.OnCheckedChangeListener; |
| 74 | import android.widget.TextView; |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 75 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 76 | public class AccountManagementFragment extends ListFragment implements LoaderCallbacks<ArrayList<Account>>, AccountsInterface { |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 77 | static final String TAG = "AccountManagementFragment"; |
Alexandre Savard | a6c0d99 | 2012-09-28 09:24:13 -0400 | [diff] [blame] | 78 | static final String DEFAULT_ACCOUNT_ID = "IP2IP"; |
Alexandre Savard | 53d2ddd | 2012-09-30 22:04:40 -0400 | [diff] [blame] | 79 | static final int ACCOUNT_CREATE_REQUEST = 1; |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 80 | static final int ACCOUNT_EDIT_REQUEST = 2; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 81 | AccountsReceiver accountReceiver; |
| 82 | AccountsAdapter mAdapter; |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 83 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 84 | private Callbacks mCallbacks = sDummyCallbacks; |
| 85 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 86 | |
| 87 | @Override |
| 88 | public ISipService getService() { |
| 89 | return null; |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | public interface Callbacks { |
| 94 | |
| 95 | public ISipService getService(); |
| 96 | |
| 97 | } |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 98 | |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 99 | @Override |
| 100 | public void onAttach(Activity activity) { |
| 101 | super.onAttach(activity); |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 102 | if (!(activity instanceof Callbacks)) { |
| 103 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 104 | } |
| 105 | |
| 106 | mCallbacks = (Callbacks) activity; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame^] | 107 | getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this); |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 108 | } |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 109 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 110 | @Override |
| 111 | public void onDetach() { |
| 112 | super.onDetach(); |
| 113 | mCallbacks = sDummyCallbacks; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 114 | } |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 115 | |
| 116 | @Override |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 117 | public void onCreate(Bundle savedInstanceState) { |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 118 | super.onCreate(savedInstanceState); |
| 119 | |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 120 | Log.i(TAG, "Create Account Management Fragment"); |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 121 | mAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>()); |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 122 | this.setHasOptionsMenu(true); |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 123 | accountReceiver = new AccountsReceiver(this); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame^] | 124 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 125 | } |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 126 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 127 | @Override |
| 128 | public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { |
| 129 | View inflatedView = inflater.inflate(android.R.layout.list_content, parent, false); |
| 130 | setListAdapter(mAdapter); |
| 131 | return inflatedView; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void onViewCreated(View view, Bundle savedInstanceState) { |
| 136 | super.onViewCreated(view, savedInstanceState); |
| 137 | getListView().setOnItemClickListener(new OnItemClickListener() { |
| 138 | |
| 139 | @Override |
| 140 | public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 141 | launchAccountEditActivity(mAdapter.getItem(pos)); |
Emeric Vigier | 0038a61 | 2012-11-06 18:51:19 -0500 | [diff] [blame] | 142 | } |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 143 | }); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 144 | |
| 145 | setEmptyText(getResources().getString(R.string.empty_account_list)); |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 146 | } |
| 147 | |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 148 | @Override |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 149 | public void onPause() { |
| 150 | super.onPause(); |
| 151 | getActivity().unregisterReceiver(accountReceiver); |
Alexandre Savard | 8b7d433 | 2012-09-30 20:02:11 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 154 | public void onResume() { |
| 155 | super.onResume(); |
| 156 | IntentFilter intentFilter2 = new IntentFilter(); |
| 157 | intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED); |
| 158 | intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED); |
| 159 | getActivity().registerReceiver(accountReceiver, intentFilter2); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame^] | 160 | |
| 161 | getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this); |
| 162 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 163 | } |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 164 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 165 | @Override |
| 166 | public Loader<ArrayList<Account>> onCreateLoader(int id, Bundle args) { |
| 167 | AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService()); |
| 168 | l.forceLoad(); |
| 169 | return l; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void onLoadFinished(Loader<ArrayList<Account>> loader, ArrayList<Account> results) { |
| 174 | mAdapter.removeAll(); |
| 175 | mAdapter.addAll(results); |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void onLoaderReset(Loader<ArrayList<Account>> arg0) { |
| 180 | // TODO Auto-generated method stub |
| 181 | |
| 182 | } |
| 183 | |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 184 | @Override |
| 185 | public void onCreateOptionsMenu(Menu m, MenuInflater inf) { |
| 186 | super.onCreateOptionsMenu(m, inf); |
| 187 | inf.inflate(R.menu.account_creation, m); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public boolean onOptionsItemSelected(MenuItem item) { |
| 192 | super.onOptionsItemSelected(item); |
| 193 | switch (item.getItemId()) { |
| 194 | case R.id.menuitem_create: |
| 195 | Intent intent = new Intent().setClass(getActivity(), AccountWizard.class); |
| 196 | startActivityForResult(intent, ACCOUNT_CREATE_REQUEST); |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | return true; |
| 201 | } |
| 202 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 203 | private void launchAccountEditActivity(Account acc) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 204 | Log.i(TAG, "Launch account edit activity"); |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 205 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 206 | Intent intent = new Intent().setClass(getActivity(), AccountEditionActivity.class); |
| 207 | Bundle bundle = new Bundle(); |
| 208 | bundle.putString("AccountID", acc.getAccountID()); |
| 209 | bundle.putStringArrayList(AccountDetailBasic.BUNDLE_TAG, acc.getBasicDetails().getValuesOnly()); |
| 210 | bundle.putStringArrayList(AccountDetailAdvanced.BUNDLE_TAG, acc.getAdvancedDetails().getValuesOnly()); |
| 211 | bundle.putStringArrayList(AccountDetailSrtp.BUNDLE_TAG, acc.getSrtpDetails().getValuesOnly()); |
| 212 | bundle.putStringArrayList(AccountDetailTls.BUNDLE_TAG, acc.getTlsDetails().getValuesOnly()); |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 213 | |
| 214 | intent.putExtras(bundle); |
| 215 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 216 | startActivityForResult(intent, ACCOUNT_EDIT_REQUEST); |
| 217 | } |
| 218 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 219 | @Override |
| 220 | public void accountsChanged() { |
| 221 | if (getActivity() != null) |
| 222 | getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this); |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 223 | } |
| 224 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 225 | @Override |
| 226 | public void accountStateChanged(Intent accountState) { |
| 227 | mAdapter.updateAccount(accountState); |
Alexandre Savard | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 230 | /** |
| 231 | * |
| 232 | * Adapter for accounts List |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 233 | * |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 234 | * @author lisional |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 235 | * |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 236 | */ |
| 237 | public class AccountsAdapter extends BaseAdapter { |
Alexandre Savard | 52a7252 | 2012-09-27 16:40:13 -0400 | [diff] [blame] | 238 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 239 | // private static final String TAG = AccountSelectionAdapter.class.getSimpleName(); |
Alexandre Savard | 7098201 | 2012-09-27 17:15:50 -0400 | [diff] [blame] | 240 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 241 | ArrayList<Account> accounts; |
| 242 | Context mContext; |
Alexandre Savard | 7098201 | 2012-09-27 17:15:50 -0400 | [diff] [blame] | 243 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 244 | public AccountsAdapter(Context cont, ArrayList<Account> newList) { |
| 245 | super(); |
| 246 | accounts = newList; |
| 247 | mContext = cont; |
Alexandre Savard | e990d05 | 2012-10-18 14:43:09 -0400 | [diff] [blame] | 248 | } |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 249 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 250 | @Override |
| 251 | public int getCount() { |
| 252 | return accounts.size(); |
| 253 | } |
Alexandre Savard | 7098201 | 2012-09-27 17:15:50 -0400 | [diff] [blame] | 254 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 255 | @Override |
| 256 | public Account getItem(int pos) { |
| 257 | return accounts.get(pos); |
| 258 | } |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 259 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 260 | @Override |
| 261 | public long getItemId(int pos) { |
| 262 | return 0; |
| 263 | } |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 264 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 265 | @Override |
| 266 | public View getView(final int pos, View convertView, ViewGroup parent) { |
| 267 | View rowView = convertView; |
| 268 | AccountView entryView = null; |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 269 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 270 | if (rowView == null) { |
| 271 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 272 | rowView = inflater.inflate(R.layout.item_account_pref, null); |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 273 | |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 274 | entryView = new AccountView(); |
| 275 | entryView.alias = (TextView) rowView.findViewById(R.id.account_alias); |
| 276 | entryView.host = (TextView) rowView.findViewById(R.id.account_host); |
| 277 | entryView.enabled = (CheckBox) rowView.findViewById(R.id.account_checked); |
| 278 | rowView.setTag(entryView); |
| 279 | } else { |
| 280 | entryView = (AccountView) rowView.getTag(); |
| 281 | } |
| 282 | |
| 283 | entryView.alias.setText(accounts.get(pos).getAlias()); |
| 284 | entryView.host.setText(accounts.get(pos).getHost() + " - " + accounts.get(pos).getRegistered_state()); |
| 285 | entryView.enabled.setChecked(accounts.get(pos).isEnabled()); |
| 286 | |
| 287 | entryView.enabled.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 288 | |
| 289 | @Override |
| 290 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 291 | accounts.get(pos).setEnabled(isChecked); |
| 292 | |
| 293 | try { |
| 294 | mCallbacks.getService().setAccountDetails(accounts.get(pos).getAccountID(), accounts.get(pos).getDetails()); |
| 295 | } catch (RemoteException e) { |
| 296 | e.printStackTrace(); |
| 297 | } |
| 298 | } |
| 299 | }); |
| 300 | |
| 301 | return rowView; |
| 302 | } |
| 303 | |
| 304 | /********************* |
| 305 | * ViewHolder Pattern |
| 306 | *********************/ |
| 307 | public class AccountView { |
| 308 | public TextView alias; |
| 309 | public TextView host; |
| 310 | public CheckBox enabled; |
| 311 | } |
| 312 | |
| 313 | public void removeAll() { |
| 314 | accounts.clear(); |
| 315 | notifyDataSetChanged(); |
| 316 | |
| 317 | } |
| 318 | |
| 319 | public void addAll(ArrayList<Account> results) { |
| 320 | accounts.addAll(results); |
| 321 | notifyDataSetChanged(); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Modify state of specific account |
| 326 | * |
| 327 | * @param accountState |
| 328 | */ |
| 329 | public void updateAccount(Intent accountState) { |
| 330 | Log.i(TAG, "updateAccount"); |
| 331 | String id = accountState.getStringExtra("Account"); |
| 332 | String newState = accountState.getStringExtra("state"); |
| 333 | accountState.getStringExtra("Account"); |
| 334 | |
| 335 | for (Account a : accounts) { |
| 336 | if (a.getAccountID().contentEquals(id)) { |
| 337 | a.setRegistered_state(newState); |
| 338 | notifyDataSetChanged(); |
| 339 | return; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | } |
| 344 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 345 | } |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 346 | } |