blob: 90f956d95044f4ba53bbf3f07745ac86287e4533 [file] [log] [blame]
Alexandre Lision064e1e02013-10-01 16:18:42 -04001package org.sflphone.loaders;
alision11e8e162013-05-28 10:33:14 -04002
3import java.util.ArrayList;
4import java.util.HashMap;
5
Alexandre Lision064e1e02013-10-01 16:18:42 -04006import org.sflphone.model.Account;
7import org.sflphone.service.ISipService;
8
alision11e8e162013-05-28 10:33:14 -04009import android.content.AsyncTaskLoader;
10import android.content.Context;
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040011import android.os.Bundle;
alision11e8e162013-05-28 10:33:14 -040012import android.os.RemoteException;
13import android.util.Log;
14
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040015public class AccountsLoader extends AsyncTaskLoader<Bundle> {
alision11e8e162013-05-28 10:33:14 -040016
17 private static final String TAG = AccountsLoader.class.getSimpleName();
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040018 public static final String ACCOUNTS = "accounts";
19 public static final String ACCOUNT_IP2IP = "IP2IP";
alision11e8e162013-05-28 10:33:14 -040020 ISipService service;
21
22 public AccountsLoader(Context context, ISipService ref) {
23 super(context);
24 service = ref;
25 }
26
Alexandre Lision6e8931e2013-09-19 16:49:34 -040027 @SuppressWarnings("unchecked") // Hashmap runtime cast
alision11e8e162013-05-28 10:33:14 -040028 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040029 public Bundle loadInBackground() {
alision5cfc35d2013-07-11 15:11:39 -040030
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040031 ArrayList<Account> accounts = new ArrayList<Account>();
32 Account IP2IP = null;
33
alision11e8e162013-05-28 10:33:14 -040034 try {
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040035 ArrayList<String> accountIDs = (ArrayList<String>) service.getAccountList();
36 HashMap<String, String> details;
alision11e8e162013-05-28 10:33:14 -040037 for (String id : accountIDs) {
alision5cfc35d2013-07-11 15:11:39 -040038
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040039 if (id.contentEquals(ACCOUNT_IP2IP)) {
40 details = (HashMap<String, String>) service.getAccountDetails(id);
41 IP2IP = new Account(ACCOUNT_IP2IP, details);
alision11e8e162013-05-28 10:33:14 -040042 continue;
43 }
44 details = (HashMap<String, String>) service.getAccountDetails(id);
Alexandre Lision059da9d2013-10-22 11:17:25 -040045 Account tmp = new Account(id, details);
46
47 accounts.add(tmp);
48
49 Log.i(TAG, "account:"+tmp.getAlias()+" "+tmp.isEnabled());
alision11e8e162013-05-28 10:33:14 -040050
51 }
52 } catch (RemoteException e) {
53 Log.e(TAG, e.toString());
alision5cfc35d2013-07-11 15:11:39 -040054 } catch (NullPointerException e1) {
alisiondf1dac92013-06-27 17:35:53 -040055 Log.e(TAG, e1.toString());
alision11e8e162013-05-28 10:33:14 -040056 }
57
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040058 Bundle result = new Bundle();
59 result.putParcelableArrayList(ACCOUNTS, accounts);
60 result.putParcelable(ACCOUNT_IP2IP, IP2IP);
alision11e8e162013-05-28 10:33:14 -040061 return result;
62 }
63
64}