blob: 49289a8ab485b5d3b50d71ba2fefc960cf06fbc6 [file] [log] [blame]
Alexandre Savard2b370f02012-09-06 16:06:01 -04001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Savard2b370f02012-09-06 16:06:01 -04003 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
alision5cfc35d2013-07-11 15:11:39 -04005 * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Alexandre Savard2b370f02012-09-06 16:06:01 -04006 *
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 Lision064e1e02013-10-01 16:18:42 -040033package org.sflphone.fragments;
alisionf76de3b2013-04-16 15:35:22 -040034
Alexandre Lision4cf78702013-10-16 13:43:23 -040035import java.io.File;
alisionf76de3b2013-04-16 15:35:22 -040036import java.util.ArrayList;
Alexandre Savard2b370f02012-09-06 16:06:01 -040037
Alexandre Lisionb4e60612014-01-14 17:47:23 -050038import android.app.ListFragment;
39import android.app.LoaderManager;
40import android.content.*;
Alexandre Lision064e1e02013-10-01 16:18:42 -040041import org.sflphone.R;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -040042import org.sflphone.client.AccountEditionActivity;
Alexandre Lision064e1e02013-10-01 16:18:42 -040043import org.sflphone.client.AccountWizard;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040044import org.sflphone.interfaces.AccountsInterface;
45import org.sflphone.loaders.AccountsLoader;
46import org.sflphone.loaders.LoaderConstants;
Alexandre Lision064e1e02013-10-01 16:18:42 -040047import org.sflphone.model.Account;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040048import org.sflphone.receivers.AccountsReceiver;
Alexandre Lision064e1e02013-10-01 16:18:42 -040049import org.sflphone.service.ConfigurationManagerCallback;
50import org.sflphone.service.ISipService;
Alexandre Lision7f0bba52013-10-16 14:43:11 -040051import org.sflphone.views.dragsortlv.DragSortListView;
Alexandre Lision064e1e02013-10-01 16:18:42 -040052
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040053import android.animation.Animator;
54import android.animation.AnimatorListenerAdapter;
Alexandre Savard9a93f062012-09-11 10:42:43 -040055import android.app.Activity;
alisionf76de3b2013-04-16 15:35:22 -040056import android.os.Bundle;
57import android.os.RemoteException;
Alexandre Savard2b370f02012-09-06 16:06:01 -040058import android.util.Log;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040059import android.view.LayoutInflater;
Alexandre Lisiona764c682013-09-09 10:02:07 -040060import android.view.Menu;
61import android.view.MenuInflater;
62import android.view.MenuItem;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040063import android.view.View;
Alexandre Lision059da9d2013-10-22 11:17:25 -040064import android.view.View.OnClickListener;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040065import android.view.ViewGroup;
66import android.widget.AdapterView;
67import android.widget.AdapterView.OnItemClickListener;
68import android.widget.BaseAdapter;
69import android.widget.CheckBox;
Alexandre Lision230d66e2013-10-22 12:32:12 -040070import android.widget.ListView;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040071import android.widget.TextView;
Alexandre Savard2b370f02012-09-06 16:06:01 -040072
Alexandre Lisionb4e60612014-01-14 17:47:23 -050073public class AccountsManagementFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Bundle>, AccountsInterface {
Alexandre Savard2b370f02012-09-06 16:06:01 -040074 static final String TAG = "AccountManagementFragment";
Alexandre Savarda6c0d992012-09-28 09:24:13 -040075 static final String DEFAULT_ACCOUNT_ID = "IP2IP";
Alexandre Savard53d2ddd2012-09-30 22:04:40 -040076 static final int ACCOUNT_CREATE_REQUEST = 1;
Alexandre Lision420b2572014-01-10 11:37:18 -050077 public static final int ACCOUNT_EDIT_REQUEST = 2;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040078 AccountsReceiver accountReceiver;
Alexandre Lision230d66e2013-10-22 12:32:12 -040079 AccountsAdapter mAccountsAdapter;
80 AccountsAdapter mIP2IPAdapter;
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040081
82 DragSortListView mDnDListView;
83 private View mLoadingView;
84 private int mShortAnimationDuration;
85
Alexandre Lision4cf78702013-10-16 13:43:23 -040086 private DragSortListView.DropListener onDrop = new DragSortListView.DropListener() {
87 @Override
88 public void drop(int from, int to) {
89 if (from != to) {
Alexandre Lision230d66e2013-10-22 12:32:12 -040090 Account item = mAccountsAdapter.getItem(from);
91 mAccountsAdapter.remove(item);
92 mAccountsAdapter.insert(item, to);
Alexandre Lision4cf78702013-10-16 13:43:23 -040093 try {
Alexandre Lision230d66e2013-10-22 12:32:12 -040094 mCallbacks.getService().setAccountOrder(mAccountsAdapter.generateAccountOrder());
Alexandre Lision4cf78702013-10-16 13:43:23 -040095 } catch (RemoteException e) {
96 e.printStackTrace();
97 }
98 }
99 }
100
Alexandre Lision4cf78702013-10-16 13:43:23 -0400101 };
102
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400103 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lision059da9d2013-10-22 11:17:25 -0400104 private Account ip2ip;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400105 private static Callbacks sDummyCallbacks = new Callbacks() {
106
107 @Override
108 public ISipService getService() {
109 return null;
110 }
111 };
112
113 public interface Callbacks {
114
115 public ISipService getService();
116
117 }
Alexandre Savardae992932012-10-17 10:26:12 -0400118
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400119 @Override
120 public void onAttach(Activity activity) {
121 super.onAttach(activity);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400122 if (!(activity instanceof Callbacks)) {
123 throw new IllegalStateException("Activity must implement fragment's callbacks.");
124 }
125
126 mCallbacks = (Callbacks) activity;
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400127 }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400128
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400129 @Override
130 public void onDetach() {
131 super.onDetach();
132 mCallbacks = sDummyCallbacks;
alisiond9e29442013-04-17 16:10:18 -0400133 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400134
135 @Override
alisiond9e29442013-04-17 16:10:18 -0400136 public void onCreate(Bundle savedInstanceState) {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400137 super.onCreate(savedInstanceState);
138
Alexandre Savard9a93f062012-09-11 10:42:43 -0400139 Log.i(TAG, "Create Account Management Fragment");
Alexandre Lision230d66e2013-10-22 12:32:12 -0400140 mAccountsAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400141 mIP2IPAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisiona764c682013-09-09 10:02:07 -0400142 this.setHasOptionsMenu(true);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400143 accountReceiver = new AccountsReceiver(this);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400144
Alexandre Lisionb97c9512014-01-07 17:14:03 -0500145 mShortAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
Alexandre Lision4d20c812013-12-12 17:44:50 -0500146 Log.i(TAG, "anim time: " + mShortAnimationDuration);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400147
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400148 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400149
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400150 @Override
151 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400152 View inflatedView = inflater.inflate(R.layout.frag_accounts_list, parent, false);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400153 setListAdapter(mAccountsAdapter);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400154
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400155 return inflatedView;
156 }
157
158 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -0400159 public DragSortListView getListView() {
160 return (DragSortListView) super.getListView();
161 }
162
163 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400164 public void onViewCreated(View view, Bundle savedInstanceState) {
165 super.onViewCreated(view, savedInstanceState);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400166
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400167 mDnDListView = getListView();
168
169 mDnDListView.setDropListener(onDrop);
170 mDnDListView.setOnItemClickListener(new OnItemClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400171
172 @Override
173 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400174 launchAccountEditActivity(mAccountsAdapter.getItem(pos));
Emeric Vigier0038a612012-11-06 18:51:19 -0500175 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400176 });
Alexandre Lision230d66e2013-10-22 12:32:12 -0400177
178 ((ListView) getView().findViewById(R.id.ip2ip)).setAdapter(mIP2IPAdapter);
179 ((ListView) getView().findViewById(R.id.ip2ip)).setOnItemClickListener(new OnItemClickListener() {
180
Alexandre Lision059da9d2013-10-22 11:17:25 -0400181 @Override
Alexandre Lision230d66e2013-10-22 12:32:12 -0400182 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400183 launchAccountEditActivity(ip2ip);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400184
Alexandre Lision059da9d2013-10-22 11:17:25 -0400185 }
186 });
Alexandre Lision40954dc2013-10-09 15:24:03 -0400187
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400188 mLoadingView = view.findViewById(R.id.loading_spinner);
Alexandre Savard2b370f02012-09-06 16:06:01 -0400189 }
190
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400191 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400192 public void onPause() {
193 super.onPause();
194 getActivity().unregisterReceiver(accountReceiver);
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400195 }
196
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400197 public void onResume() {
198 super.onResume();
199 IntentFilter intentFilter2 = new IntentFilter();
200 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
201 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
202 getActivity().registerReceiver(accountReceiver, intentFilter2);
Alexandre Lisionb97c9512014-01-07 17:14:03 -0500203 getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Lision658999c2013-12-13 14:42:45 -0500204 getActivity().getActionBar().setTitle(R.string.menu_item_accounts);
alisiona4325152013-04-19 11:10:03 -0400205 }
alision73424b62013-04-26 11:49:18 -0400206
Alexandre Lisiona764c682013-09-09 10:02:07 -0400207 @Override
208 public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
209 super.onCreateOptionsMenu(m, inf);
210 inf.inflate(R.menu.account_creation, m);
211 }
212
213 @Override
214 public boolean onOptionsItemSelected(MenuItem item) {
215 super.onOptionsItemSelected(item);
216 switch (item.getItemId()) {
217 case R.id.menuitem_create:
218 Intent intent = new Intent().setClass(getActivity(), AccountWizard.class);
219 startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
220 break;
221 }
222
223 return true;
224 }
225
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400226 private void launchAccountEditActivity(Account acc) {
Alexandre Savard68838112012-10-30 11:34:43 -0400227 Log.i(TAG, "Launch account edit activity");
Alexandre Savard833616f2012-10-30 16:02:30 -0400228
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400229 Intent intent = new Intent().setClass(getActivity(), AccountEditionActivity.class);
230 Bundle bundle = new Bundle();
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400231 bundle.putParcelable("account", acc);
Alexandre Lision059da9d2013-10-22 11:17:25 -0400232
Alexandre Savard833616f2012-10-30 16:02:30 -0400233 intent.putExtras(bundle);
234
Alexandre Savard68838112012-10-30 11:34:43 -0400235 startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
236 }
237
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400238 @Override
239 public void accountsChanged() {
240 if (getActivity() != null)
Alexandre Lisionb97c9512014-01-07 17:14:03 -0500241 getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Savard52a72522012-09-27 16:40:13 -0400242 }
243
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400244 @Override
245 public void accountStateChanged(Intent accountState) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400246 mAccountsAdapter.updateAccount(accountState);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400247 }
248
Alexandre Lision420b2572014-01-10 11:37:18 -0500249 @Override
250 public void onActivityResult(int requestCode, int resultCode, Intent data) {
251 super.onActivityResult(requestCode, resultCode, data);
252 if(resultCode == ACCOUNT_EDIT_REQUEST) {
253 getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
254 }
255 }
256
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400257 /**
258 *
259 * Adapter for accounts List
Alexandre Lision40954dc2013-10-09 15:24:03 -0400260 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400261 * @author lisional
Alexandre Lision40954dc2013-10-09 15:24:03 -0400262 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400263 */
264 public class AccountsAdapter extends BaseAdapter {
Alexandre Savard52a72522012-09-27 16:40:13 -0400265
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400266 // private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
Alexandre Savard70982012012-09-27 17:15:50 -0400267
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400268 ArrayList<Account> accounts;
269 Context mContext;
Alexandre Savard70982012012-09-27 17:15:50 -0400270
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400271 public AccountsAdapter(Context cont, ArrayList<Account> newList) {
272 super();
273 accounts = newList;
274 mContext = cont;
Alexandre Savarde990d052012-10-18 14:43:09 -0400275 }
alisiond9e29442013-04-17 16:10:18 -0400276
Alexandre Lision4cf78702013-10-16 13:43:23 -0400277 public void insert(Account item, int to) {
278 accounts.add(to, item);
279 notifyDataSetChanged();
280 }
281
282 public void remove(Account item) {
283 accounts.remove(item);
284 notifyDataSetChanged();
285 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400286
Alexandre Lision4cf78702013-10-16 13:43:23 -0400287 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400288 public boolean hasStableIds() {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400289 return true;
290 }
291
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400292 @Override
293 public int getCount() {
294 return accounts.size();
295 }
Alexandre Savard70982012012-09-27 17:15:50 -0400296
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400297 @Override
298 public Account getItem(int pos) {
299 return accounts.get(pos);
300 }
Alexandre Savard68838112012-10-30 11:34:43 -0400301
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400302 @Override
303 public long getItemId(int pos) {
304 return 0;
305 }
Alexandre Savard68838112012-10-30 11:34:43 -0400306
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400307 @Override
308 public View getView(final int pos, View convertView, ViewGroup parent) {
309 View rowView = convertView;
310 AccountView entryView = null;
Alexandre Savard68838112012-10-30 11:34:43 -0400311
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400312 if (rowView == null) {
313 LayoutInflater inflater = LayoutInflater.from(mContext);
314 rowView = inflater.inflate(R.layout.item_account_pref, null);
alisiond9e29442013-04-17 16:10:18 -0400315
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400316 entryView = new AccountView();
317 entryView.alias = (TextView) rowView.findViewById(R.id.account_alias);
318 entryView.host = (TextView) rowView.findViewById(R.id.account_host);
319 entryView.enabled = (CheckBox) rowView.findViewById(R.id.account_checked);
320 rowView.setTag(entryView);
321 } else {
322 entryView = (AccountView) rowView.getTag();
323 }
324
Alexandre Lision059da9d2013-10-22 11:17:25 -0400325 final Account item = accounts.get(pos);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400326 entryView.alias.setText(accounts.get(pos).getAlias());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400327 if (item.isIP2IP()) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400328 entryView.host.setText(item.getRegistered_state());
329 entryView.enabled.setVisibility(View.GONE);
330 } else {
331 entryView.host.setText(item.getHost() + " - " + item.getRegistered_state());
332 entryView.enabled.setChecked(item.isEnabled());
333 entryView.enabled.setOnClickListener(new OnClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400334
Alexandre Lision230d66e2013-10-22 12:32:12 -0400335 @Override
336 public void onClick(View v) {
337 item.setEnabled(!item.isEnabled());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400338
Alexandre Lision230d66e2013-10-22 12:32:12 -0400339 try {
340 mCallbacks.getService().setAccountDetails(item.getAccountID(), item.getDetails());
341 } catch (RemoteException e) {
342 e.printStackTrace();
343 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400344 }
Alexandre Lision230d66e2013-10-22 12:32:12 -0400345 });
346 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400347
348 return rowView;
349 }
350
351 /*********************
352 * ViewHolder Pattern
353 *********************/
354 public class AccountView {
355 public TextView alias;
356 public TextView host;
357 public CheckBox enabled;
358 }
359
360 public void removeAll() {
361 accounts.clear();
362 notifyDataSetChanged();
363
364 }
365
366 public void addAll(ArrayList<Account> results) {
367 accounts.addAll(results);
368 notifyDataSetChanged();
369 }
370
371 /**
372 * Modify state of specific account
373 *
374 * @param accountState
375 */
376 public void updateAccount(Intent accountState) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400377 String id = accountState.getStringExtra("Account");
378 String newState = accountState.getStringExtra("state");
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400379
Alexandre Lision4d20c812013-12-12 17:44:50 -0500380 Log.i(TAG, "updateAccount:" + newState);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400381 for (Account a : accounts) {
382 if (a.getAccountID().contentEquals(id)) {
383 a.setRegistered_state(newState);
384 notifyDataSetChanged();
385 return;
386 }
387 }
388
389 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400390
Alexandre Lision4cf78702013-10-16 13:43:23 -0400391 private String generateAccountOrder() {
392 String result = DEFAULT_ACCOUNT_ID + File.separator;
393 for (Account a : accounts) {
394 result += a.getAccountID() + File.separator;
395 }
396 return result;
397 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400398
Alexandre Savard68838112012-10-30 11:34:43 -0400399 }
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400400
401 private void crossfade() {
402
403 // Set the content view to 0% opacity but visible, so that it is visible
404 // (but fully transparent) during the animation.
405 mDnDListView.setAlpha(0f);
406 mDnDListView.setVisibility(View.VISIBLE);
407
408 // Animate the content view to 100% opacity, and clear any animation
409 // listener set on the view.
410 mDnDListView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
411
412 // Animate the loading view to 0% opacity. After the animation ends,
413 // set its visibility to GONE as an optimization step (it won't
414 // participate in layout passes, etc.)
415 mLoadingView.animate().alpha(0f).setDuration(mShortAnimationDuration).setListener(new AnimatorListenerAdapter() {
416 @Override
417 public void onAnimationEnd(Animator animation) {
418 mLoadingView.setVisibility(View.GONE);
419 }
420 });
421 }
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500422
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500423
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500424 @Override
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500425 public AsyncTaskLoader<Bundle> onCreateLoader(int arg0, Bundle arg1) {
426 AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService());
427 l.forceLoad();
428 return l;
429 }
430
431 @Override
432 public void onLoadFinished(Loader<Bundle> loader, Bundle results) {
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500433 mAccountsAdapter.removeAll();
434 ArrayList<Account> tmp = results.getParcelableArrayList(AccountsLoader.ACCOUNTS);
435 ip2ip = results.getParcelable(AccountsLoader.ACCOUNT_IP2IP);
436 mAccountsAdapter.addAll(tmp);
437 mIP2IPAdapter.removeAll();
438 mIP2IPAdapter.insert(ip2ip, 0);
439 if (mAccountsAdapter.isEmpty()) {
440 mDnDListView.setEmptyView(getView().findViewById(R.id.empty_account_list));
441 }
442 crossfade();
443 }
444
445 @Override
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500446 public void onLoaderReset(Loader<Bundle> loader) {
Alexandre Lision658999c2013-12-13 14:42:45 -0500447
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500448 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400449}