Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 1 | package org.sflphone.loaders; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.HashMap; |
| 5 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 6 | import org.sflphone.model.Account; |
| 7 | import org.sflphone.service.ISipService; |
| 8 | |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 9 | import android.content.AsyncTaskLoader; |
| 10 | import android.content.Context; |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 11 | import android.os.Bundle; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 12 | import android.os.RemoteException; |
| 13 | import android.util.Log; |
| 14 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 15 | public class AccountsLoader extends AsyncTaskLoader<Bundle> { |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 16 | |
| 17 | private static final String TAG = AccountsLoader.class.getSimpleName(); |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 18 | public static final String ACCOUNTS = "accounts"; |
| 19 | public static final String ACCOUNT_IP2IP = "IP2IP"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 20 | ISipService service; |
| 21 | |
| 22 | public AccountsLoader(Context context, ISipService ref) { |
| 23 | super(context); |
| 24 | service = ref; |
| 25 | } |
| 26 | |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 27 | @SuppressWarnings("unchecked") |
| 28 | // Hashmap runtime cast |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 29 | @Override |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 30 | public Bundle loadInBackground() { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 31 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 32 | ArrayList<Account> accounts = new ArrayList<Account>(); |
| 33 | Account IP2IP = null; |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 34 | |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 35 | try { |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 36 | ArrayList<String> accountIDs = (ArrayList<String>) service.getAccountList(); |
| 37 | HashMap<String, String> details; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 38 | ArrayList<HashMap<String, String>> credentials; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 39 | for (String id : accountIDs) { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 40 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 41 | if (id.contentEquals(ACCOUNT_IP2IP)) { |
| 42 | details = (HashMap<String, String>) service.getAccountDetails(id); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 43 | IP2IP = new Account(ACCOUNT_IP2IP, details, new ArrayList<HashMap<String, String>>()); // Empty credentials |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 44 | continue; |
| 45 | } |
| 46 | details = (HashMap<String, String>) service.getAccountDetails(id); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 47 | credentials = (ArrayList<HashMap<String, String>>) service.getCredentials(id); |
| 48 | Account tmp = new Account(id, details, credentials); |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 49 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 50 | accounts.add(tmp); |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 51 | |
| 52 | Log.i(TAG, "account:" + tmp.getAlias() + " " + tmp.isEnabled()); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 53 | |
| 54 | } |
| 55 | } catch (RemoteException e) { |
| 56 | Log.e(TAG, e.toString()); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 57 | } catch (NullPointerException e1) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 58 | Log.e(TAG, e1.toString()); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 59 | } |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 60 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 61 | Bundle result = new Bundle(); |
| 62 | result.putParcelableArrayList(ACCOUNTS, accounts); |
| 63 | result.putParcelable(ACCOUNT_IP2IP, IP2IP); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 64 | return result; |
| 65 | } |
| 66 | |
| 67 | } |