blob: e4bf4ce745cf0603f332f6f3a79613d80de6b198 [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;
alision11e8e162013-05-28 10:33:14 -040038 for (String id : accountIDs) {
alision5cfc35d2013-07-11 15:11:39 -040039
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040040 if (id.contentEquals(ACCOUNT_IP2IP)) {
41 details = (HashMap<String, String>) service.getAccountDetails(id);
42 IP2IP = new Account(ACCOUNT_IP2IP, details);
alision11e8e162013-05-28 10:33:14 -040043 continue;
44 }
45 details = (HashMap<String, String>) service.getAccountDetails(id);
Alexandre Lision059da9d2013-10-22 11:17:25 -040046 Account tmp = new Account(id, details);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040047
Alexandre Lision059da9d2013-10-22 11:17:25 -040048 accounts.add(tmp);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040049
50 Log.i(TAG, "account:" + tmp.getAlias() + " " + tmp.isEnabled());
alision11e8e162013-05-28 10:33:14 -040051
52 }
53 } catch (RemoteException e) {
54 Log.e(TAG, e.toString());
alision5cfc35d2013-07-11 15:11:39 -040055 } catch (NullPointerException e1) {
alisiondf1dac92013-06-27 17:35:53 -040056 Log.e(TAG, e1.toString());
alision11e8e162013-05-28 10:33:14 -040057 }
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040058
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040059 Bundle result = new Bundle();
60 result.putParcelableArrayList(ACCOUNTS, accounts);
61 result.putParcelable(ACCOUNT_IP2IP, IP2IP);
alision11e8e162013-05-28 10:33:14 -040062 return result;
63 }
64
65}