blob: 95caf5dc06e021b6aa996eb78cd49fbcb049f63e [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 Lisionbe54c342014-01-21 17:10:33 -050038import android.content.Context;
39import android.content.Intent;
40import android.content.IntentFilter;
41import android.support.v4.app.ListFragment;
42import android.support.v4.app.LoaderManager;
43import android.support.v4.content.AsyncTaskLoader;
44import android.support.v4.content.Loader;
Alexandre Lision064e1e02013-10-01 16:18:42 -040045import org.sflphone.R;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -040046import org.sflphone.client.AccountEditionActivity;
Alexandre Lision064e1e02013-10-01 16:18:42 -040047import org.sflphone.client.AccountWizard;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040048import org.sflphone.interfaces.AccountsInterface;
49import org.sflphone.loaders.AccountsLoader;
50import org.sflphone.loaders.LoaderConstants;
Alexandre Lision064e1e02013-10-01 16:18:42 -040051import org.sflphone.model.Account;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040052import org.sflphone.receivers.AccountsReceiver;
Alexandre Lision064e1e02013-10-01 16:18:42 -040053import org.sflphone.service.ConfigurationManagerCallback;
54import org.sflphone.service.ISipService;
Alexandre Lision7f0bba52013-10-16 14:43:11 -040055import org.sflphone.views.dragsortlv.DragSortListView;
Alexandre Lision064e1e02013-10-01 16:18:42 -040056
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040057import android.animation.Animator;
58import android.animation.AnimatorListenerAdapter;
Alexandre Savard9a93f062012-09-11 10:42:43 -040059import android.app.Activity;
alisionf76de3b2013-04-16 15:35:22 -040060import android.os.Bundle;
61import android.os.RemoteException;
Alexandre Savard2b370f02012-09-06 16:06:01 -040062import android.util.Log;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040063import android.view.LayoutInflater;
Alexandre Lisiona764c682013-09-09 10:02:07 -040064import android.view.Menu;
65import android.view.MenuInflater;
66import android.view.MenuItem;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040067import android.view.View;
Alexandre Lision059da9d2013-10-22 11:17:25 -040068import android.view.View.OnClickListener;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040069import android.view.ViewGroup;
70import android.widget.AdapterView;
71import android.widget.AdapterView.OnItemClickListener;
72import android.widget.BaseAdapter;
73import android.widget.CheckBox;
Alexandre Lision230d66e2013-10-22 12:32:12 -040074import android.widget.ListView;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040075import android.widget.TextView;
Alexandre Savard2b370f02012-09-06 16:06:01 -040076
Alexandre Lisionb4e60612014-01-14 17:47:23 -050077public class AccountsManagementFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Bundle>, AccountsInterface {
Alexandre Savard2b370f02012-09-06 16:06:01 -040078 static final String TAG = "AccountManagementFragment";
Alexandre Savarda6c0d992012-09-28 09:24:13 -040079 static final String DEFAULT_ACCOUNT_ID = "IP2IP";
Alexandre Savard53d2ddd2012-09-30 22:04:40 -040080 static final int ACCOUNT_CREATE_REQUEST = 1;
Alexandre Lision420b2572014-01-10 11:37:18 -050081 public static final int ACCOUNT_EDIT_REQUEST = 2;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040082 AccountsReceiver accountReceiver;
Alexandre Lision230d66e2013-10-22 12:32:12 -040083 AccountsAdapter mAccountsAdapter;
84 AccountsAdapter mIP2IPAdapter;
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040085
86 DragSortListView mDnDListView;
87 private View mLoadingView;
88 private int mShortAnimationDuration;
89
Alexandre Lision4cf78702013-10-16 13:43:23 -040090 private DragSortListView.DropListener onDrop = new DragSortListView.DropListener() {
91 @Override
92 public void drop(int from, int to) {
93 if (from != to) {
Alexandre Lision230d66e2013-10-22 12:32:12 -040094 Account item = mAccountsAdapter.getItem(from);
95 mAccountsAdapter.remove(item);
96 mAccountsAdapter.insert(item, to);
Alexandre Lision4cf78702013-10-16 13:43:23 -040097 try {
Alexandre Lision230d66e2013-10-22 12:32:12 -040098 mCallbacks.getService().setAccountOrder(mAccountsAdapter.generateAccountOrder());
Alexandre Lision4cf78702013-10-16 13:43:23 -040099 } catch (RemoteException e) {
100 e.printStackTrace();
101 }
102 }
103 }
104
Alexandre Lision4cf78702013-10-16 13:43:23 -0400105 };
106
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400107 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lision059da9d2013-10-22 11:17:25 -0400108 private Account ip2ip;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400109 private static Callbacks sDummyCallbacks = new Callbacks() {
110
111 @Override
112 public ISipService getService() {
113 return null;
114 }
115 };
116
117 public interface Callbacks {
118
119 public ISipService getService();
120
121 }
Alexandre Savardae992932012-10-17 10:26:12 -0400122
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400123 @Override
124 public void onAttach(Activity activity) {
125 super.onAttach(activity);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400126 if (!(activity instanceof Callbacks)) {
127 throw new IllegalStateException("Activity must implement fragment's callbacks.");
128 }
129
130 mCallbacks = (Callbacks) activity;
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400131 }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400132
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400133 @Override
134 public void onDetach() {
135 super.onDetach();
136 mCallbacks = sDummyCallbacks;
alisiond9e29442013-04-17 16:10:18 -0400137 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400138
139 @Override
alisiond9e29442013-04-17 16:10:18 -0400140 public void onCreate(Bundle savedInstanceState) {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400141 super.onCreate(savedInstanceState);
142
Alexandre Savard9a93f062012-09-11 10:42:43 -0400143 Log.i(TAG, "Create Account Management Fragment");
Alexandre Lision230d66e2013-10-22 12:32:12 -0400144 mAccountsAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400145 mIP2IPAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisiona764c682013-09-09 10:02:07 -0400146 this.setHasOptionsMenu(true);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400147 accountReceiver = new AccountsReceiver(this);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400148
Alexandre Lisionb97c9512014-01-07 17:14:03 -0500149 mShortAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
Alexandre Lision4d20c812013-12-12 17:44:50 -0500150 Log.i(TAG, "anim time: " + mShortAnimationDuration);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400151
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400152 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400153
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400154 @Override
155 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400156 View inflatedView = inflater.inflate(R.layout.frag_accounts_list, parent, false);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400157 setListAdapter(mAccountsAdapter);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400158
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400159 return inflatedView;
160 }
161
162 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -0400163 public DragSortListView getListView() {
164 return (DragSortListView) super.getListView();
165 }
166
167 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400168 public void onViewCreated(View view, Bundle savedInstanceState) {
169 super.onViewCreated(view, savedInstanceState);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400170
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400171 mDnDListView = getListView();
172
173 mDnDListView.setDropListener(onDrop);
174 mDnDListView.setOnItemClickListener(new OnItemClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400175
176 @Override
177 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400178 launchAccountEditActivity(mAccountsAdapter.getItem(pos));
Emeric Vigier0038a612012-11-06 18:51:19 -0500179 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400180 });
Alexandre Lision230d66e2013-10-22 12:32:12 -0400181
182 ((ListView) getView().findViewById(R.id.ip2ip)).setAdapter(mIP2IPAdapter);
183 ((ListView) getView().findViewById(R.id.ip2ip)).setOnItemClickListener(new OnItemClickListener() {
184
Alexandre Lision059da9d2013-10-22 11:17:25 -0400185 @Override
Alexandre Lision230d66e2013-10-22 12:32:12 -0400186 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400187 launchAccountEditActivity(ip2ip);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400188
Alexandre Lision059da9d2013-10-22 11:17:25 -0400189 }
190 });
Alexandre Lision40954dc2013-10-09 15:24:03 -0400191
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400192 mLoadingView = view.findViewById(R.id.loading_spinner);
Alexandre Savard2b370f02012-09-06 16:06:01 -0400193 }
194
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400195 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400196 public void onPause() {
197 super.onPause();
198 getActivity().unregisterReceiver(accountReceiver);
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400199 }
200
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400201 public void onResume() {
202 super.onResume();
203 IntentFilter intentFilter2 = new IntentFilter();
204 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
205 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
206 getActivity().registerReceiver(accountReceiver, intentFilter2);
Alexandre Lisionb97c9512014-01-07 17:14:03 -0500207 getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Lision658999c2013-12-13 14:42:45 -0500208 getActivity().getActionBar().setTitle(R.string.menu_item_accounts);
alisiona4325152013-04-19 11:10:03 -0400209 }
alision73424b62013-04-26 11:49:18 -0400210
Alexandre Lisiona764c682013-09-09 10:02:07 -0400211 @Override
212 public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
213 super.onCreateOptionsMenu(m, inf);
214 inf.inflate(R.menu.account_creation, m);
215 }
216
217 @Override
218 public boolean onOptionsItemSelected(MenuItem item) {
219 super.onOptionsItemSelected(item);
220 switch (item.getItemId()) {
221 case R.id.menuitem_create:
222 Intent intent = new Intent().setClass(getActivity(), AccountWizard.class);
223 startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
224 break;
225 }
226
227 return true;
228 }
229
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400230 private void launchAccountEditActivity(Account acc) {
Alexandre Savard68838112012-10-30 11:34:43 -0400231 Log.i(TAG, "Launch account edit activity");
Alexandre Savard833616f2012-10-30 16:02:30 -0400232
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400233 Intent intent = new Intent().setClass(getActivity(), AccountEditionActivity.class);
234 Bundle bundle = new Bundle();
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400235 bundle.putParcelable("account", acc);
Alexandre Lision059da9d2013-10-22 11:17:25 -0400236
Alexandre Savard833616f2012-10-30 16:02:30 -0400237 intent.putExtras(bundle);
238
Alexandre Savard68838112012-10-30 11:34:43 -0400239 startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
240 }
241
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400242 @Override
243 public void accountsChanged() {
244 if (getActivity() != null)
Alexandre Lisionb97c9512014-01-07 17:14:03 -0500245 getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Savard52a72522012-09-27 16:40:13 -0400246 }
247
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400248 @Override
249 public void accountStateChanged(Intent accountState) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400250 mAccountsAdapter.updateAccount(accountState);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400251 }
252
Alexandre Lision420b2572014-01-10 11:37:18 -0500253 @Override
254 public void onActivityResult(int requestCode, int resultCode, Intent data) {
255 super.onActivityResult(requestCode, resultCode, data);
256 if(resultCode == ACCOUNT_EDIT_REQUEST) {
257 getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
258 }
259 }
260
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400261 /**
262 *
263 * Adapter for accounts List
Alexandre Lision40954dc2013-10-09 15:24:03 -0400264 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400265 * @author lisional
Alexandre Lision40954dc2013-10-09 15:24:03 -0400266 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400267 */
268 public class AccountsAdapter extends BaseAdapter {
Alexandre Savard52a72522012-09-27 16:40:13 -0400269
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400270 // private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
Alexandre Savard70982012012-09-27 17:15:50 -0400271
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400272 ArrayList<Account> accounts;
273 Context mContext;
Alexandre Savard70982012012-09-27 17:15:50 -0400274
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400275 public AccountsAdapter(Context cont, ArrayList<Account> newList) {
276 super();
277 accounts = newList;
278 mContext = cont;
Alexandre Savarde990d052012-10-18 14:43:09 -0400279 }
alisiond9e29442013-04-17 16:10:18 -0400280
Alexandre Lision4cf78702013-10-16 13:43:23 -0400281 public void insert(Account item, int to) {
282 accounts.add(to, item);
283 notifyDataSetChanged();
284 }
285
286 public void remove(Account item) {
287 accounts.remove(item);
288 notifyDataSetChanged();
289 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400290
Alexandre Lision4cf78702013-10-16 13:43:23 -0400291 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400292 public boolean hasStableIds() {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400293 return true;
294 }
295
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400296 @Override
297 public int getCount() {
298 return accounts.size();
299 }
Alexandre Savard70982012012-09-27 17:15:50 -0400300
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400301 @Override
302 public Account getItem(int pos) {
303 return accounts.get(pos);
304 }
Alexandre Savard68838112012-10-30 11:34:43 -0400305
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400306 @Override
307 public long getItemId(int pos) {
308 return 0;
309 }
Alexandre Savard68838112012-10-30 11:34:43 -0400310
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400311 @Override
312 public View getView(final int pos, View convertView, ViewGroup parent) {
313 View rowView = convertView;
314 AccountView entryView = null;
Alexandre Savard68838112012-10-30 11:34:43 -0400315
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400316 if (rowView == null) {
317 LayoutInflater inflater = LayoutInflater.from(mContext);
318 rowView = inflater.inflate(R.layout.item_account_pref, null);
alisiond9e29442013-04-17 16:10:18 -0400319
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400320 entryView = new AccountView();
321 entryView.alias = (TextView) rowView.findViewById(R.id.account_alias);
322 entryView.host = (TextView) rowView.findViewById(R.id.account_host);
323 entryView.enabled = (CheckBox) rowView.findViewById(R.id.account_checked);
324 rowView.setTag(entryView);
325 } else {
326 entryView = (AccountView) rowView.getTag();
327 }
328
Alexandre Lision059da9d2013-10-22 11:17:25 -0400329 final Account item = accounts.get(pos);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400330 entryView.alias.setText(accounts.get(pos).getAlias());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400331 if (item.isIP2IP()) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400332 entryView.host.setText(item.getRegistered_state());
333 entryView.enabled.setVisibility(View.GONE);
334 } else {
335 entryView.host.setText(item.getHost() + " - " + item.getRegistered_state());
336 entryView.enabled.setChecked(item.isEnabled());
337 entryView.enabled.setOnClickListener(new OnClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400338
Alexandre Lision230d66e2013-10-22 12:32:12 -0400339 @Override
340 public void onClick(View v) {
341 item.setEnabled(!item.isEnabled());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400342
Alexandre Lision230d66e2013-10-22 12:32:12 -0400343 try {
344 mCallbacks.getService().setAccountDetails(item.getAccountID(), item.getDetails());
345 } catch (RemoteException e) {
346 e.printStackTrace();
347 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400348 }
Alexandre Lision230d66e2013-10-22 12:32:12 -0400349 });
350 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400351
352 return rowView;
353 }
354
355 /*********************
356 * ViewHolder Pattern
357 *********************/
358 public class AccountView {
359 public TextView alias;
360 public TextView host;
361 public CheckBox enabled;
362 }
363
364 public void removeAll() {
365 accounts.clear();
366 notifyDataSetChanged();
367
368 }
369
370 public void addAll(ArrayList<Account> results) {
371 accounts.addAll(results);
372 notifyDataSetChanged();
373 }
374
375 /**
376 * Modify state of specific account
377 *
378 * @param accountState
379 */
380 public void updateAccount(Intent accountState) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400381 String id = accountState.getStringExtra("Account");
382 String newState = accountState.getStringExtra("state");
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400383
Alexandre Lision4d20c812013-12-12 17:44:50 -0500384 Log.i(TAG, "updateAccount:" + newState);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400385 for (Account a : accounts) {
386 if (a.getAccountID().contentEquals(id)) {
387 a.setRegistered_state(newState);
388 notifyDataSetChanged();
389 return;
390 }
391 }
392
393 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400394
Alexandre Lision4cf78702013-10-16 13:43:23 -0400395 private String generateAccountOrder() {
396 String result = DEFAULT_ACCOUNT_ID + File.separator;
397 for (Account a : accounts) {
398 result += a.getAccountID() + File.separator;
399 }
400 return result;
401 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400402
Alexandre Savard68838112012-10-30 11:34:43 -0400403 }
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400404
405 private void crossfade() {
406
407 // Set the content view to 0% opacity but visible, so that it is visible
408 // (but fully transparent) during the animation.
409 mDnDListView.setAlpha(0f);
410 mDnDListView.setVisibility(View.VISIBLE);
411
412 // Animate the content view to 100% opacity, and clear any animation
413 // listener set on the view.
414 mDnDListView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
415
416 // Animate the loading view to 0% opacity. After the animation ends,
417 // set its visibility to GONE as an optimization step (it won't
418 // participate in layout passes, etc.)
419 mLoadingView.animate().alpha(0f).setDuration(mShortAnimationDuration).setListener(new AnimatorListenerAdapter() {
420 @Override
421 public void onAnimationEnd(Animator animation) {
422 mLoadingView.setVisibility(View.GONE);
423 }
424 });
425 }
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500426
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500427
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500428 @Override
Alexandre Lisionb4e60612014-01-14 17:47:23 -0500429 public AsyncTaskLoader<Bundle> onCreateLoader(int arg0, Bundle arg1) {
430 AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService());
431 l.forceLoad();
432 return l;
433 }
434
435 @Override
Alexandre Lisionbe54c342014-01-21 17:10:33 -0500436 public void onLoadFinished(Loader<Bundle> bundleLoader, Bundle results) {
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500437 mAccountsAdapter.removeAll();
438 ArrayList<Account> tmp = results.getParcelableArrayList(AccountsLoader.ACCOUNTS);
439 ip2ip = results.getParcelable(AccountsLoader.ACCOUNT_IP2IP);
440 mAccountsAdapter.addAll(tmp);
441 mIP2IPAdapter.removeAll();
442 mIP2IPAdapter.insert(ip2ip, 0);
443 if (mAccountsAdapter.isEmpty()) {
444 mDnDListView.setEmptyView(getView().findViewById(R.id.empty_account_list));
445 }
446 crossfade();
447 }
448
449 @Override
Alexandre Lisionbe54c342014-01-21 17:10:33 -0500450 public void onLoaderReset(Loader<Bundle> bundleLoader) {
Alexandre Lision658999c2013-12-13 14:42:45 -0500451
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500452 }
Alexandre Lisionbe54c342014-01-21 17:10:33 -0500453
Alexandre Savard2b370f02012-09-06 16:06:01 -0400454}