blob: be69b00e0d47f250efc95f0c3c1f11ecb3e75222 [file] [log] [blame]
Alexandre Savard2b370f02012-09-06 16:06:01 -04001/*
alision5cfc35d2013-07-11 15:11:39 -04002 * Copyright (C) 2004-2013 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 Lision064e1e02013-10-01 16:18:42 -040038import org.sflphone.R;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -040039import org.sflphone.client.AccountEditionActivity;
Alexandre Lision064e1e02013-10-01 16:18:42 -040040import org.sflphone.client.AccountWizard;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040041import org.sflphone.interfaces.AccountsInterface;
42import org.sflphone.loaders.AccountsLoader;
43import org.sflphone.loaders.LoaderConstants;
Alexandre Lision064e1e02013-10-01 16:18:42 -040044import org.sflphone.model.Account;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040045import org.sflphone.receivers.AccountsReceiver;
Alexandre Lision064e1e02013-10-01 16:18:42 -040046import org.sflphone.service.ConfigurationManagerCallback;
47import org.sflphone.service.ISipService;
Alexandre Lision7f0bba52013-10-16 14:43:11 -040048import org.sflphone.views.dragsortlv.DragSortListView;
Alexandre Lision064e1e02013-10-01 16:18:42 -040049
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040050import android.animation.Animator;
51import android.animation.AnimatorListenerAdapter;
Alexandre Savard9a93f062012-09-11 10:42:43 -040052import android.app.Activity;
Alexandre Savardae992932012-10-17 10:26:12 -040053import android.content.Context;
Alexandre Savard53d2ddd2012-09-30 22:04:40 -040054import android.content.Intent;
Alexandre Savard4f11d7a2012-10-18 13:15:36 -040055import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040056import android.os.Bundle;
57import android.os.RemoteException;
Alexandre Lisiona8b78722013-12-13 10:18:33 -050058import android.support.v4.app.ListFragment;
59import android.support.v4.app.LoaderManager.LoaderCallbacks;
Alexandre Savard2b370f02012-09-06 16:06:01 -040060import android.util.Log;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040061import android.view.LayoutInflater;
Alexandre Lisiona764c682013-09-09 10:02:07 -040062import android.view.Menu;
63import android.view.MenuInflater;
64import android.view.MenuItem;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040065import android.view.View;
Alexandre Lision059da9d2013-10-22 11:17:25 -040066import android.view.View.OnClickListener;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040067import android.view.ViewGroup;
68import android.widget.AdapterView;
69import android.widget.AdapterView.OnItemClickListener;
70import android.widget.BaseAdapter;
71import android.widget.CheckBox;
Alexandre Lision230d66e2013-10-22 12:32:12 -040072import android.widget.ListView;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040073import android.widget.TextView;
Alexandre Savard2b370f02012-09-06 16:06:01 -040074
Alexandre Lisiona3650992013-11-13 14:19:35 -050075public class AccountsManagementFragment extends ListFragment implements LoaderCallbacks<Bundle>, AccountsInterface {
Alexandre Savard2b370f02012-09-06 16:06:01 -040076 static final String TAG = "AccountManagementFragment";
Alexandre Savarda6c0d992012-09-28 09:24:13 -040077 static final String DEFAULT_ACCOUNT_ID = "IP2IP";
Alexandre Savard53d2ddd2012-09-30 22:04:40 -040078 static final int ACCOUNT_CREATE_REQUEST = 1;
Alexandre Savard68838112012-10-30 11:34:43 -040079 static final int ACCOUNT_EDIT_REQUEST = 2;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040080 AccountsReceiver accountReceiver;
Alexandre Lision230d66e2013-10-22 12:32:12 -040081 AccountsAdapter mAccountsAdapter;
82 AccountsAdapter mIP2IPAdapter;
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040083
84 DragSortListView mDnDListView;
85 private View mLoadingView;
86 private int mShortAnimationDuration;
87
Alexandre Lision4cf78702013-10-16 13:43:23 -040088 private DragSortListView.DropListener onDrop = new DragSortListView.DropListener() {
89 @Override
90 public void drop(int from, int to) {
91 if (from != to) {
Alexandre Lision230d66e2013-10-22 12:32:12 -040092 Account item = mAccountsAdapter.getItem(from);
93 mAccountsAdapter.remove(item);
94 mAccountsAdapter.insert(item, to);
Alexandre Lision4cf78702013-10-16 13:43:23 -040095 try {
Alexandre Lision230d66e2013-10-22 12:32:12 -040096 mCallbacks.getService().setAccountOrder(mAccountsAdapter.generateAccountOrder());
Alexandre Lision4cf78702013-10-16 13:43:23 -040097 } catch (RemoteException e) {
98 e.printStackTrace();
99 }
100 }
101 }
102
Alexandre Lision4cf78702013-10-16 13:43:23 -0400103 };
104
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400105 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lision059da9d2013-10-22 11:17:25 -0400106 private Account ip2ip;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400107 private static Callbacks sDummyCallbacks = new Callbacks() {
108
109 @Override
110 public ISipService getService() {
111 return null;
112 }
113 };
114
115 public interface Callbacks {
116
117 public ISipService getService();
118
119 }
Alexandre Savardae992932012-10-17 10:26:12 -0400120
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400121 @Override
122 public void onAttach(Activity activity) {
123 super.onAttach(activity);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400124 if (!(activity instanceof Callbacks)) {
125 throw new IllegalStateException("Activity must implement fragment's callbacks.");
126 }
127
128 mCallbacks = (Callbacks) activity;
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400129 }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400130
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400131 @Override
132 public void onDetach() {
133 super.onDetach();
134 mCallbacks = sDummyCallbacks;
alisiond9e29442013-04-17 16:10:18 -0400135 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400136
137 @Override
alisiond9e29442013-04-17 16:10:18 -0400138 public void onCreate(Bundle savedInstanceState) {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400139 super.onCreate(savedInstanceState);
140
Alexandre Savard9a93f062012-09-11 10:42:43 -0400141 Log.i(TAG, "Create Account Management Fragment");
Alexandre Lision230d66e2013-10-22 12:32:12 -0400142 mAccountsAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400143 mIP2IPAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisiona764c682013-09-09 10:02:07 -0400144 this.setHasOptionsMenu(true);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400145 accountReceiver = new AccountsReceiver(this);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400146
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400147 mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
Alexandre Lision4d20c812013-12-12 17:44:50 -0500148 Log.i(TAG, "anim time: " + mShortAnimationDuration);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400149
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400150 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400151
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400152 @Override
153 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400154 View inflatedView = inflater.inflate(R.layout.frag_accounts_list, parent, false);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400155 setListAdapter(mAccountsAdapter);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400156
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400157 return inflatedView;
158 }
159
160 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -0400161 public DragSortListView getListView() {
162 return (DragSortListView) super.getListView();
163 }
164
165 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400166 public void onViewCreated(View view, Bundle savedInstanceState) {
167 super.onViewCreated(view, savedInstanceState);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400168
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400169 mDnDListView = getListView();
170
171 mDnDListView.setDropListener(onDrop);
172 mDnDListView.setOnItemClickListener(new OnItemClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400173
174 @Override
175 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400176 launchAccountEditActivity(mAccountsAdapter.getItem(pos));
Emeric Vigier0038a612012-11-06 18:51:19 -0500177 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400178 });
Alexandre Lision230d66e2013-10-22 12:32:12 -0400179
180 ((ListView) getView().findViewById(R.id.ip2ip)).setAdapter(mIP2IPAdapter);
181 ((ListView) getView().findViewById(R.id.ip2ip)).setOnItemClickListener(new OnItemClickListener() {
182
Alexandre Lision059da9d2013-10-22 11:17:25 -0400183 @Override
Alexandre Lision230d66e2013-10-22 12:32:12 -0400184 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400185 launchAccountEditActivity(ip2ip);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400186
Alexandre Lision059da9d2013-10-22 11:17:25 -0400187 }
188 });
Alexandre Lision40954dc2013-10-09 15:24:03 -0400189
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400190 mLoadingView = view.findViewById(R.id.loading_spinner);
Alexandre Savard2b370f02012-09-06 16:06:01 -0400191 }
192
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400193 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400194 public void onPause() {
195 super.onPause();
196 getActivity().unregisterReceiver(accountReceiver);
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400197 }
198
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400199 public void onResume() {
200 super.onResume();
201 IntentFilter intentFilter2 = new IntentFilter();
202 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
203 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
204 getActivity().registerReceiver(accountReceiver, intentFilter2);
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500205 getActivity().getSupportLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Lision658999c2013-12-13 14:42:45 -0500206 getActivity().getActionBar().setTitle(R.string.menu_item_accounts);
alisiona4325152013-04-19 11:10:03 -0400207 }
alision73424b62013-04-26 11:49:18 -0400208
Alexandre Lisiona764c682013-09-09 10:02:07 -0400209 @Override
210 public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
211 super.onCreateOptionsMenu(m, inf);
212 inf.inflate(R.menu.account_creation, m);
213 }
214
215 @Override
216 public boolean onOptionsItemSelected(MenuItem item) {
217 super.onOptionsItemSelected(item);
218 switch (item.getItemId()) {
219 case R.id.menuitem_create:
220 Intent intent = new Intent().setClass(getActivity(), AccountWizard.class);
221 startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
222 break;
223 }
224
225 return true;
226 }
227
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400228 private void launchAccountEditActivity(Account acc) {
Alexandre Savard68838112012-10-30 11:34:43 -0400229 Log.i(TAG, "Launch account edit activity");
Alexandre Savard833616f2012-10-30 16:02:30 -0400230
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400231 Intent intent = new Intent().setClass(getActivity(), AccountEditionActivity.class);
232 Bundle bundle = new Bundle();
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400233 bundle.putParcelable("account", acc);
Alexandre Lision059da9d2013-10-22 11:17:25 -0400234
Alexandre Savard833616f2012-10-30 16:02:30 -0400235 intent.putExtras(bundle);
236
Alexandre Savard68838112012-10-30 11:34:43 -0400237 startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
238 }
239
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400240 @Override
241 public void accountsChanged() {
242 if (getActivity() != null)
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500243 getActivity().getSupportLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Savard52a72522012-09-27 16:40:13 -0400244 }
245
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400246 @Override
247 public void accountStateChanged(Intent accountState) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400248 mAccountsAdapter.updateAccount(accountState);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400249 }
250
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400251 /**
252 *
253 * Adapter for accounts List
Alexandre Lision40954dc2013-10-09 15:24:03 -0400254 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400255 * @author lisional
Alexandre Lision40954dc2013-10-09 15:24:03 -0400256 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400257 */
258 public class AccountsAdapter extends BaseAdapter {
Alexandre Savard52a72522012-09-27 16:40:13 -0400259
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400260 // private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
Alexandre Savard70982012012-09-27 17:15:50 -0400261
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400262 ArrayList<Account> accounts;
263 Context mContext;
Alexandre Savard70982012012-09-27 17:15:50 -0400264
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400265 public AccountsAdapter(Context cont, ArrayList<Account> newList) {
266 super();
267 accounts = newList;
268 mContext = cont;
Alexandre Savarde990d052012-10-18 14:43:09 -0400269 }
alisiond9e29442013-04-17 16:10:18 -0400270
Alexandre Lision4cf78702013-10-16 13:43:23 -0400271 public void insert(Account item, int to) {
272 accounts.add(to, item);
273 notifyDataSetChanged();
274 }
275
276 public void remove(Account item) {
277 accounts.remove(item);
278 notifyDataSetChanged();
279 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400280
Alexandre Lision4cf78702013-10-16 13:43:23 -0400281 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400282 public boolean hasStableIds() {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400283 return true;
284 }
285
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400286 @Override
287 public int getCount() {
288 return accounts.size();
289 }
Alexandre Savard70982012012-09-27 17:15:50 -0400290
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400291 @Override
292 public Account getItem(int pos) {
293 return accounts.get(pos);
294 }
Alexandre Savard68838112012-10-30 11:34:43 -0400295
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400296 @Override
297 public long getItemId(int pos) {
298 return 0;
299 }
Alexandre Savard68838112012-10-30 11:34:43 -0400300
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400301 @Override
302 public View getView(final int pos, View convertView, ViewGroup parent) {
303 View rowView = convertView;
304 AccountView entryView = null;
Alexandre Savard68838112012-10-30 11:34:43 -0400305
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400306 if (rowView == null) {
307 LayoutInflater inflater = LayoutInflater.from(mContext);
308 rowView = inflater.inflate(R.layout.item_account_pref, null);
alisiond9e29442013-04-17 16:10:18 -0400309
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400310 entryView = new AccountView();
311 entryView.alias = (TextView) rowView.findViewById(R.id.account_alias);
312 entryView.host = (TextView) rowView.findViewById(R.id.account_host);
313 entryView.enabled = (CheckBox) rowView.findViewById(R.id.account_checked);
314 rowView.setTag(entryView);
315 } else {
316 entryView = (AccountView) rowView.getTag();
317 }
318
Alexandre Lision059da9d2013-10-22 11:17:25 -0400319 final Account item = accounts.get(pos);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400320 entryView.alias.setText(accounts.get(pos).getAlias());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400321 if (item.isIP2IP()) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400322 entryView.host.setText(item.getRegistered_state());
323 entryView.enabled.setVisibility(View.GONE);
324 } else {
325 entryView.host.setText(item.getHost() + " - " + item.getRegistered_state());
326 entryView.enabled.setChecked(item.isEnabled());
327 entryView.enabled.setOnClickListener(new OnClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400328
Alexandre Lision230d66e2013-10-22 12:32:12 -0400329 @Override
330 public void onClick(View v) {
331 item.setEnabled(!item.isEnabled());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400332
Alexandre Lision230d66e2013-10-22 12:32:12 -0400333 try {
334 mCallbacks.getService().setAccountDetails(item.getAccountID(), item.getDetails());
335 } catch (RemoteException e) {
336 e.printStackTrace();
337 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400338 }
Alexandre Lision230d66e2013-10-22 12:32:12 -0400339 });
340 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400341
342 return rowView;
343 }
344
345 /*********************
346 * ViewHolder Pattern
347 *********************/
348 public class AccountView {
349 public TextView alias;
350 public TextView host;
351 public CheckBox enabled;
352 }
353
354 public void removeAll() {
355 accounts.clear();
356 notifyDataSetChanged();
357
358 }
359
360 public void addAll(ArrayList<Account> results) {
361 accounts.addAll(results);
362 notifyDataSetChanged();
363 }
364
365 /**
366 * Modify state of specific account
367 *
368 * @param accountState
369 */
370 public void updateAccount(Intent accountState) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400371 String id = accountState.getStringExtra("Account");
372 String newState = accountState.getStringExtra("state");
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400373
Alexandre Lision4d20c812013-12-12 17:44:50 -0500374 Log.i(TAG, "updateAccount:" + newState);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400375 for (Account a : accounts) {
376 if (a.getAccountID().contentEquals(id)) {
377 a.setRegistered_state(newState);
378 notifyDataSetChanged();
379 return;
380 }
381 }
382
383 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400384
Alexandre Lision4cf78702013-10-16 13:43:23 -0400385 private String generateAccountOrder() {
386 String result = DEFAULT_ACCOUNT_ID + File.separator;
387 for (Account a : accounts) {
388 result += a.getAccountID() + File.separator;
389 }
390 return result;
391 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400392
Alexandre Savard68838112012-10-30 11:34:43 -0400393 }
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400394
395 private void crossfade() {
396
397 // Set the content view to 0% opacity but visible, so that it is visible
398 // (but fully transparent) during the animation.
399 mDnDListView.setAlpha(0f);
400 mDnDListView.setVisibility(View.VISIBLE);
401
402 // Animate the content view to 100% opacity, and clear any animation
403 // listener set on the view.
404 mDnDListView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
405
406 // Animate the loading view to 0% opacity. After the animation ends,
407 // set its visibility to GONE as an optimization step (it won't
408 // participate in layout passes, etc.)
409 mLoadingView.animate().alpha(0f).setDuration(mShortAnimationDuration).setListener(new AnimatorListenerAdapter() {
410 @Override
411 public void onAnimationEnd(Animator animation) {
412 mLoadingView.setVisibility(View.GONE);
413 }
414 });
415 }
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500416
417 @Override
418 public void onLoadFinished(android.support.v4.content.Loader<Bundle> arg0, Bundle results) {
419 mAccountsAdapter.removeAll();
420 ArrayList<Account> tmp = results.getParcelableArrayList(AccountsLoader.ACCOUNTS);
421 ip2ip = results.getParcelable(AccountsLoader.ACCOUNT_IP2IP);
422 mAccountsAdapter.addAll(tmp);
423 mIP2IPAdapter.removeAll();
424 mIP2IPAdapter.insert(ip2ip, 0);
425 if (mAccountsAdapter.isEmpty()) {
426 mDnDListView.setEmptyView(getView().findViewById(R.id.empty_account_list));
427 }
428 crossfade();
429 }
430
431 @Override
432 public void onLoaderReset(android.support.v4.content.Loader<Bundle> arg0) {
Alexandre Lision658999c2013-12-13 14:42:45 -0500433
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500434 }
435
436 @Override
437 public android.support.v4.content.Loader<Bundle> onCreateLoader(int arg0, Bundle arg1) {
438 AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService());
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500439 l.forceLoad();
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500440 return l;
441 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400442}