blob: e5b85e3901813e4ba7747f2b50fd78f48dd28113 [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 Lisionef2aa9e2013-10-25 16:22:52 -040027 @SuppressWarnings("unchecked")
28 // Hashmap runtime cast
alision11e8e162013-05-28 10:33:14 -040029 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040030 public Bundle loadInBackground() {
alision5cfc35d2013-07-11 15:11:39 -040031
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040032 ArrayList<Account> accounts = new ArrayList<Account>();
33 Account IP2IP = null;
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040034
alision11e8e162013-05-28 10:33:14 -040035 try {
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040036 ArrayList<String> accountIDs = (ArrayList<String>) service.getAccountList();
37 HashMap<String, String> details;
Alexandre Lision3b7148e2013-11-13 17:23:06 -050038 ArrayList<HashMap<String, String>> credentials;
alision11e8e162013-05-28 10:33:14 -040039 for (String id : accountIDs) {
alision5cfc35d2013-07-11 15:11:39 -040040
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040041 if (id.contentEquals(ACCOUNT_IP2IP)) {
42 details = (HashMap<String, String>) service.getAccountDetails(id);
Alexandre Lision3b7148e2013-11-13 17:23:06 -050043 IP2IP = new Account(ACCOUNT_IP2IP, details, new ArrayList<HashMap<String, String>>()); // Empty credentials
alision11e8e162013-05-28 10:33:14 -040044 continue;
45 }
46 details = (HashMap<String, String>) service.getAccountDetails(id);
Alexandre Lision3b7148e2013-11-13 17:23:06 -050047 credentials = (ArrayList<HashMap<String, String>>) service.getCredentials(id);
48 Account tmp = new Account(id, details, credentials);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040049
Alexandre Lision059da9d2013-10-22 11:17:25 -040050 accounts.add(tmp);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040051
52 Log.i(TAG, "account:" + tmp.getAlias() + " " + tmp.isEnabled());
alision11e8e162013-05-28 10:33:14 -040053
54 }
55 } catch (RemoteException e) {
56 Log.e(TAG, e.toString());
alision5cfc35d2013-07-11 15:11:39 -040057 } catch (NullPointerException e1) {
alisiondf1dac92013-06-27 17:35:53 -040058 Log.e(TAG, e1.toString());
alision11e8e162013-05-28 10:33:14 -040059 }
Alexandre Lision3b7148e2013-11-13 17:23:06 -050060
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040061 Bundle result = new Bundle();
62 result.putParcelableArrayList(ACCOUNTS, accounts);
63 result.putParcelable(ACCOUNT_IP2IP, IP2IP);
alision11e8e162013-05-28 10:33:14 -040064 return result;
65 }
66
67}