blob: 042f6fef4a9e08ceaffa90e0b4dce5fbeafaa86c [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 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 Lision420b2572014-01-10 11:37:18 -050079 public 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 Lisionb97c9512014-01-07 17:14:03 -0500147 mShortAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
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 Lisionb97c9512014-01-07 17:14:03 -0500205 getLoaderManager().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 Lisionb97c9512014-01-07 17:14:03 -0500243 getLoaderManager().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 Lision420b2572014-01-10 11:37:18 -0500251 @Override
252 public void onActivityResult(int requestCode, int resultCode, Intent data) {
253 super.onActivityResult(requestCode, resultCode, data);
254 if(resultCode == ACCOUNT_EDIT_REQUEST) {
255 getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
256 }
257 }
258
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400259 /**
260 *
261 * Adapter for accounts List
Alexandre Lision40954dc2013-10-09 15:24:03 -0400262 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400263 * @author lisional
Alexandre Lision40954dc2013-10-09 15:24:03 -0400264 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400265 */
266 public class AccountsAdapter extends BaseAdapter {
Alexandre Savard52a72522012-09-27 16:40:13 -0400267
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400268 // private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
Alexandre Savard70982012012-09-27 17:15:50 -0400269
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400270 ArrayList<Account> accounts;
271 Context mContext;
Alexandre Savard70982012012-09-27 17:15:50 -0400272
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400273 public AccountsAdapter(Context cont, ArrayList<Account> newList) {
274 super();
275 accounts = newList;
276 mContext = cont;
Alexandre Savarde990d052012-10-18 14:43:09 -0400277 }
alisiond9e29442013-04-17 16:10:18 -0400278
Alexandre Lision4cf78702013-10-16 13:43:23 -0400279 public void insert(Account item, int to) {
280 accounts.add(to, item);
281 notifyDataSetChanged();
282 }
283
284 public void remove(Account item) {
285 accounts.remove(item);
286 notifyDataSetChanged();
287 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400288
Alexandre Lision4cf78702013-10-16 13:43:23 -0400289 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400290 public boolean hasStableIds() {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400291 return true;
292 }
293
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400294 @Override
295 public int getCount() {
296 return accounts.size();
297 }
Alexandre Savard70982012012-09-27 17:15:50 -0400298
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400299 @Override
300 public Account getItem(int pos) {
301 return accounts.get(pos);
302 }
Alexandre Savard68838112012-10-30 11:34:43 -0400303
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400304 @Override
305 public long getItemId(int pos) {
306 return 0;
307 }
Alexandre Savard68838112012-10-30 11:34:43 -0400308
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400309 @Override
310 public View getView(final int pos, View convertView, ViewGroup parent) {
311 View rowView = convertView;
312 AccountView entryView = null;
Alexandre Savard68838112012-10-30 11:34:43 -0400313
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400314 if (rowView == null) {
315 LayoutInflater inflater = LayoutInflater.from(mContext);
316 rowView = inflater.inflate(R.layout.item_account_pref, null);
alisiond9e29442013-04-17 16:10:18 -0400317
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400318 entryView = new AccountView();
319 entryView.alias = (TextView) rowView.findViewById(R.id.account_alias);
320 entryView.host = (TextView) rowView.findViewById(R.id.account_host);
321 entryView.enabled = (CheckBox) rowView.findViewById(R.id.account_checked);
322 rowView.setTag(entryView);
323 } else {
324 entryView = (AccountView) rowView.getTag();
325 }
326
Alexandre Lision059da9d2013-10-22 11:17:25 -0400327 final Account item = accounts.get(pos);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400328 entryView.alias.setText(accounts.get(pos).getAlias());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400329 if (item.isIP2IP()) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400330 entryView.host.setText(item.getRegistered_state());
331 entryView.enabled.setVisibility(View.GONE);
332 } else {
333 entryView.host.setText(item.getHost() + " - " + item.getRegistered_state());
334 entryView.enabled.setChecked(item.isEnabled());
335 entryView.enabled.setOnClickListener(new OnClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400336
Alexandre Lision230d66e2013-10-22 12:32:12 -0400337 @Override
338 public void onClick(View v) {
339 item.setEnabled(!item.isEnabled());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400340
Alexandre Lision230d66e2013-10-22 12:32:12 -0400341 try {
342 mCallbacks.getService().setAccountDetails(item.getAccountID(), item.getDetails());
343 } catch (RemoteException e) {
344 e.printStackTrace();
345 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400346 }
Alexandre Lision230d66e2013-10-22 12:32:12 -0400347 });
348 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400349
350 return rowView;
351 }
352
353 /*********************
354 * ViewHolder Pattern
355 *********************/
356 public class AccountView {
357 public TextView alias;
358 public TextView host;
359 public CheckBox enabled;
360 }
361
362 public void removeAll() {
363 accounts.clear();
364 notifyDataSetChanged();
365
366 }
367
368 public void addAll(ArrayList<Account> results) {
369 accounts.addAll(results);
370 notifyDataSetChanged();
371 }
372
373 /**
374 * Modify state of specific account
375 *
376 * @param accountState
377 */
378 public void updateAccount(Intent accountState) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400379 String id = accountState.getStringExtra("Account");
380 String newState = accountState.getStringExtra("state");
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400381
Alexandre Lision4d20c812013-12-12 17:44:50 -0500382 Log.i(TAG, "updateAccount:" + newState);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400383 for (Account a : accounts) {
384 if (a.getAccountID().contentEquals(id)) {
385 a.setRegistered_state(newState);
386 notifyDataSetChanged();
387 return;
388 }
389 }
390
391 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400392
Alexandre Lision4cf78702013-10-16 13:43:23 -0400393 private String generateAccountOrder() {
394 String result = DEFAULT_ACCOUNT_ID + File.separator;
395 for (Account a : accounts) {
396 result += a.getAccountID() + File.separator;
397 }
398 return result;
399 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400400
Alexandre Savard68838112012-10-30 11:34:43 -0400401 }
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400402
403 private void crossfade() {
404
405 // Set the content view to 0% opacity but visible, so that it is visible
406 // (but fully transparent) during the animation.
407 mDnDListView.setAlpha(0f);
408 mDnDListView.setVisibility(View.VISIBLE);
409
410 // Animate the content view to 100% opacity, and clear any animation
411 // listener set on the view.
412 mDnDListView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
413
414 // Animate the loading view to 0% opacity. After the animation ends,
415 // set its visibility to GONE as an optimization step (it won't
416 // participate in layout passes, etc.)
417 mLoadingView.animate().alpha(0f).setDuration(mShortAnimationDuration).setListener(new AnimatorListenerAdapter() {
418 @Override
419 public void onAnimationEnd(Animator animation) {
420 mLoadingView.setVisibility(View.GONE);
421 }
422 });
423 }
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500424
425 @Override
426 public void onLoadFinished(android.support.v4.content.Loader<Bundle> arg0, Bundle results) {
427 mAccountsAdapter.removeAll();
428 ArrayList<Account> tmp = results.getParcelableArrayList(AccountsLoader.ACCOUNTS);
429 ip2ip = results.getParcelable(AccountsLoader.ACCOUNT_IP2IP);
430 mAccountsAdapter.addAll(tmp);
431 mIP2IPAdapter.removeAll();
432 mIP2IPAdapter.insert(ip2ip, 0);
433 if (mAccountsAdapter.isEmpty()) {
434 mDnDListView.setEmptyView(getView().findViewById(R.id.empty_account_list));
435 }
436 crossfade();
437 }
438
439 @Override
440 public void onLoaderReset(android.support.v4.content.Loader<Bundle> arg0) {
Alexandre Lision658999c2013-12-13 14:42:45 -0500441
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500442 }
443
444 @Override
445 public android.support.v4.content.Loader<Bundle> onCreateLoader(int arg0, Bundle arg1) {
446 AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService());
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500447 l.forceLoad();
Alexandre Lisiona8b78722013-12-13 10:18:33 -0500448 return l;
449 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400450}